diff --git a/.gitignore b/.gitignore index d0f42167dbd53b4bedadc0a8988e4646e9fb2972..2a23da7872b255928df7d4d3d547cc6a41e8326f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ ets2panda/linter*/test_rules/**/results ets2panda/linter*/**/package-lock.json **/compile_commands.json .cache +.vscode diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 26f273d6689e4bf2e085648adfe5133f6f638e8a..6a29659a5f81d0b0b688016ff33f10360aa8f0b9 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -202,6 +202,7 @@ libes2panda_sources = [ "ir/expressions/assignmentExpression.cpp", "ir/expressions/awaitExpression.cpp", "ir/expressions/binaryExpression.cpp", + "ir/expressions/blockExpression.cpp", "ir/expressions/callExpression.cpp", "ir/expressions/chainExpression.cpp", "ir/expressions/classExpression.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 75f77a2394adfe82e21b0af131288fd05124d528..463ac9740cc65699399329dc2787691508ead700 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -166,6 +166,7 @@ set(ES2PANDA_LIB_SRC ir/expressions/assignmentExpression.cpp ir/expressions/awaitExpression.cpp ir/expressions/binaryExpression.cpp + ir/expressions/blockExpression.cpp ir/expressions/callExpression.cpp ir/expressions/chainExpression.cpp ir/expressions/classExpression.cpp diff --git a/ets2panda/checker/ASchecker.cpp b/ets2panda/checker/ASchecker.cpp index 3f096b5ce26ac987146c0e414621a175f75b9eb4..36b7a658c53174deeeb1dcd704a747dbf664accb 100644 --- a/ets2panda/checker/ASchecker.cpp +++ b/ets2panda/checker/ASchecker.cpp @@ -26,6 +26,11 @@ bool ASChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + return false; } diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f91ee6ca74baf1c27f552ac3a85e504a908deba4..c26e12302dfa23fe17414210e3865726446af043 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -20,14 +20,6 @@ #include "checker/ETSchecker.h" #include "checker/ets/castingContext.h" #include "checker/ets/typeRelationContext.h" -#include "ir/base/catchClause.h" -#include "ir/base/classProperty.h" -#include "ir/base/classStaticBlock.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/returnStatement.h" #include "util/helpers.h" namespace panda::es2panda::checker { @@ -82,7 +74,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassDefinition *node) const checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const { - ASSERT(st->Key()->IsIdentifier()); + ASSERT(st->Id() != nullptr); ETSChecker *checker = GetETSChecker(); if (st->TsType() != nullptr) { @@ -97,8 +89,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); } - st->SetTsType( - checker->CheckVariableDeclaration(st->Key()->AsIdentifier(), st->TypeAnnotation(), st->Value(), st->flags_)); + st->SetTsType(checker->CheckVariableDeclaration(st->Id(), st->TypeAnnotation(), st->Value(), st->Modifiers())); return st->TsType(); } @@ -126,27 +117,224 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::Decorator *st) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::MetaProperty *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::MetaProperty *expr) const { - (void)expr; UNREACHABLE(); } +static void CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, + checker::ETSObjectType *obj_type, + ir::ScriptFunction *extension_func, + checker::Signature *signature) +{ + const auto method_name = extension_func->Id()->Name(); + // Only check if there are class and interfaces' instance methods which would shadow instance extension method + auto *const variable = obj_type->GetOwnProperty(method_name); + if (variable == nullptr) { + return; + } + + const auto *const func_type = variable->TsType()->AsETSFunctionType(); + for (auto *func_signature : func_type->CallSignatures()) { + signature->SetReturnType(func_signature->ReturnType()); + if (!checker->Relation()->IsIdenticalTo(signature, func_signature)) { + continue; + } + + checker->ReportWarning({"extension is shadowed by a instance member function '", func_type->Name(), + func_signature, "' in class ", obj_type->Name()}, + extension_func->Body()->Start()); + return; + } +} + +static void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, + ir::ScriptFunction *extension_func, checker::Signature *signature) +{ + if (obj_type == nullptr) { + return; + } + + CheckExtensionIsShadowedInCurrentClassOrInterface(checker, obj_type, extension_func, signature); + + for (auto *interface : obj_type->Interfaces()) { + CheckExtensionIsShadowedByMethod(checker, interface, extension_func, signature); + } + + CheckExtensionIsShadowedByMethod(checker, obj_type->SuperType(), extension_func, signature); +} + +static void CheckExtensionMethod(checker::ETSChecker *checker, ir::ScriptFunction *extension_func, + ir::MethodDefinition *node) +{ + auto *const class_type = extension_func->Signature()->Params()[0]->TsType(); + if (!class_type->IsETSObjectType() || + (!class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CLASS) && + !class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::INTERFACE))) { + checker->ThrowTypeError("Extension function can only defined for class and interface type.", node->Start()); + } + + checker->AddStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD); + + checker::SignatureInfo *original_extension_sig_info = checker->Allocator()->New( + extension_func->Signature()->GetSignatureInfo(), checker->Allocator()); + original_extension_sig_info->min_arg_count -= 1; + original_extension_sig_info->params.erase(original_extension_sig_info->params.begin()); + checker::Signature *original_extension_sigature = checker->CreateSignature( + original_extension_sig_info, extension_func->Signature()->ReturnType(), extension_func); + + CheckExtensionIsShadowedByMethod(checker, class_type->AsETSObjectType(), extension_func, + original_extension_sigature); +} + +void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::ScriptFunction *script_func) +{ + if (script_func->HasBody() && (node->IsNative() || node->IsAbstract() || node->IsDeclare())) { + checker->ThrowTypeError("Native, Abstract and Declare methods cannot have body.", script_func->Body()->Start()); + } + + if (script_func->IsAsyncFunc()) { + auto *ret_type = static_cast(script_func->Signature()->ReturnType()); + if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { + checker->ThrowTypeError("Return type of async function must be 'Promise'.", script_func->Start()); + } + } else if (script_func->HasBody() && !script_func->IsExternal()) { + checker::ScopeContext scope_ctx(checker, script_func->Scope()); + checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), + checker->Context().ContainingClass()); + checker->Context().SetContainingSignature(checker->GetSignatureFromMethodDefinition(node)); + + if (node->IsStatic() && !node->IsConstructor() && + !checker->Context().ContainingClass()->HasObjectFlag(checker::ETSObjectFlags::GLOBAL)) { + checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); + } + + if (node->IsConstructor()) { + checker->AddStatus(checker::CheckerStatus::IN_CONSTRUCTOR); + } + + if (node->IsExtensionMethod()) { + CheckExtensionMethod(checker, script_func, node); + } + + script_func->Body()->Check(checker); + + // In case of inferred function's return type set it forcedly to all return statements; + if (script_func->Signature()->HasSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE) && + script_func->ReturnTypeAnnotation() == nullptr && script_func->Body() != nullptr && + script_func->Body()->IsStatement()) { + script_func->Body()->AsStatement()->SetReturnType(checker, script_func->Signature()->ReturnType()); + } + + checker->Context().SetContainingSignature(nullptr); + } +} + +void CheckGetterSetterTypeConstrains(ETSChecker *checker, ir::ScriptFunction *script_func) +{ + if (script_func->IsSetter() && (script_func->Signature()->ReturnType() != checker->GlobalBuiltinVoidType())) { + checker->ThrowTypeError("Setter must have void return type", script_func->Start()); + } + + if (script_func->IsGetter() && (script_func->Signature()->ReturnType() == checker->GlobalBuiltinVoidType())) { + checker->ThrowTypeError("Getter must return a value", script_func->Start()); + } +} + checker::Type *ETSAnalyzer::Check(ir::MethodDefinition *node) const { - (void)node; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + auto *script_func = node->Function(); + if (script_func->IsProxy()) { + return nullptr; + } + + // NOTE: aszilagyi. make it correctly check for open function not have body + if (!script_func->HasBody() && !(node->IsAbstract() || node->IsNative() || node->IsDeclare() || + checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { + checker->ThrowTypeError("Only abstract or native methods can't have body.", script_func->Start()); + } + + if (script_func->ReturnTypeAnnotation() == nullptr && + (node->IsNative() || (node->IsDeclare() && !node->IsConstructor()))) { + checker->ThrowTypeError("Native and Declare methods should have explicit return type.", script_func->Start()); + } + + if (node->TsType() == nullptr) { + node->SetTsType(checker->BuildMethodSignature(node)); + } + + this->CheckMethodModifiers(node); + + if (node->IsNative() && script_func->ReturnTypeAnnotation() == nullptr) { + checker->ThrowTypeError("'Native' method should have explicit return type", script_func->Start()); + } + + if (node->IsNative() && (script_func->IsGetter() || script_func->IsSetter())) { + checker->ThrowTypeError("'Native' modifier is invalid for Accessors", script_func->Start()); + } + + DoBodyTypeChecking(checker, node, script_func); + CheckGetterSetterTypeConstrains(checker, script_func); + + checker->CheckOverride(node->TsType()->AsETSFunctionType()->FindSignature(node->Function())); + + for (auto *it : node->Overloads()) { + it->Check(checker); + } + + if (script_func->IsRethrowing()) { + checker->CheckRethrowingFunction(script_func); + } + + return node->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::Property *expr) const +void ETSAnalyzer::CheckMethodModifiers(ir::MethodDefinition *node) const +{ + ETSChecker *checker = GetETSChecker(); + auto const not_valid_in_abstract = ir::ModifierFlags::NATIVE | ir::ModifierFlags::PRIVATE | + ir::ModifierFlags::OVERRIDE | ir::ModifierFlags::FINAL | + ir::ModifierFlags::STATIC; + + if (node->IsAbstract() && (node->flags_ & not_valid_in_abstract) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): an abstract method can't have private, override, static, final or native " + "modifier.", + node->Start()); + } + + if ((node->IsAbstract() || (!node->Function()->HasBody() && !node->IsNative() && !node->IsDeclare())) && + !(checker->HasStatus(checker::CheckerStatus::IN_ABSTRACT) || + checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { + checker->ThrowTypeError("Non abstract class has abstract method.", node->Start()); + } + + auto const not_valid_in_final = ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::STATIC | ir::ModifierFlags::NATIVE; + + if (node->IsFinal() && (node->flags_ & not_valid_in_final) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): a final method can't have abstract, static or native modifier.", + node->Start()); + } + + auto const not_valid_in_static = + ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::FINAL | ir::ModifierFlags::OVERRIDE; + + if (node->IsStatic() && (node->flags_ & not_valid_in_static) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): a static method can't have abstract, final or override modifier.", + node->Start()); + } +} + +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ScriptFunction *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -158,25 +346,23 @@ checker::Type *ETSAnalyzer::Check(ir::SpreadElement *expr) const checker::Type *ETSAnalyzer::Check(ir::TemplateElement *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + expr->SetTsType(checker->CreateETSStringLiteralType(expr->Raw())); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::TSIndexSignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSMethodSignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSPropertySignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -372,49 +558,309 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + + checker::Type *arg_type = expr->argument_->Check(checker); + // Check the argument type of await expression + if (!arg_type->IsETSObjectType() || + (arg_type->AsETSObjectType()->AssemblerName() != compiler::Signatures::BUILTIN_PROMISE)) { + checker->ThrowTypeError("'await' expressions require Promise object as argument.", expr->Argument()->Start()); + } + + expr->SetTsType(arg_type->AsETSObjectType()->TypeArguments().at(0)); + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::BinaryExpression *expr) const { - (void)expr; + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + checker::Type *new_ts_type {nullptr}; + std::tie(new_ts_type, expr->operation_type_) = + checker->CheckBinaryOperator(expr->Left(), expr->Right(), expr, expr->OperatorType(), expr->Start()); + expr->SetTsType(new_ts_type); + return expr->TsType(); +} + +static checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, ir::Expression *callee, + checker::Type *callee_type) +{ + auto *const arrow_func = callee->AsArrowFunctionExpression()->Function(); + auto orig_params = arrow_func->Params(); + auto *func_type = checker->Allocator()->New( + arrow_func->Scope()->AsFunctionScope()->ParamScope(), std::move(orig_params), nullptr, + arrow_func->ReturnTypeAnnotation(), ir::ScriptFunctionFlags::NONE); + auto *const func_iface = func_type->Check(checker); + checker->Relation()->SetNode(callee); + checker->Relation()->IsAssignableTo(callee_type, func_iface); + return func_iface; +} + +static checker::Signature *ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, + checker::ETSChecker *checker, ir::CallExpression *expr) +{ + auto *member_expr = expr->Callee()->AsMemberExpression(); + expr->Arguments().insert(expr->Arguments().begin(), member_expr->Object()); + auto *signature = + checker->ResolveCallExpressionAndTrailingLambda(function_type->CallSignatures(), expr, expr->Start()); + if (!signature->Function()->IsExtensionMethod()) { + checker->ThrowTypeError({"Property '", member_expr->Property()->AsIdentifier()->Name(), + "' does not exist on type '", member_expr->ObjType()->Name(), "'"}, + member_expr->Property()->Start()); + } + expr->SetSignature(signature); + expr->SetCallee(member_expr->Property()); + member_expr->Property()->AsIdentifier()->SetParent(expr); + expr->Arguments()[0]->SetParent(expr); + checker->HandleUpdatedCallExpressionNode(expr); + // Set TsType for new Callee(original member expression's Object) + expr->Callee()->Check(checker); + return signature; +} + +static checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, + checker::ETSChecker *checker, + ir::CallExpression *expr) +{ + checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda( + type->ClassMethodType()->CallSignatures(), expr, expr->Start(), checker::TypeRelationFlag::NO_THROW); + + if (signature != nullptr) { + return signature; + } + + return ResolveCallExtensionFunction(type->ExtensionMethodType(), checker, expr); +} + +checker::Type *ETSAnalyzer::Check(ir::BlockExpression *st) const +{ + (void)st; UNREACHABLE(); } +ArenaVector &ChooseSignatures(checker::Type *callee_type, bool is_constructor_call, + bool is_functional_interface) +{ + if (is_constructor_call) { + return callee_type->AsETSObjectType()->ConstructSignatures(); + } + if (is_functional_interface) { + return callee_type->AsETSObjectType() + ->GetOwnProperty("invoke") + ->TsType() + ->AsETSFunctionType() + ->CallSignatures(); + } + return callee_type->AsETSFunctionType()->CallSignatures(); +} + +checker::ETSObjectType *ChooseCalleeObj(ETSChecker *checker, ir::CallExpression *expr, checker::Type *callee_type, + bool is_constructor_call) +{ + if (is_constructor_call) { + return callee_type->AsETSObjectType(); + } + if (expr->Callee()->IsIdentifier()) { + return checker->Context().ContainingClass(); + } + ASSERT(expr->Callee()->IsMemberExpression()); + return expr->Callee()->AsMemberExpression()->ObjType(); +} + +checker::Signature *ResolveSignature(ETSChecker *checker, ir::CallExpression *expr, checker::Type *callee_type, + bool is_constructor_call, bool is_functional_interface) +{ + bool extension_function_type = + expr->Callee()->IsMemberExpression() && checker->ExtensionETSFunctionType(callee_type); + + if (callee_type->IsETSExtensionFuncHelperType()) { + return ResolveCallForETSExtensionFuncHelperType(callee_type->AsETSExtensionFuncHelperType(), checker, expr); + } + if (extension_function_type) { + return ResolveCallExtensionFunction(callee_type->AsETSFunctionType(), checker, expr); + } + auto &signatures = ChooseSignatures(callee_type, is_constructor_call, is_functional_interface); + checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda(signatures, expr, expr->Start()); + if (signature->Function()->IsExtensionMethod()) { + checker->ThrowTypeError({"No matching call signature"}, expr->Start()); + } + return signature; +} + +checker::Type *ETSAnalyzer::GetReturnType(ir::CallExpression *expr, checker::Type *callee_type) const +{ + ETSChecker *checker = GetETSChecker(); + bool is_constructor_call = expr->IsETSConstructorCall(); + bool is_functional_interface = callee_type->IsETSObjectType() && callee_type->AsETSObjectType()->HasObjectFlag( + checker::ETSObjectFlags::FUNCTIONAL_INTERFACE); + bool ets_extension_func_helper_type = callee_type->IsETSExtensionFuncHelperType(); + + if (expr->Callee()->IsArrowFunctionExpression()) { + callee_type = InitAnonymousLambdaCallee(checker, expr->Callee(), callee_type); + is_functional_interface = true; + } + + if (!is_functional_interface && !callee_type->IsETSFunctionType() && !is_constructor_call && + !ets_extension_func_helper_type) { + checker->ThrowTypeError("This expression is not callable.", expr->Start()); + } + + checker::Signature *signature = + ResolveSignature(checker, expr, callee_type, is_constructor_call, is_functional_interface); + + checker->CheckObjectLiteralArguments(signature, expr->Arguments()); + checker->AddUndefinedParamsForDefaultParams(signature, expr->Arguments(), checker); + + if (!is_functional_interface) { + checker::ETSObjectType *callee_obj = ChooseCalleeObj(checker, expr, callee_type, is_constructor_call); + checker->ValidateSignatureAccessibility(callee_obj, signature, expr->Start()); + } + + ASSERT(signature->Function() != nullptr); + if (signature->Function()->IsThrowing() || signature->Function()->IsRethrowing()) { + checker->CheckThrowingStatements(expr); + } + + if (signature->Function()->IsDynamic()) { + ASSERT(signature->Function()->IsDynamic()); + auto lang = signature->Function()->Language(); + expr->SetSignature(checker->ResolveDynamicCallExpression(expr->Callee(), signature->Params(), lang, false)); + } else { + ASSERT(!signature->Function()->IsDynamic()); + expr->SetSignature(signature); + } + + return signature->ReturnType(); +} + checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + auto *old_callee = expr->Callee(); + checker::Type *callee_type = expr->Callee()->Check(checker); + if (expr->Callee() != old_callee) { + // If it is a static invoke, the callee will be transformed from an identifier to a member expression + // Type check the callee again for member expression + callee_type = expr->Callee()->Check(checker); + } + if (!expr->IsOptional()) { + checker->CheckNonNullishType(callee_type, expr->Callee()->Start()); + } + checker::Type *return_type; + if (callee_type->IsETSDynamicType() && !callee_type->AsETSDynamicType()->HasDecl()) { + // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` + checker->EnsureValidCurlyBrace(expr); + auto lang = callee_type->AsETSDynamicType()->Language(); + expr->SetSignature(checker->ResolveDynamicCallExpression(expr->Callee(), expr->Arguments(), lang, false)); + return_type = expr->Signature()->ReturnType(); + } else { + return_type = GetReturnType(expr, callee_type); + } + + if (expr->Signature()->RestVar() != nullptr) { + auto *const element_type = expr->Signature()->RestVar()->TsType()->AsETSArrayType()->ElementType(); + auto *const array_type = checker->CreateETSArrayType(element_type)->AsETSArrayType(); + checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); + } + + if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { + expr->Signature()->OwnerVar()->Declaration()->Node()->Check(checker); + return_type = expr->Signature()->ReturnType(); + } + expr->SetOptionalType(return_type); + if (expr->IsOptional() && callee_type->IsNullishOrNullLike()) { + checker->Relation()->SetNode(expr); + return_type = checker->CreateOptionalResultType(return_type); + checker->Relation()->SetNode(nullptr); + } + expr->SetTsType(return_type); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::ChainExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ChainExpression *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ClassExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + + checker->CheckTruthinessOfType(expr->Test()); + + checker::Type *consequent_type = expr->consequent_->Check(checker); + checker::Type *alternate_type = expr->alternate_->Check(checker); + + auto *primitive_consequent_type = checker->ETSBuiltinTypeAsPrimitiveType(consequent_type); + auto *primitive_alter_type = checker->ETSBuiltinTypeAsPrimitiveType(alternate_type); + + if (primitive_consequent_type != nullptr && primitive_alter_type != nullptr) { + if (checker->IsTypeIdenticalTo(consequent_type, alternate_type)) { + expr->SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequent_type)); + } else if (checker->IsTypeIdenticalTo(primitive_consequent_type, primitive_alter_type)) { + checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitive_consequent_type, + expr->consequent_); + checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitive_alter_type, expr->alternate_); + + expr->SetTsType(primitive_consequent_type); + } else if (primitive_consequent_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) && + primitive_alter_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { + checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitive_consequent_type, + expr->consequent_); + checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitive_alter_type, expr->alternate_); + + expr->SetTsType( + checker->ApplyConditionalOperatorPromotion(checker, primitive_consequent_type, primitive_alter_type)); + } else { + checker->ThrowTypeError("Type error", expr->Range().start); + } + } else { + if (!(consequent_type->IsETSArrayType() || alternate_type->IsETSArrayType()) && + !(consequent_type->IsETSObjectType() && alternate_type->IsETSObjectType())) { + checker->ThrowTypeError("Type error", expr->Range().start); + } else { + checker->Relation()->SetNode(expr->consequent_); + auto builtin_conseq_type = checker->PrimitiveTypeAsETSBuiltinType(consequent_type); + auto builtin_alternate_type = checker->PrimitiveTypeAsETSBuiltinType(alternate_type); + + if (builtin_conseq_type == nullptr) { + builtin_conseq_type = consequent_type; + } + + if (builtin_alternate_type == nullptr) { + builtin_alternate_type = alternate_type; + } + + expr->SetTsType(checker->FindLeastUpperBound(builtin_conseq_type, builtin_alternate_type)); + } + } + + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::DirectEvalExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::FunctionExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::FunctionExpression *expr) const { - (void)expr; UNREACHABLE(); } @@ -528,26 +974,47 @@ checker::Type *ETSAnalyzer::Check(ir::CharLiteral *expr) const checker::Type *ETSAnalyzer::Check(ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() == nullptr) { + expr->SetTsType(checker->GlobalETSNullType()); + } + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->Number().IsInt()) { + expr->SetTsType(checker->CreateIntType(expr->Number().GetInt())); + return expr->TsType(); + } + + if (expr->Number().IsLong()) { + expr->SetTsType(checker->CreateLongType(expr->Number().GetLong())); + return expr->TsType(); + } + + if (expr->Number().IsFloat()) { + expr->SetTsType(checker->CreateFloatType(expr->Number().GetFloat())); + return expr->TsType(); + } + + expr->SetTsType(checker->CreateDoubleType(expr->Number().GetDouble())); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::RegExpLiteral *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() == nullptr) { + expr->SetTsType(checker->CreateETSStringLiteralType(expr->Str())); + } + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::UndefinedLiteral *expr) const @@ -557,51 +1024,123 @@ checker::Type *ETSAnalyzer::Check(ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -checker::Type *ETSAnalyzer::Check(ir::ExportAllDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportDefaultDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportNamedDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ImportDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::Type *type = nullptr; + for (auto *spec : st->Specifiers()) { + if (spec->IsImportNamespaceSpecifier()) { + type = spec->AsImportNamespaceSpecifier()->Check(checker); + } + } + + return type; } -checker::Type *ETSAnalyzer::Check(ir::ImportDefaultSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } +checker::ETSObjectType *CreateSyntheticType(ETSChecker *checker, util::StringView const &synthetic_name, + checker::ETSObjectType *last_object_type, ir::Identifier *id) +{ + auto *synthetic_obj_type = checker->Allocator()->New( + checker->Allocator(), synthetic_name, synthetic_name, id, checker::ETSObjectFlags::NO_OPTS); + + auto *class_decl = checker->Allocator()->New(synthetic_name); + varbinder::LocalVariable *var = + checker->Allocator()->New(class_decl, varbinder::VariableFlags::CLASS); + var->SetTsType(synthetic_obj_type); + last_object_type->AddProperty(var); + synthetic_obj_type->SetEnclosingType(last_object_type); + return synthetic_obj_type; +} + checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (st->Local()->Name().Empty()) { + return nullptr; + } + + if (st->Local()->AsIdentifier()->TsType() != nullptr) { + return st->Local()->TsType(); + } + + auto *import_decl = st->Parent()->AsETSImportDeclaration(); + auto import_path = import_decl->Source()->Str(); + + if (import_decl->IsPureDynamic()) { + auto *type = checker->GlobalBuiltinDynamicType(import_decl->Language()); + checker->SetrModuleObjectTsType(st->Local(), type); + return type; + } + + std::string package_name = + (import_decl->Module() == nullptr) ? import_path.Mutf8() : import_decl->Module()->Str().Mutf8(); + + std::replace(package_name.begin(), package_name.end(), '/', '.'); + util::UString package_path(package_name, checker->Allocator()); + std::vector synthetic_names = checker->GetNameForSynteticObjectType(package_path.View()); + + ASSERT(!synthetic_names.empty()); + + auto assembler_name = synthetic_names[0]; + if (import_decl->Module() != nullptr) { + assembler_name = util::UString(assembler_name.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), + checker->Allocator()) + .View(); + } + + auto *module_object_type = + checker->Allocator()->New(checker->Allocator(), synthetic_names[0], assembler_name, + st->Local()->AsIdentifier(), checker::ETSObjectFlags::CLASS); + + auto *root_decl = checker->Allocator()->New(synthetic_names[0]); + varbinder::LocalVariable *root_var = + checker->Allocator()->New(root_decl, varbinder::VariableFlags::NONE); + root_var->SetTsType(module_object_type); + + synthetic_names.erase(synthetic_names.begin()); + checker::ETSObjectType *last_object_type(module_object_type); + + for (const auto &synthetic_name : synthetic_names) { + last_object_type = CreateSyntheticType(checker, synthetic_name, last_object_type, st->Local()->AsIdentifier()); + } + + checker->SetPropertiesForModuleObject( + last_object_type, + (import_decl->Module() != nullptr) + ? util::UString(import_path.Mutf8() + import_decl->Module()->Str().Mutf8(), checker->Allocator()).View() + : import_path); + checker->SetrModuleObjectTsType(st->Local(), last_object_type); + + return module_object_type; } -checker::Type *ETSAnalyzer::Check(ir::ImportSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -625,74 +1164,182 @@ checker::Type *ETSAnalyzer::Check(ir::BreakStatement *st) const checker::Type *ETSAnalyzer::Check(ir::ClassDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->Definition()->Check(checker); + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->target_ = checker->FindJumpTarget(st->Type(), st, st->Ident()); + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::DebuggerStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker->CheckTruthinessOfType(st->Test()); + st->Body()->Check(checker); + + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::EmptyStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const { - (void)st; - UNREACHABLE(); + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + return st->GetExpression()->Check(checker); } -checker::Type *ETSAnalyzer::Check(ir::ForInStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_SOURCE_EXPR_TYPE[] = + "'For-of' statement source expression should be either a string or an array."; +static constexpr char const INVALID_CONST_ASSIGNMENT[] = "Cannot assign a value to a constant variable "; +static constexpr char const ITERATOR_TYPE_ABSENT[] = "Cannot obtain iterator type in 'for-of' statement."; +// NOLINTEND(modernize-avoid-c-arrays) + +checker::Type *GetIteratorType(ETSChecker *checker, checker::Type *elem_type, ir::AstNode *left) +{ + // Just to avoid extra nested level(s) + auto const get_iter_type = [checker, elem_type](ir::VariableDeclarator *const declarator) -> checker::Type * { + if (declarator->TsType() == nullptr) { + if (auto *resolved = checker->FindVariableInFunctionScope(declarator->Id()->AsIdentifier()->Name()); + resolved != nullptr) { + resolved->SetTsType(elem_type); + return elem_type; + } + } else { + return declarator->TsType(); + } + return nullptr; + }; + + checker::Type *iter_type = nullptr; + if (left->IsIdentifier()) { + if (auto *const variable = left->AsIdentifier()->Variable(); variable != nullptr) { + if (variable->Declaration()->IsConstDecl()) { + checker->ThrowTypeError({INVALID_CONST_ASSIGNMENT, variable->Name()}, + variable->Declaration()->Node()->Start()); + } + } + iter_type = left->AsIdentifier()->TsType(); + } else if (left->IsVariableDeclaration()) { + if (auto const &declarators = left->AsVariableDeclaration()->Declarators(); !declarators.empty()) { + iter_type = get_iter_type(declarators.front()); + } + } + + if (iter_type == nullptr) { + checker->ThrowTypeError(ITERATOR_TYPE_ABSENT, left->Start()); + } + return iter_type; +} + checker::Type *ETSAnalyzer::Check(ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *const expr_type = st->Right()->Check(checker); + checker::Type *elem_type; + + if (expr_type == nullptr || (!expr_type->IsETSArrayType() && !expr_type->IsETSStringType())) { + checker->ThrowTypeError(INVALID_SOURCE_EXPR_TYPE, st->Right()->Start()); + } else if (expr_type->IsETSStringType()) { + elem_type = checker->GetGlobalTypesHolder()->GlobalCharType(); + } else { + elem_type = expr_type->AsETSArrayType()->ElementType()->Instantiate(checker->Allocator(), checker->Relation(), + checker->GetGlobalTypesHolder()); + elem_type->RemoveTypeFlag(checker::TypeFlag::CONSTANT); + } + + st->Left()->Check(checker); + checker::Type *iter_type = GetIteratorType(checker, elem_type, st->Left()); + auto *const relation = checker->Relation(); + relation->SetFlags(checker::TypeRelationFlag::ASSIGNMENT_CONTEXT); + relation->SetNode(checker->AllocNode()); // Dummy node to avoid assertion! + + if (!relation->IsAssignableTo(elem_type, iter_type)) { + std::stringstream ss {}; + ss << "Source element type '"; + elem_type->ToString(ss); + ss << "' is not assignable to the loop iterator type '"; + iter_type->ToString(ss); + ss << "'."; + checker->ThrowTypeError(ss.str(), st->Start()); + } + + relation->SetNode(nullptr); + relation->SetFlags(checker::TypeRelationFlag::NONE); + + st->Body()->Check(checker); + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + if (st->Init() != nullptr) { + st->Init()->Check(checker); + } + + if (st->Test() != nullptr) { + checker->CheckTruthinessOfType(st->Test()); + } + + if (st->Update() != nullptr) { + st->Update()->Check(checker); + } + + st->Body()->Check(checker); + + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::FunctionDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::FunctionDeclaration *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker->CheckTruthinessOfType(st->test_); + + st->consequent_->Check(checker); + + if (st->Alternate() != nullptr) { + st->alternate_->Check(checker); + } + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->body_->Check(checker); + return nullptr; } void CheckArgumentVoidType(checker::Type *&func_return_type, ETSChecker *checker, const std::string &name, @@ -906,16 +1553,64 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::SwitchCaseStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->scope_); + st->discriminant_->Check(checker); + checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(checker->Relation(), + checker::TypeRelationFlag::NONE); + // NOTE (user): check exhaustive Switch + checker->CheckSwitchDiscriminant(st->discriminant_); + auto *compared_expr_type = st->discriminant_->TsType(); + auto unboxed_disc_type = + (st->Discriminant()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U + ? checker->ETSBuiltinTypeAsPrimitiveType(compared_expr_type) + : compared_expr_type; + + bool valid_case_type; + + for (auto *it : st->Cases()) { + if (it->Test() != nullptr) { + auto *case_type = it->Test()->Check(checker); + valid_case_type = true; + if (case_type->HasTypeFlag(checker::TypeFlag::CHAR)) { + valid_case_type = compared_expr_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); + } else if (case_type->IsETSEnumType() && st->Discriminant()->TsType()->IsETSEnumType()) { + valid_case_type = + st->Discriminant()->TsType()->AsETSEnumType()->IsSameEnumType(case_type->AsETSEnumType()); + } else if (case_type->IsETSStringEnumType() && st->Discriminant()->TsType()->IsETSStringEnumType()) { + valid_case_type = st->Discriminant()->TsType()->AsETSStringEnumType()->IsSameEnumType( + case_type->AsETSStringEnumType()); + } else { + checker::AssignmentContext( + checker->Relation(), st->discriminant_, case_type, unboxed_disc_type, it->Test()->Start(), + {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, + (compared_expr_type->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING + : checker::TypeRelationFlag::NO_UNBOXING) | + checker::TypeRelationFlag::NO_BOXING); + } + + if (!valid_case_type) { + checker->ThrowTypeError( + {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, + it->Test()->Start()); + } + } + + for (auto *case_stmt : it->Consequent()) { + case_stmt->Check(checker); + } + } + + checker->CheckForSameSwitchCases(&st->cases_); + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ThrowStatement *st) const @@ -948,9 +1643,8 @@ checker::Type *ETSAnalyzer::Check(ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -checker::Type *ETSAnalyzer::Check(ir::TSAnyKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -972,9 +1666,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSBigintKeyword *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSBooleanKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -998,19 +1691,36 @@ checker::Type *ETSAnalyzer::Check(ir::TSConstructorType *node) const checker::Type *ETSAnalyzer::Check(ir::TSEnumDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + varbinder::Variable *enum_var = st->Key()->Variable(); + ASSERT(enum_var != nullptr); + + if (enum_var->TsType() == nullptr) { + checker::Type *ets_enum_type; + if (auto *const item_init = st->Members().front()->AsTSEnumMember()->Init(); item_init->IsNumberLiteral()) { + ets_enum_type = checker->CreateETSEnumType(st); + } else if (item_init->IsStringLiteral()) { + ets_enum_type = checker->CreateETSStringEnumType(st); + } else { + checker->ThrowTypeError("Invalid enumeration value type.", st->Start()); + } + st->SetTsType(ets_enum_type); + ets_enum_type->SetVariable(enum_var); + enum_var->SetTsType(ets_enum_type); + } else if (st->TsType() == nullptr) { + st->SetTsType(enum_var->TsType()); + } + + return st->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::TSEnumMember *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSExternalModuleReference *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -1116,15 +1826,13 @@ checker::Type *ETSAnalyzer::Check(ir::TSNullKeyword *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSNumberKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSObjectKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1146,9 +1854,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSQualifiedName *expr) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSStringKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1224,9 +1931,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSTypeReference *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSUndefinedKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1236,15 +1942,13 @@ checker::Type *ETSAnalyzer::Check(ir::TSUnionType *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSUnknownKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSVoidKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index de2b57cc58f1221ba182913a895318b90abe91fd..ba76d31adaced2bab7242650536707b4db6e1c2e 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -37,6 +37,8 @@ public: private: ETSChecker *GetETSChecker() const; + void CheckMethodModifiers(ir::MethodDefinition *node) const; + checker::Type *GetReturnType(ir::CallExpression *expr, checker::Type *callee_type) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 4d5cfde2fe2dcda1a6456896e5cbbdc5425bd7a1..4144da1ef35b883dced383245d7f619cea334c73 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -77,6 +77,11 @@ bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + if (options.parse_only) { return false; } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 756489ee872a2156d4fadd46a59b9bb5feaf14b7..87fc469310256e6f5cdb6c2ae77fe7c722b4cd85 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -257,7 +257,7 @@ public: bool TypeInference(Signature *signature, const ArenaVector &arguments, TypeRelationFlag flags = TypeRelationFlag::NONE); bool CheckLambdaAssignable(ir::Expression *param, ir::ScriptFunction *lambda); - bool IsCompatibleTypeArgument(Type *type_param, Type *type_argument); + bool IsCompatibleTypeArgument(Type *type_param, Type *type_argument, const Substitution *substitution); Substitution *NewSubstitution() { return Allocator()->New(Allocator()->Adapter()); @@ -266,8 +266,13 @@ public: { return Allocator()->New(*src); } + ArenaUnorderedSet *NewInstantiatedTypeParamsSet() + { + return Allocator()->New>(Allocator()->Adapter()); + } void EnhanceSubstitutionForType(const ArenaVector &type_params, Type *param_type, Type *argument_type, - Substitution *substitution); + Substitution *substitution, + ArenaUnorderedSet *instantiated_type_params); Signature *ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *type_arguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, TypeRelationFlag initial_flags, const std::vector &arg_type_inference_required); @@ -470,6 +475,8 @@ public: bool CheckRethrowingParams(const ir::AstNode *ancestor_function, const ir::AstNode *node); void CheckThrowingStatements(ir::AstNode *node); bool CheckThrowingPlacement(ir::AstNode *node, const ir::AstNode *ancestor_function); + void CheckNumberOfTypeArguments(Type *type, ir::TSTypeParameterDeclaration *type_param_decl, + ir::TSTypeParameterInstantiation *type_args, const lexer::SourcePosition &pos); ir::BlockStatement *FindFinalizerOfTryStatement(ir::AstNode *start_from, const ir::AstNode *p); void CheckRethrowingFunction(ir::ScriptFunction *func); ETSObjectType *GetRelevantArgumentedTypeFromChild(ETSObjectType *child, ETSObjectType *target); @@ -581,6 +588,8 @@ private: ArenaVector CreateTypeForTypeParameters(ir::TSTypeParameterDeclaration *type_params); Type *CreateTypeParameterType(ir::TSTypeParameter *param); + void SetUpTypeParameterConstraint(ir::TSTypeParameter *param); + ETSObjectType *SetUpParameterType(ir::TSTypeParameter *param); ETSObjectType *CreateETSObjectTypeCheckBuiltins(util::StringView name, ir::AstNode *decl_node, ETSObjectFlags flags); void CheckProgram(parser::Program *program, bool run_analysis = false); diff --git a/ets2panda/checker/JSchecker.cpp b/ets2panda/checker/JSchecker.cpp index 5b72fec1c2e5b3e7fb44add5f59787d31a4f2457..a844137c2b0fc9cb747ab957909009e4d25a9060 100644 --- a/ets2panda/checker/JSchecker.cpp +++ b/ets2panda/checker/JSchecker.cpp @@ -29,6 +29,11 @@ bool JSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + return !options.parse_only; } diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index d3e96e821ffd6bb149a2337acaa909ed200d7dca..49ebfde42f51c16072b57f36c933341a4aee7e70 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -17,7 +17,6 @@ #include "checker/TSchecker.h" #include "checker/ts/destructuringContext.h" -#include "util/helpers.h" namespace panda::es2panda::checker { @@ -78,27 +77,25 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::Decorator *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::MetaProperty *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::MetaProperty *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE: aszilagyi. + return checker->GlobalAnyType(); } -checker::Type *TSAnalyzer::Check(ir::MethodDefinition *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::Property *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ScriptFunction *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -108,28 +105,81 @@ checker::Type *TSAnalyzer::Check(ir::SpreadElement *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TemplateElement *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TemplateElement *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::TSIndexSignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->TsType() != nullptr) { + return node->TsType(); + } + + const util::StringView ¶m_name = node->Param()->AsIdentifier()->Name(); + node->type_annotation_->Check(checker); + checker::Type *index_type = node->type_annotation_->GetType(checker); + checker::IndexInfo *info = + checker->Allocator()->New(index_type, param_name, node->Readonly(), node->Start()); + checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); + checker::ObjectType *placeholder = checker->Allocator()->New(desc); + + if (node->Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { + placeholder->Desc()->number_index_info = info; + } else { + placeholder->Desc()->string_index_info = info; + } + + node->SetTsType(placeholder); + return placeholder; } checker::Type *TSAnalyzer::Check(ir::TSMethodSignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->Computed()) { + checker->CheckComputedPropertyName(node->Key()); + } + + checker::ScopeContext scope_ctx(checker, node->Scope()); + + auto *signature_info = checker->Allocator()->New(checker->Allocator()); + checker->CheckFunctionParameterDeclarations(node->Params(), signature_info); + + auto *call_signature = checker->Allocator()->New(signature_info, checker->GlobalAnyType()); + node->Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(call_signature)); + + if (node->ReturnTypeAnnotation() == nullptr) { + checker->ThrowTypeError( + "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", + node->Start()); + } + + node->return_type_annotation_->Check(checker); + call_signature->SetReturnType(node->return_type_annotation_->GetType(checker)); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSPropertySignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->TypeAnnotation() != nullptr) { + node->TypeAnnotation()->Check(checker); + } + + if (node->Computed()) { + checker->CheckComputedPropertyName(node->Key()); + } + + if (node->TypeAnnotation() != nullptr) { + node->Variable()->SetTsType(node->TypeAnnotation()->GetType(checker)); + return nullptr; + } + + checker->ThrowTypeError("Property implicitly has an 'any' type.", node->Start()); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSSignatureDeclaration *node) const @@ -267,52 +317,163 @@ checker::Type *TSAnalyzer::Check(ir::AssignmentExpression *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::AwaitExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE(aszilagyi) + return checker->GlobalAnyType(); } checker::Type *TSAnalyzer::Check(ir::BinaryExpression *expr) const { - (void)expr; + TSChecker *checker = GetTSChecker(); + auto *left_type = expr->Left()->Check(checker); + auto *right_type = expr->Right()->Check(checker); + + switch (expr->OperatorType()) { + case lexer::TokenType::PUNCTUATOR_MULTIPLY: + case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: + case lexer::TokenType::PUNCTUATOR_DIVIDE: + case lexer::TokenType::PUNCTUATOR_MOD: + case lexer::TokenType::PUNCTUATOR_MINUS: + case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: + case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: + case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: + case lexer::TokenType::PUNCTUATOR_BITWISE_AND: + case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: + case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { + return checker->CheckBinaryOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_PLUS: { + return checker->CheckPlusOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_LESS_THAN: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN: { + return checker->CheckCompareOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: + case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: { + if (checker->IsTypeEqualityComparableTo(left_type, right_type) || + checker->IsTypeEqualityComparableTo(right_type, left_type)) { + return checker->GlobalBooleanType(); + } + + checker->ThrowBinaryLikeError(expr->OperatorType(), left_type, right_type, expr->Start()); + } + case lexer::TokenType::KEYW_INSTANCEOF: { + return checker->CheckInstanceofExpression(left_type, right_type, expr->Right(), expr); + } + case lexer::TokenType::KEYW_IN: { + return checker->CheckInExpression(left_type, right_type, expr->Left(), expr->Right(), expr); + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { + return checker->CheckAndOperator(left_type, right_type, expr->Left()); + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { + return checker->CheckOrOperator(left_type, right_type, expr->Left()); + } + case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { + // NOTE: Csaba Repasi. Implement checker for nullish coalescing + return checker->GlobalAnyType(); + } + case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { + checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), left_type, right_type); + return right_type; + } + default: { + UNREACHABLE(); + break; + } + } + + return nullptr; +} + +checker::Type *TSAnalyzer::Check(ir::BlockExpression *st) const +{ + (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *callee_type = expr->callee_->Check(checker); + + // NOTE: aszilagyi. handle optional chain + if (callee_type->IsObjectType()) { + checker::ObjectType *callee_obj = callee_type->AsObjectType(); + return checker->ResolveCallOrNewExpression(callee_obj->CallSignatures(), expr->Arguments(), expr->Start()); + } + + checker->ThrowTypeError("This expression is not callable.", expr->Start()); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ChainExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return expr->expression_->Check(checker); } -checker::Type *TSAnalyzer::Check(ir::ClassExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *test_type = expr->Test()->Check(checker); + + checker->CheckTruthinessOfType(test_type, expr->Test()->Start()); + checker->CheckTestingKnownTruthyCallableOrAwaitableType(expr->Test(), test_type, expr->consequent_); + + checker::Type *consequent_type = expr->consequent_->Check(checker); + checker::Type *alternate_type = expr->alternate_->Check(checker); + + return checker->CreateUnionType({consequent_type, alternate_type}); } -checker::Type *TSAnalyzer::Check(ir::DirectEvalExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::FunctionExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + varbinder::Variable *func_var = nullptr; + + if (expr->Function()->Parent()->Parent() != nullptr && + expr->Function()->Parent()->Parent()->IsVariableDeclarator() && + expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { + func_var = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Variable(); + } + + checker::ScopeContext scope_ctx(checker, expr->Function()->Scope()); + + auto *signature_info = checker->Allocator()->New(checker->Allocator()); + checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signature_info); + + auto *signature = checker->Allocator()->New( + signature_info, checker->GlobalResolvingReturnType(), expr->Function()); + checker::Type *func_type = checker->CreateFunctionTypeWithSignature(signature); + + if (func_var != nullptr && func_var->TsType() == nullptr) { + func_var->SetTsType(func_type); + } + + signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); + + expr->Function()->Body()->Check(checker); + + return func_type; } checker::Type *TSAnalyzer::Check(ir::Identifier *expr) const @@ -423,28 +584,44 @@ checker::Type *TSAnalyzer::Check(ir::CharLiteral *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::NullLiteral *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return checker->GlobalNullType(); } checker::Type *TSAnalyzer::Check(ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + auto search = checker->NumberLiteralMap().find(expr->Number().GetDouble()); + if (search != checker->NumberLiteralMap().end()) { + return search->second; + } + + auto *new_num_literal_type = checker->Allocator()->New(expr->Number().GetDouble()); + checker->NumberLiteralMap().insert({expr->Number().GetDouble(), new_num_literal_type}); + return new_num_literal_type; } -checker::Type *TSAnalyzer::Check(ir::RegExpLiteral *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE: aszilagyi + return checker->GlobalAnyType(); } checker::Type *TSAnalyzer::Check(ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + auto search = checker->StringLiteralMap().find(expr->Str()); + if (search != checker->StringLiteralMap().end()) { + return search->second; + } + + auto *new_str_literal_type = checker->Allocator()->New(expr->Str()); + checker->StringLiteralMap().insert({expr->Str(), new_str_literal_type}); + + return new_str_literal_type; } checker::Type *TSAnalyzer::Check(ir::UndefinedLiteral *expr) const @@ -454,51 +631,43 @@ checker::Type *TSAnalyzer::Check(ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -checker::Type *TSAnalyzer::Check(ir::ExportAllDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportDefaultDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportNamedDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportDefaultSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -520,9 +689,8 @@ checker::Type *TSAnalyzer::Check(ir::BreakStatement *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ClassDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassDeclaration *st) const { - (void)st; UNREACHABLE(); } @@ -532,63 +700,107 @@ checker::Type *TSAnalyzer::Check(ir::ContinueStatement *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::DebuggerStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *test_type = st->Test()->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Test()->Start()); + st->Body()->Check(checker); + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::EmptyStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const { - (void)st; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return st->GetExpression()->Check(checker); } -checker::Type *TSAnalyzer::Check(ir::ForInStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ForOfStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ForOfStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + if (st->Init() != nullptr) { + st->Init()->Check(checker); + } + + if (st->Test() != nullptr) { + checker::Type *test_type = st->Test()->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Start()); + } + + if (st->Update() != nullptr) { + st->Update()->Check(checker); + } + + st->Body()->Check(checker); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::FunctionDeclaration *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (st->Function()->IsOverload()) { + return nullptr; + } + + const util::StringView &func_name = st->Function()->Id()->Name(); + auto result = checker->Scope()->Find(func_name); + ASSERT(result.variable); + + checker::ScopeContext scope_ctx(checker, st->Function()->Scope()); + + if (result.variable->TsType() == nullptr) { + checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.variable); + } + + st->Function()->Body()->Check(checker); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *test_type = st->test_->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Start()); + checker->CheckTestingKnownTruthyCallableOrAwaitableType(st->test_, test_type, st->consequent_); + + st->consequent_->Check(checker); + + if (st->Alternate() != nullptr) { + st->alternate_->Check(checker); + } + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::LabelledStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::LabelledStatement *st) const { - (void)st; UNREACHABLE(); } @@ -623,16 +835,43 @@ checker::Type *TSAnalyzer::Check(ir::ReturnStatement *st) const return nullptr; } -checker::Type *TSAnalyzer::Check(ir::SwitchCaseStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *expr_type = st->discriminant_->Check(checker); + bool expr_is_literal = checker::TSChecker::IsLiteralType(expr_type); + + for (auto *it : st->Cases()) { + if (it->Test() != nullptr) { + checker::Type *case_type = it->Test()->Check(checker); + bool case_is_literal = checker::TSChecker::IsLiteralType(case_type); + checker::Type *compared_expr_type = expr_type; + + if (!case_is_literal || !expr_is_literal) { + case_type = case_is_literal ? checker->GetBaseTypeOfLiteralType(case_type) : case_type; + compared_expr_type = checker->GetBaseTypeOfLiteralType(expr_type); + } + + if (!checker->IsTypeEqualityComparableTo(compared_expr_type, case_type) && + !checker->IsTypeComparableTo(case_type, compared_expr_type)) { + checker->ThrowTypeError({"Type ", case_type, " is not comparable to type ", compared_expr_type}, + it->Test()->Start()); + } + } + + for (auto *case_stmt : it->Consequent()) { + case_stmt->Check(checker); + } + } + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ThrowStatement *st) const @@ -665,10 +904,9 @@ checker::Type *TSAnalyzer::Check(ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -checker::Type *TSAnalyzer::Check(ir::TSAnyKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSArrayType *node) const @@ -689,10 +927,9 @@ checker::Type *TSAnalyzer::Check(ir::TSBigintKeyword *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSBooleanKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSClassImplements *expr) const @@ -713,21 +950,343 @@ checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const UNREACHABLE(); } +static varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::Identifier *expr) +{ + if (expr->Name() == "NaN") { + return std::nan(""); + } + if (expr->Name() == "Infinity") { + return std::numeric_limits::infinity(); + } + + varbinder::Variable *enum_member = expr->AsIdentifier()->Variable(); + + if (enum_member == nullptr) { + checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, + enum_var->Declaration()->Node()->Start()); + } + + if (enum_member->IsEnumVariable()) { + varbinder::EnumVariable *expr_enum_var = enum_member->AsEnumVariable(); + if (std::holds_alternative(expr_enum_var->Value())) { + checker->ThrowTypeError( + "A member initializer in a enum declaration cannot reference members declared after it, " + "including " + "members defined in other enums.", + enum_var->Declaration()->Node()->Start()); + } + + return expr_enum_var->Value(); + } + + return false; +} + +static int32_t ToInt(double num) +{ + if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { + return static_cast(num); + } + + // NOTE (aszilagyi): Perform ECMA defined toInt conversion + + return 0; +} + +static uint32_t ToUInt(double num) +{ + if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { + return static_cast(num); + } + + // NOTE (aszilagyi): Perform ECMA defined toInt conversion + + return 0; +} + +varbinder::EnumMemberResult GetOperationResulForDouble(lexer::TokenType type, varbinder::EnumMemberResult left, + varbinder::EnumMemberResult right) +{ + switch (type) { + case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { + return static_cast(ToUInt(std::get(left)) | ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_BITWISE_AND: { + return static_cast(ToUInt(std::get(left)) & ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: { + return static_cast(ToUInt(std::get(left)) ^ ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) + return static_cast(ToInt(std::get(left)) << ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) + return static_cast(ToInt(std::get(left)) >> ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: { + return static_cast(ToUInt(std::get(left)) >> ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_PLUS: { + return std::get(left) + std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MINUS: { + return std::get(left) - std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MULTIPLY: { + return std::get(left) * std::get(right); + } + case lexer::TokenType::PUNCTUATOR_DIVIDE: { + return std::get(left) / std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MOD: { + return std::fmod(std::get(left), std::get(right)); + } + case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: { + return std::pow(std::get(left), std::get(right)); + } + default: { + return false; + } + } +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateBinaryExpression(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::BinaryExpression *expr) const +{ + varbinder::EnumMemberResult left = EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Left()); + varbinder::EnumMemberResult right = EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Right()); + if (std::holds_alternative(left) && std::holds_alternative(right)) { + GetOperationResulForDouble(expr->AsBinaryExpression()->OperatorType(), left, right); + } + + if (std::holds_alternative(left) && std::holds_alternative(right) && + expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { + std::stringstream ss; + ss << std::get(left) << std::get(right); + + util::UString res(ss.str(), checker->Allocator()); + return res.View(); + } + + return false; +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateUnaryExpression(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::UnaryExpression *expr) const +{ + varbinder::EnumMemberResult value = EvaluateEnumMember(checker, enum_var, expr->Argument()); + if (!std::holds_alternative(value)) { + return false; + } + + switch (expr->OperatorType()) { + case lexer::TokenType::PUNCTUATOR_PLUS: { + return std::get(value); + } + case lexer::TokenType::PUNCTUATOR_MINUS: { + return -std::get(value); + } + case lexer::TokenType::PUNCTUATOR_TILDE: { + return static_cast(~ToInt(std::get(value))); // NOLINT(hicpp-signed-bitwise) + } + default: { + break; + } + } + + return false; +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateEnumMember(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::AstNode *expr) const +{ + switch (expr->Type()) { + case ir::AstNodeType::UNARY_EXPRESSION: { + return EvaluateUnaryExpression(checker, enum_var, expr->AsUnaryExpression()); + } + case ir::AstNodeType::BINARY_EXPRESSION: { + return EvaluateBinaryExpression(checker, enum_var, expr->AsBinaryExpression()); + } + case ir::AstNodeType::NUMBER_LITERAL: { + return expr->AsNumberLiteral()->Number().GetDouble(); + } + case ir::AstNodeType::STRING_LITERAL: { + return expr->AsStringLiteral()->Str(); + } + case ir::AstNodeType::IDENTIFIER: { + return EvaluateIdentifier(checker, enum_var, expr->AsIdentifier()); + } + case ir::AstNodeType::MEMBER_EXPRESSION: { + return EvaluateEnumMember(checker, enum_var, expr->AsMemberExpression()); + } + default: + break; + } + + return false; +} + +static bool IsComputedEnumMember(const ir::Expression *init) +{ + if (init->IsLiteral()) { + return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); + } + + if (init->IsTemplateLiteral()) { + return !init->AsTemplateLiteral()->Quasis().empty(); + } + + return true; +} + +static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVariable *variable) +{ + variable->SetTsType(checker->GlobalNumberType()); + + util::StringView member_str = util::Helpers::ToStringView(checker->Allocator(), number); + + varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + varbinder::Variable *res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); + varbinder::EnumVariable *enum_var = nullptr; + + if (res == nullptr) { + auto *decl = checker->Allocator()->New(member_str); + decl->BindNode(variable->Declaration()->Node()); + enum_scope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); + res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); + ASSERT(res && res->IsEnumVariable()); + enum_var = res->AsEnumVariable(); + enum_var->AsEnumVariable()->SetBackReference(); + enum_var->SetTsType(checker->GlobalStringType()); + } else { + ASSERT(res->IsEnumVariable()); + enum_var = res->AsEnumVariable(); + auto *decl = checker->Allocator()->New(member_str); + decl->BindNode(variable->Declaration()->Node()); + enum_var->ResetDecl(decl); + } + + enum_var->SetValue(variable->Declaration()->Name()); +} + +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_COMPUTED_WITH_STRING[] = + "Computed values are not permitted in an enum with string valued members."; +static constexpr char const INVALID_CONST_MEMBER[] = + "'const' enum member initializers can only contain literal values and other computed enum values."; +static constexpr char const INVALID_CONST_NAN[] = + "'const' enum member initializer was evaluated to disallowed value 'NaN'."; +static constexpr char const INVALID_CONST_INF[] = + "'const' enum member initializer was evaluated to a non-finite value."; +// NOLINTEND(modernize-avoid-c-arrays) + +void TSAnalyzer::InferEnumVariableType(varbinder::EnumVariable *variable, double *value, bool *init_next, + bool *is_literal_enum, bool is_const_enum) const +{ + TSChecker *checker = GetTSChecker(); + const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); + + if (init == nullptr && *init_next) { + checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Start()); + } + + if (init == nullptr && !*init_next) { + variable->SetValue(++(*value)); + AddEnumValueDeclaration(checker, *value, variable); + return; + } + + ASSERT(init); + if (IsComputedEnumMember(init) && *is_literal_enum) { + checker->ThrowTypeError(INVALID_COMPUTED_WITH_STRING, init->Start()); + } + + varbinder::EnumMemberResult res = EvaluateEnumMember(checker, variable, init); + if (std::holds_alternative(res)) { + *is_literal_enum = true; + variable->SetTsType(checker->GlobalStringType()); + *init_next = true; + return; + } + + if (std::holds_alternative(res)) { + if (is_const_enum) { + checker->ThrowTypeError(INVALID_CONST_MEMBER, init->Start()); + } + + *init_next = true; + return; + } + + ASSERT(std::holds_alternative(res)); + variable->SetValue(res); + + *value = std::get(res); + if (is_const_enum && std::isnan(*value)) { + checker->ThrowTypeError(INVALID_CONST_NAN, init->Start()); + } + + if (is_const_enum && std::isinf(*value)) { + checker->ThrowTypeError(INVALID_CONST_INF, init->Start()); + } + + *init_next = false; + AddEnumValueDeclaration(checker, *value, variable); +} + +checker::Type *TSAnalyzer::InferType(checker::TSChecker *checker, bool is_const, ir::TSEnumDeclaration *st) const +{ + double value = -1.0; + + varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + + bool init_next = false; + bool is_literal_enum = false; + size_t locals_size = enum_scope->Decls().size(); + + for (size_t i = 0; i < locals_size; i++) { + const util::StringView ¤t_name = enum_scope->Decls()[i]->Name(); + varbinder::Variable *current_var = + enum_scope->FindLocal(current_name, varbinder::ResolveBindingOptions::BINDINGS); + ASSERT(current_var && current_var->IsEnumVariable()); + InferEnumVariableType(current_var->AsEnumVariable(), &value, &init_next, &is_literal_enum, is_const); + } + + checker::Type *enum_type = checker->Allocator()->New( + st->Key()->Name(), checker->Scope(), + is_literal_enum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL + : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); + + return enum_type; +} + checker::Type *TSAnalyzer::Check(ir::TSEnumDeclaration *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + varbinder::Variable *enum_var = st->Key()->Variable(); + ASSERT(enum_var); + + if (enum_var->TsType() == nullptr) { + checker::ScopeContext scope_ctx(checker, st->Scope()); + checker::Type *enum_type = InferType(checker, st->IsConst(), st); + enum_type->SetVariable(enum_var); + enum_var->SetTsType(enum_type); + } + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSEnumMember *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSExternalModuleReference *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -833,15 +1392,13 @@ checker::Type *TSAnalyzer::Check(ir::TSNullKeyword *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSNumberKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSObjectKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -863,10 +1420,9 @@ checker::Type *TSAnalyzer::Check(ir::TSQualifiedName *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSStringKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSThisType *node) const @@ -941,10 +1497,9 @@ checker::Type *TSAnalyzer::Check(ir::TSTypeReference *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSUndefinedKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const @@ -953,16 +1508,14 @@ checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSUnknownKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSVoidKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/TSAnalyzer.h b/ets2panda/checker/TSAnalyzer.h index eb23fa2fc5c919df6b4b822e49429c8c3775b349..1f5979d31cba03f7f01fc980e5ccff15156645dc 100644 --- a/ets2panda/checker/TSAnalyzer.h +++ b/ets2panda/checker/TSAnalyzer.h @@ -16,6 +16,7 @@ #define ES2PANDA_CHECKER_TSANALYZER_H #include "checker/SemanticAnalyzer.h" +#include "util/helpers.h" namespace panda::es2panda::checker { @@ -36,6 +37,16 @@ public: private: TSChecker *GetTSChecker() const; + + varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::BinaryExpression *expr) const; + varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::AstNode *expr) const; + varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::UnaryExpression *expr) const; + void InferEnumVariableType(varbinder::EnumVariable *variable, double *value, bool *init_next, bool *is_literal_enum, + bool is_const_enum) const; + checker::Type *InferType(checker::TSChecker *checker, bool is_const, ir::TSEnumDeclaration *st) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/TSchecker.cpp b/ets2panda/checker/TSchecker.cpp index 6a9eb3977e56b87d2790f40def815bfd80dab5bc..2a910c8424d01f29e07cccb22a769a70dbeede3d 100644 --- a/ets2panda/checker/TSchecker.cpp +++ b/ets2panda/checker/TSchecker.cpp @@ -29,6 +29,11 @@ bool TSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + if (options.parse_only) { return false; } diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7e6538ad779804810f7a49a78c87889141bdb4fe..ed412dc6469d9ffd2ccddfa5f77ddb0856695366 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -67,7 +67,7 @@ namespace panda::es2panda::checker { -bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) +bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument, const Substitution *substitution) { ASSERT(type_param->IsETSObjectType() && type_param->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::TYPE_PARAMETER)); @@ -78,13 +78,21 @@ bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) return false; } auto *type_param_obj = type_param->AsETSObjectType(); - if (type_param_obj->SuperType() != nullptr) { - type_param_obj->SuperType()->IsSupertypeOf(Relation(), type_argument); + auto *type_param_obj_supertype = type_param_obj->SuperType(); + if (type_param_obj_supertype != nullptr) { + if (!type_param_obj_supertype->TypeArguments().empty()) { + type_param_obj_supertype = + type_param_obj_supertype->Substitute(this->Relation(), substitution)->AsETSObjectType(); + } + type_param_obj_supertype->IsSupertypeOf(Relation(), type_argument); if (!Relation()->IsTrue()) { return false; } } for (auto *itf : type_param_obj->Interfaces()) { + if (!itf->TypeArguments().empty()) { + itf = itf->Substitute(this->Relation(), substitution)->AsETSObjectType(); + } itf->IsSupertypeOf(Relation(), type_argument); if (!Relation()->IsTrue()) { return false; @@ -96,7 +104,8 @@ bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) /* A very rough and imprecise partial type inference */ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_params, Type *param_type, - Type *argument_type, Substitution *substitution) + Type *argument_type, Substitution *substitution, + ArenaUnorderedSet *instantiated_type_params) { if (!param_type->IsETSObjectType()) { return; @@ -104,24 +113,47 @@ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_para auto *param_obj_type = param_type->AsETSObjectType(); if (param_obj_type->HasObjectFlag(ETSObjectFlags::TYPE_PARAMETER)) { auto *param_base = GetOriginalBaseType(param_obj_type); + if (instantiated_type_params->find(param_obj_type) != instantiated_type_params->end() && + substitution->at(param_base) != argument_type) { + ThrowTypeError({"Type parameter already instantiated with another type "}, + param_obj_type->GetDeclNode()->Start()); + } if (std::find(type_params.begin(), type_params.end(), param_base) != type_params.end() && substitution->count(param_base) == 0) { substitution->emplace(param_base, argument_type); + instantiated_type_params->insert(param_obj_type); return; } } - if (!argument_type->IsETSObjectType()) { + if (argument_type->IsETSObjectType()) { + auto *arg_obj_type = argument_type->AsETSObjectType(); + if (GetOriginalBaseType(arg_obj_type) != GetOriginalBaseType(param_obj_type)) { + return; // don't attempt anything fancy for now + } + ASSERT(arg_obj_type->TypeArguments().size() == param_obj_type->TypeArguments().size()); + for (size_t ix = 0; ix < arg_obj_type->TypeArguments().size(); ix++) { + EnhanceSubstitutionForType(type_params, param_obj_type->TypeArguments()[ix], + arg_obj_type->TypeArguments()[ix], substitution, instantiated_type_params); + } + } else if (argument_type->IsETSFunctionType() && + param_obj_type->HasObjectFlag(ETSObjectFlags::FUNCTIONAL_INTERFACE)) { + auto parameter_signatures = param_obj_type->GetOwnProperty("invoke") + ->TsType() + ->AsETSFunctionType() + ->CallSignatures(); + auto argument_signatures = argument_type->AsETSFunctionType()->CallSignatures(); + ASSERT(argument_signatures.size() == 1); + ASSERT(parameter_signatures.size() == 1); + for (size_t idx = 0; idx < argument_signatures[0]->GetSignatureInfo()->params.size(); idx++) { + EnhanceSubstitutionForType(type_params, parameter_signatures[0]->GetSignatureInfo()->params[idx]->TsType(), + argument_signatures[0]->GetSignatureInfo()->params[idx]->TsType(), substitution, + instantiated_type_params); + } + EnhanceSubstitutionForType(type_params, parameter_signatures[0]->ReturnType(), + argument_signatures[0]->ReturnType(), substitution, instantiated_type_params); + } else { return; } - auto *arg_obj_type = argument_type->AsETSObjectType(); - if (GetOriginalBaseType(arg_obj_type) != GetOriginalBaseType(param_obj_type)) { - return; // don't attempt anything fancy for now - } - ASSERT(arg_obj_type->TypeArguments().size() == param_obj_type->TypeArguments().size()); - for (size_t ix = 0; ix < arg_obj_type->TypeArguments().size(); ix++) { - EnhanceSubstitutionForType(type_params, param_obj_type->TypeArguments()[ix], arg_obj_type->TypeArguments()[ix], - substitution); - } } // NOLINTBEGIN(modernize-avoid-c-arrays) diff --git a/ets2panda/checker/ets/function_helpers.h b/ets2panda/checker/ets/function_helpers.h index c112c116f7f81819b5fe4e0e0577fe4ea70f5e10..a4b7e1d091fb53b079bf33bf55dfd1411c37e93b 100644 --- a/ets2panda/checker/ets/function_helpers.h +++ b/ets2panda/checker/ets/function_helpers.h @@ -86,6 +86,7 @@ static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *che const ArenaVector &arguments) { Substitution *substitution = checker->NewSubstitution(); + auto *instantiated_type_params = checker->NewInstantiatedTypeParamsSet(); auto *sig_info = signature->GetSignatureInfo(); ArenaVector &type_params = sig_info->type_params; for (size_t ix = 0; ix < arguments.size(); ix++) { @@ -100,7 +101,7 @@ static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *che if (param_type == nullptr) { continue; } - checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution); + checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution, instantiated_type_params); } return substitution; } @@ -111,6 +112,7 @@ static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *che TypeRelationFlag flags) { auto *substitution = checker->NewSubstitution(); + auto *constraints_substitution = checker->NewSubstitution(); ArenaVector &type_params = signature->GetSignatureInfo()->type_params; ArenaVector type_arg_types {checker->Allocator()->Adapter()}; for (auto *ta_expr : type_arguments->Params()) { @@ -125,8 +127,11 @@ static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *che } return nullptr; } + for (size_t ix = 0; ix < type_params.size(); ix++) { + constraints_substitution->emplace(type_params[ix], type_arg_types[ix]); + } for (size_t ix = 0; ix < type_arg_types.size(); ix++) { - if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix])) { + if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix], constraints_substitution)) { return nullptr; } substitution->emplace(type_params[ix], type_arg_types[ix]); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index b1f99ba5be31df8752d5e681279a7fc6a67bfa98..73311393661a09964e961fe4673159a8a0ac6b8a 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2068,6 +2068,30 @@ void ETSChecker::CheckValidGenericTypeParameter(Type *const arg_type, const lexe ThrowTypeError("Type '" + ss.str() + "' is not valid for generic type arguments", pos); } +void ETSChecker::CheckNumberOfTypeArguments(Type *const type, ir::TSTypeParameterDeclaration *const type_param_decl, + ir::TSTypeParameterInstantiation *const type_args, + const lexer::SourcePosition &pos) +{ + if (type_param_decl != nullptr && type_args == nullptr) { + ThrowTypeError({"Type '", type, "' is generic but type argument were not provided."}, pos); + } + + if (type_param_decl == nullptr && type_args != nullptr) { + ThrowTypeError({"Type '", type, "' is not generic."}, pos); + } + + if (type_args == nullptr) { + return; + } + + ASSERT(type_param_decl != nullptr && type_args != nullptr); + if (type_param_decl->Params().size() != type_args->Params().size()) { + ThrowTypeError({"Type '", type, "' has ", type_param_decl->Params().size(), " number of type parameters, but ", + type_args->Params().size(), " type arguments were provided."}, + pos); + } +} + bool ETSChecker::NeedTypeInference(const ir::ScriptFunction *lambda) { if (lambda->ReturnTypeAnnotation() == nullptr) { @@ -2282,7 +2306,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons parser::Program program(Allocator(), VarBinder()); es2panda::CompilerOptions options; auto parser = parser::ETSParser(&program, options, parser::ParserStatus::NO_OPTS); - auto *arg_expr = parser.CreateExpression(parser::ExpressionParseFlags::NO_OPTS, implicit_instantiate_argument); + auto *arg_expr = parser.CreateExpression(implicit_instantiate_argument); arg_expr->SetParent(call_expr); arg_expr->SetRange(ident->Range()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9ae05f1775df24d55457e41a6a45944c51e2b7c2..3de0b51247e8420256b92e76e1292216d3413a91 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -178,6 +178,11 @@ ArenaVector ETSChecker::CreateTypeForTypeParameters(ir::TSTypeParameterD for (auto *const param : type_params->Params()) { result.push_back(CreateTypeParameterType(param)); } + // The type parameter might be used in the constraint, like 'K extend Comparable', + // so we need to create their type first, then set up the constraint + for (auto *const param : type_params->Params()) { + SetUpTypeParameterConstraint(param); + } return result; } @@ -189,13 +194,28 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) ->AsETSObjectType(); }; - ETSObjectType *param_type = - CreateNewETSObjectType(param->Name()->Name(), param, GlobalETSObjectType()->ObjectFlags()); - param_type->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); - param_type->AddTypeFlag(TypeFlag::GENERIC); - param_type->AddObjectFlag(ETSObjectFlags::TYPE_PARAMETER); - param_type->SetVariable(param->Variable()); + ETSObjectType *param_type = SetUpParameterType(param); + if (param->Constraint() == nullptr) { + // No constraint, so it's Object|null + param_type->SetSuperType(instantiate_supertype(TypeFlag::NULLISH)); + } + return param_type; +} + +void ETSChecker::SetUpTypeParameterConstraint(ir::TSTypeParameter *const param) +{ + auto const instantiate_supertype = [this](TypeFlag nullish_flags) { + return CreateNullishType(GlobalETSObjectType(), nullish_flags, Allocator(), Relation(), GetGlobalTypesHolder()) + ->AsETSObjectType(); + }; + + ETSObjectType *param_type = nullptr; + if (param->Name()->Variable()->TsType() == nullptr) { + param_type = SetUpParameterType(param); + } else { + param_type = param->Name()->Variable()->TsType()->AsETSObjectType(); + } if (param->Constraint() != nullptr) { if (param->Constraint()->IsETSTypeReference() && param->Constraint()->AsETSTypeReference()->Part()->Name()->IsIdentifier() && @@ -213,7 +233,7 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) if (auto *const found_param = type_param_scope->FindLocal(constraint_name, varbinder::ResolveBindingOptions::BINDINGS); found_param != nullptr) { - CreateTypeParameterType(found_param->Declaration()->Node()->AsTSTypeParameter()); + SetUpTypeParameterConstraint(found_param->Declaration()->Node()->AsTSTypeParameter()); } } @@ -233,7 +253,16 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) // No constraint, so it's Object|null|undefined param_type->SetSuperType(instantiate_supertype(TypeFlag::NULLISH)); } +} +ETSObjectType *ETSChecker::SetUpParameterType(ir::TSTypeParameter *const param) +{ + ETSObjectType *param_type = + CreateNewETSObjectType(param->Name()->Name(), param, GlobalETSObjectType()->ObjectFlags()); + param_type->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); + param_type->AddTypeFlag(TypeFlag::GENERIC); + param_type->AddObjectFlag(ETSObjectFlags::TYPE_PARAMETER); + param_type->SetVariable(param->Variable()); SetTypeParameterType(param, param_type); return param_type; } diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index ee23d08854063b5e52316957947e01388f42bee9..b89612f33a37925d9309f4b441c900b639d1bce8 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -39,30 +39,36 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType ir::TSTypeParameterInstantiation *type_args, const lexer::SourcePosition &pos) { - if (type_param_decl != nullptr && type_args == nullptr) { - checker_->ThrowTypeError({"Type '", type, "' is generic but type argument were not provided."}, pos); - } - - if (type_param_decl == nullptr && type_args != nullptr) { - checker_->ThrowTypeError({"Type '", type, "' is not generic."}, pos); - } + checker_->CheckNumberOfTypeArguments(type, type_param_decl, type_args, pos); if (type_args == nullptr) { result_ = type; return true; } - ASSERT(type_param_decl != nullptr && type_args != nullptr); - if (type_param_decl->Params().size() != type_args->Params().size()) { - checker_->ThrowTypeError({"Type '", type, "' has ", type_param_decl->Params().size(), - " number of type parameters, but ", type_args->Params().size(), - " type arguments were provided."}, - pos); + auto *substitution = checker_->NewSubstitution(); + /* + The first loop is to create a substitution of type_params & type_args. + so that we can replace the type_params in constaints by the right type. + e.g: + class X ,T> {} + function main(){ + const myCharClass = new X(); + } + In the case above, the constraints_substitution should store "K->Char" and "T->String". + And in the second loop, we use this substitution to replace type_params in constraints. + In this case, we will check "Comparable" with "Char", since "Char" doesn't + extends "Comparable", we will get an error here. + */ + for (size_t type_param_iter = 0; type_param_iter < type_param_decl->Params().size(); ++type_param_iter) { + auto *const type_arg_type = type_args->Params().at(type_param_iter)->GetType(checker_); + checker_->CheckValidGenericTypeParameter(type_arg_type, pos); + auto *const type_param_type = type->TypeArguments().at(type_param_iter); + substitution->emplace(type_param_type, type_arg_type); } for (size_t type_param_iter = 0; type_param_iter < type_param_decl->Params().size(); ++type_param_iter) { - auto *const param_type = type_args->Params().at(type_param_iter)->GetType(checker_); - checker_->CheckValidGenericTypeParameter(param_type, pos); + auto *const type_arg_type = type_args->Params().at(type_param_iter)->GetType(checker_); auto *const type_param_constraint = type_param_decl->Params().at(type_param_iter)->AsTSTypeParameter()->Constraint(); if (type_param_constraint == nullptr) { @@ -71,10 +77,15 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType bool assignable = false; auto *constraint_type = type_param_constraint->GetType(checker_); - if (constraint_type->IsETSObjectType() && param_type->IsETSObjectType()) { - assignable = ValidateTypeArg(constraint_type->AsETSObjectType(), param_type->AsETSObjectType()); - } else if (param_type->IsETSUnionType() && !constraint_type->IsETSUnionType()) { - auto constituent_types = param_type->AsETSUnionType()->ConstituentTypes(); + + if (!constraint_type->AsETSObjectType()->TypeArguments().empty()) { + constraint_type = constraint_type->Substitute(checker_->Relation(), substitution); + } + + if (constraint_type->IsETSObjectType() && type_arg_type->IsETSObjectType()) { + assignable = ValidateTypeArg(constraint_type->AsETSObjectType(), type_arg_type->AsETSObjectType()); + } else if (type_arg_type->IsETSUnionType() && !constraint_type->IsETSUnionType()) { + auto constituent_types = type_arg_type->AsETSUnionType()->ConstituentTypes(); assignable = std::all_of(constituent_types.begin(), constituent_types.end(), [this, constraint_type](Type *c_type) { return c_type->IsETSObjectType() && @@ -83,7 +94,7 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType } if (!assignable) { - checker_->ThrowTypeError({"Type '", param_type->AsETSObjectType(), + checker_->ThrowTypeError({"Type '", type_arg_type->AsETSObjectType(), "' is not assignable to constraint type '", constraint_type, "'."}, type_args->Params().at(type_param_iter)->Start()); } @@ -146,17 +157,23 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ArenaVectorNewSubstitution(); + auto *constraints_substitution = checker_->NewSubstitution(); + for (size_t ix = 0; ix < type_params.size(); ix++) { + constraints_substitution->emplace(type_params[ix], type_arg_types[ix]); + } for (size_t ix = 0; ix < type_params.size(); ix++) { auto *type_param = type_params[ix]; bool is_compatible_type_arg; if (type_arg_types[ix]->IsETSUnionType()) { auto union_constituent_types = type_arg_types[ix]->AsETSUnionType()->ConstituentTypes(); is_compatible_type_arg = std::all_of(union_constituent_types.begin(), union_constituent_types.end(), - [this, type_param](Type *type_arg) { - return checker_->IsCompatibleTypeArgument(type_param, type_arg); + [this, type_param, constraints_substitution](Type *type_arg) { + return checker_->IsCompatibleTypeArgument( + type_param, type_arg, constraints_substitution); }); } else { - is_compatible_type_arg = checker_->IsCompatibleTypeArgument(type_param, type_arg_types[ix]); + is_compatible_type_arg = + checker_->IsCompatibleTypeArgument(type_param, type_arg_types[ix], constraints_substitution); } if (!is_compatible_type_arg) { checker_->ThrowTypeError( diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index b67c53ca99d7394fc16a3659e7ed87f311f20174..9a62df6fc07588558a55afb6c5f870036ffa4a2c 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -70,21 +70,9 @@ bool ETSFunctionType::AssignmentSource(TypeRelation *relation, Type *target) return false; } -void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) +static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, ETSFunctionType *source_func_type) { - if (!source->IsETSFunctionType() && - (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { - return; - } - - ASSERT(call_signatures_.size() == 1 && call_signatures_[0]->HasSignatureFlag(SignatureFlags::TYPE)); - - Signature *target = call_signatures_[0]; Signature *match {}; - bool source_is_functional = source->IsETSObjectType(); - auto *source_func_type = source_is_functional ? source->AsETSObjectType()->GetFunctionalInterfaceInvokeType() - : source->AsETSFunctionType(); - for (auto *it : source_func_type->CallSignatures()) { if (target->MinArgCount() != it->MinArgCount()) { continue; @@ -97,15 +85,16 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) if (!it->GetSignatureInfo()->type_params.empty()) { auto *substitution = relation->GetChecker()->AsETSChecker()->NewSubstitution(); + auto *instantiated_type_params = relation->GetChecker()->AsETSChecker()->NewInstantiatedTypeParamsSet(); for (size_t ix = 0; ix < target->MinArgCount(); ix++) { relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->type_params, it->GetSignatureInfo()->params[ix]->TsType(), - target->GetSignatureInfo()->params[ix]->TsType(), substitution); + target->GetSignatureInfo()->params[ix]->TsType(), substitution, instantiated_type_params); } if (target->RestVar() != nullptr) { relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->type_params, it->RestVar()->TsType(), target->RestVar()->TsType(), - substitution); + substitution, instantiated_type_params); } it = it->Substitute(relation, substitution); } @@ -133,6 +122,23 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) match = it; break; } + return match; +} + +void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + if (!source->IsETSFunctionType() && + (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { + return; + } + + ASSERT(call_signatures_.size() == 1 && call_signatures_[0]->HasSignatureFlag(SignatureFlags::TYPE)); + + Signature *target = call_signatures_[0]; + bool source_is_functional = source->IsETSObjectType(); + auto *source_func_type = source_is_functional ? source->AsETSObjectType()->GetFunctionalInterfaceInvokeType() + : source->AsETSFunctionType(); + Signature *match = ProcessSignatures(relation, target, source_func_type); if (match == nullptr) { relation->Result(false); diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 46dd096ae82d9c812db8af28704dee330951bdcd..6ee70ad191040eb3ba06d358f357beeb3794599e 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -19,6 +19,7 @@ #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/ETSGen.h" +#include "compiler/core/switchBuilder.h" #include "compiler/function/functionBuilder.h" namespace panda::es2panda::compiler { @@ -86,27 +87,23 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::Decorator *st) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::MetaProperty *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::MetaProperty *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::MethodDefinition *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::Property *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ScriptFunction *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -118,25 +115,22 @@ void ETSCompiler::Compile(const ir::SpreadElement *expr) const void ETSCompiler::Compile(const ir::TemplateElement *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorString(expr, expr->Raw()); } -void ETSCompiler::Compile(const ir::TSIndexSignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSMethodSignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSPropertySignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -270,49 +264,365 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const void ETSCompiler::Compile(const ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + static constexpr bool IS_UNCHECKED_CAST = false; + compiler::RegScope rs(etsg); + compiler::VReg argument_reg = etsg->AllocReg(); + expr->Argument()->Compile(etsg); + etsg->StoreAccumulator(expr, argument_reg); + etsg->CallThisVirtual0(expr->Argument(), argument_reg, compiler::Signatures::BUILTIN_PROMISE_AWAIT_RESOLUTION); + etsg->CastToArrayOrObject(expr->Argument(), expr->TsType(), IS_UNCHECKED_CAST); + etsg->SetAccumulatorType(expr->TsType()); +} + +static void CompileNullishCoalescing(compiler::ETSGen *etsg, ir::BinaryExpression const *const node) +{ + auto const compile_operand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { + etsg->CompileAndCheck(expr); + etsg->ApplyConversion(expr, optype); + }; + + compile_operand(node->Left()); + + if (!node->Left()->TsType()->IsNullishOrNullLike()) { + // fallthrough + } else if (node->Left()->TsType()->IsETSNullLike()) { + compile_operand(node->Right()); + } else { + auto *if_left_nullish = etsg->AllocLabel(); + auto *end_label = etsg->AllocLabel(); + + etsg->BranchIfNullish(node, if_left_nullish); + + etsg->ConvertToNonNullish(node); + etsg->ApplyConversion(node->Left(), node->OperationType()); + etsg->JumpTo(node, end_label); + + etsg->SetLabel(node, if_left_nullish); + compile_operand(node->Right()); + + etsg->SetLabel(node, end_label); + } + etsg->SetAccumulatorType(node->TsType()); +} + +static void CompileLogical(compiler::ETSGen *etsg, const ir::BinaryExpression *expr) +{ + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { + CompileNullishCoalescing(etsg, expr); + return; + } + + ASSERT(expr->IsLogicalExtended()); + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); + compiler::RegScope rs(etsg); + auto lhs = etsg->AllocReg(); + auto rhs = etsg->AllocReg(); + expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); + + auto *end_label = etsg->AllocLabel(); + + auto left_false_label = etsg->AllocLabel(); + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { + etsg->ResolveConditionalResultIfFalse(expr->Left(), left_false_label); + etsg->BranchIfFalse(expr, left_false_label); + + expr->Right()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Right(), rhs, expr->OperationType()); + etsg->Branch(expr, end_label); + + etsg->SetLabel(expr, left_false_label); + etsg->LoadAccumulator(expr, lhs); + } else { + etsg->ResolveConditionalResultIfFalse(expr->Left(), left_false_label); + etsg->BranchIfFalse(expr, left_false_label); + + etsg->LoadAccumulator(expr, lhs); + etsg->Branch(expr, end_label); + + etsg->SetLabel(expr, left_false_label); + expr->Right()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Right(), rhs, expr->OperationType()); + } + + etsg->SetLabel(expr, end_label); + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::BinaryExpression *expr) const +{ + ETSGen *etsg = GetETSGen(); + if (etsg->TryLoadConstantExpression(expr)) { + return; + } + + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); + + if (expr->IsLogical()) { + CompileLogical(etsg, expr); + etsg->ApplyConversion(expr, expr->OperationType()); + return; + } + + compiler::RegScope rs(etsg); + compiler::VReg lhs = etsg->AllocReg(); + + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS && + (expr->Left()->TsType()->IsETSStringType() || expr->Right()->TsType()->IsETSStringType())) { + etsg->BuildString(expr); + return; + } + + expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); + expr->Right()->Compile(etsg); + etsg->ApplyConversion(expr->Right(), expr->OperationType()); + if (expr->OperatorType() >= lexer::TokenType::PUNCTUATOR_LEFT_SHIFT && + expr->OperatorType() <= lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT) { + etsg->ApplyCast(expr->Right(), expr->OperationType()); + } + + etsg->Binary(expr, expr->OperatorType(), lhs); +} + +static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr) +{ + if (expr->Signature()->RestVar() != nullptr) { + std::size_t const argument_count = expr->Arguments().size(); + std::size_t const parameter_count = expr->Signature()->MinArgCount(); + ASSERT(argument_count >= parameter_count); + + auto &arguments = const_cast &>(expr->Arguments()); + std::size_t i = parameter_count; + + if (i < argument_count && expr->Arguments()[i]->IsSpreadElement()) { + arguments[i] = expr->Arguments()[i]->AsSpreadElement()->Argument(); + } else { + ArenaVector elements(checker->Allocator()->Adapter()); + for (; i < argument_count; ++i) { + elements.emplace_back(expr->Arguments()[i]); + } + auto *array_expression = checker->AllocNode(std::move(elements), checker->Allocator()); + array_expression->SetParent(const_cast(expr)); + array_expression->SetTsType(expr->Signature()->RestVar()->TsType()); + arguments.erase(expr->Arguments().begin() + parameter_count, expr->Arguments().end()); + arguments.emplace_back(array_expression); + } + } +} + +void ETSCompiler::Compile(const ir::BlockExpression *expr) const { (void)expr; UNREACHABLE(); } +bool ETSCompiler::IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const +{ + ETSGen *etsg = GetETSGen(); + auto *const callee_object = expr->callee_->AsMemberExpression()->Object(); + auto const *const enum_interface = [callee_type = callee_object->TsType()]() -> checker::ETSEnumInterface const * { + if (callee_type->IsETSEnumType()) { + return callee_type->AsETSEnumType(); + } + if (callee_type->IsETSStringEnumType()) { + return callee_type->AsETSStringEnumType(); + } + return nullptr; + }(); + + if (enum_interface != nullptr) { + ArenaVector arguments(etsg->Allocator()->Adapter()); + + checker::Signature *const signature = [expr, callee_object, enum_interface, &arguments]() { + const auto &member_proxy_method_name = expr->Signature()->InternalName(); + + if (member_proxy_method_name == checker::ETSEnumType::TO_STRING_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->ToStringMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::GET_VALUE_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->GetValueMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::GET_NAME_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->GetNameMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::VALUES_METHOD_NAME) { + return enum_interface->ValuesMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::VALUE_OF_METHOD_NAME) { + arguments.push_back(expr->Arguments().front()); + return enum_interface->ValueOfMethod().global_signature; + } + UNREACHABLE(); + }(); + + ASSERT(signature->ReturnType() == expr->Signature()->ReturnType()); + etsg->CallStatic(expr, signature, arguments); + etsg->SetAccumulatorType(expr->TsType()); + } + + return enum_interface != nullptr; +} + +void ETSCompiler::CompileDynamic(const ir::CallExpression *expr, compiler::VReg &callee_reg) const +{ + ETSGen *etsg = GetETSGen(); + compiler::VReg dyn_param2 = etsg->AllocReg(); + ir::Expression *obj = expr->callee_; + std::vector parts; + + while (obj->IsMemberExpression() && obj->AsMemberExpression()->ObjType()->IsETSDynamicType()) { + auto *mem_expr = obj->AsMemberExpression(); + obj = mem_expr->Object(); + parts.push_back(mem_expr->Property()->AsIdentifier()->Name()); + } + + if (!obj->IsMemberExpression() && obj->IsIdentifier()) { + auto *var = obj->AsIdentifier()->Variable(); + auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); + if (data != nullptr) { + auto *import = data->import; + auto *specifier = data->specifier; + ASSERT(import->Language().IsDynamic()); + etsg->LoadAccumulatorDynamicModule(expr, import); + if (specifier->IsImportSpecifier()) { + parts.push_back(specifier->AsImportSpecifier()->Imported()->Name()); + } + } else { + obj->Compile(etsg); + } + } else { + obj->Compile(etsg); + } + + etsg->StoreAccumulator(expr, callee_reg); + + if (!parts.empty()) { + std::stringstream ss; + for_each(parts.rbegin(), parts.rend(), [&ss](util::StringView sv) { ss << "." << sv; }); + etsg->LoadAccumulatorString(expr, util::UString(ss.str(), etsg->Allocator()).View()); + } else { + auto lang = expr->Callee()->TsType()->IsETSDynamicFunctionType() + ? expr->Callee()->TsType()->AsETSDynamicFunctionType()->Language() + : expr->Callee()->TsType()->AsETSDynamicType()->Language(); + etsg->LoadUndefinedDynamic(expr, lang); + } + etsg->StoreAccumulator(expr, dyn_param2); + etsg->CallDynamic(expr, callee_reg, dyn_param2, expr->Signature(), expr->Arguments()); + etsg->SetAccumulatorType(expr->TsType()); + + if (expr->Signature()->ReturnType() != expr->TsType()) { + etsg->ApplyConversion(expr, expr->TsType()); + } +} + +// Helper function to avoid branching in non optional cases +void ETSCompiler::EmitCall(const ir::CallExpression *expr, compiler::VReg &callee_reg, bool is_static) const +{ + ETSGen *etsg = GetETSGen(); + + if (is_static) { + etsg->CallStatic(expr, expr->Signature(), expr->Arguments()); + } else if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PRIVATE) || expr->IsETSConstructorCall() || + (expr->Callee()->IsMemberExpression() && + expr->Callee()->AsMemberExpression()->Object()->IsSuperExpression())) { + etsg->CallThisStatic(expr, callee_reg, expr->Signature(), expr->Arguments()); + } else { + etsg->CallThisVirtual(expr, callee_reg, expr->Signature(), expr->Arguments()); + } + etsg->SetAccumulatorType(expr->TsType()); +} + void ETSCompiler::Compile(const ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::RegScope rs(etsg); + compiler::VReg callee_reg = etsg->AllocReg(); + + const auto is_proxy = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PROXY); + if (is_proxy && expr->Callee()->IsMemberExpression()) { + if (IsSucceedCompilationProxyMemberExpr(expr)) { + return; + } + } + + bool is_static = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); + bool is_reference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); + bool is_dynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); + + ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker()), expr); + + if (is_dynamic) { + CompileDynamic(expr, callee_reg); + } else if (!is_reference && expr->Callee()->IsIdentifier()) { + if (!is_static) { + etsg->LoadThis(expr); + etsg->StoreAccumulator(expr, callee_reg); + } + EmitCall(expr, callee_reg, is_static); + } else if (!is_reference && expr->Callee()->IsMemberExpression()) { + if (!is_static) { + expr->Callee()->AsMemberExpression()->Object()->Compile(etsg); + etsg->StoreAccumulator(expr, callee_reg); + } + EmitCall(expr, callee_reg, is_static); + } else if (expr->Callee()->IsSuperExpression() || expr->Callee()->IsThisExpression()) { + ASSERT(!is_reference && expr->IsETSConstructorCall()); + expr->Callee()->Compile(etsg); // ctor is not a value! + etsg->SetVRegType(callee_reg, etsg->GetAccumulatorType()); + EmitCall(expr, callee_reg, is_static); + } else { + ASSERT(is_reference); + etsg->CompileAndCheck(expr->Callee()); + etsg->StoreAccumulator(expr, callee_reg); + etsg->EmitMaybeOptional( + expr, [this, expr, is_static, &callee_reg]() { this->EmitCall(expr, callee_reg, is_static); }, + expr->IsOptional()); + } } -void ETSCompiler::Compile(const ir::ChainExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ChainExpression *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ClassExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } void ETSCompiler::Compile(const ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + + auto *false_label = etsg->AllocLabel(); + auto *end_label = etsg->AllocLabel(); + + compiler::Condition::Compile(etsg, expr->Test(), false_label); + + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + + expr->Consequent()->Compile(etsg); + etsg->ApplyConversion(expr->Consequent()); + etsg->Branch(expr, end_label); + etsg->SetLabel(expr, false_label); + expr->Alternate()->Compile(etsg); + etsg->ApplyConversion(expr->Alternate()); + etsg->SetLabel(expr, end_label); + etsg->SetAccumulatorType(expr->TsType()); } -void ETSCompiler::Compile(const ir::DirectEvalExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::FunctionExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::FunctionExpression *expr) const { - (void)expr; UNREACHABLE(); } @@ -426,26 +736,54 @@ void ETSCompiler::Compile(const ir::CharLiteral *expr) const void ETSCompiler::Compile(const ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorNull(expr, expr->TsType()); } void ETSCompiler::Compile(const ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (expr->Number().IsInt()) { + if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { + etsg->LoadAccumulatorByte(expr, static_cast(expr->Number().GetInt())); + return; + } + + if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { + etsg->LoadAccumulatorShort(expr, static_cast(expr->Number().GetInt())); + return; + } + + etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); + return; + } + + if (expr->Number().IsLong()) { + etsg->LoadAccumulatorWideInt(expr, expr->Number().GetLong()); + return; + } + + if (expr->Number().IsFloat()) { + etsg->LoadAccumulatorFloat(expr, expr->Number().GetFloat()); + return; + } + + etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); } -void ETSCompiler::Compile(const ir::RegExpLiteral *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::RegExpLiteral *expr) const { - (void)expr; UNREACHABLE(); } void ETSCompiler::Compile(const ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorString(expr, expr->Str()); + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const @@ -455,51 +793,43 @@ void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -void ETSCompiler::Compile(const ir::ExportAllDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportDefaultDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportNamedDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportDefaultSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportNamespaceSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -521,76 +851,206 @@ void ETSCompiler::Compile(const ir::BreakStatement *st) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ClassDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ClassDeclaration *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::ContinueStatement *self, ETSGen *etsg) +{ + compiler::Label *target = etsg->ControlFlowChangeContinue(self->Ident()); + etsg->Branch(self, target); +} + void ETSCompiler::Compile(const ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + if (etsg->ExtendWithFinalizer(st->parent_, st)) { + return; + } + CompileImpl(st, etsg); } -void ETSCompiler::Compile(const ir::DebuggerStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::DoWhileStatement *st) const +void CompileImpl(const ir::DoWhileStatement *self, ETSGen *etsg) { - (void)st; - UNREACHABLE(); + auto *start_label = etsg->AllocLabel(); + compiler::LabelTarget label_target(etsg); + + etsg->SetLabel(self, start_label); + + { + compiler::LocalRegScope reg_scope(etsg, self->Scope()); + compiler::LabelContext label_ctx(etsg, label_target); + self->Body()->Compile(etsg); + } + + etsg->SetLabel(self, label_target.ContinueTarget()); + compiler::Condition::Compile(etsg, self->Test(), label_target.BreakTarget()); + + etsg->Branch(self, start_label); + etsg->SetLabel(self, label_target.BreakTarget()); } -void ETSCompiler::Compile(const ir::EmptyStatement *st) const +void ETSCompiler::Compile(const ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } +void ETSCompiler::Compile([[maybe_unused]] const ir::EmptyStatement *st) const {} + void ETSCompiler::Compile(const ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + st->GetExpression()->Compile(etsg); } -void ETSCompiler::Compile(const ir::ForInStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } void ETSCompiler::Compile(const ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::LocalRegScope decl_reg_scope(etsg, st->Scope()->DeclScope()->InitScope()); + + checker::Type const *const expr_type = st->Right()->TsType(); + ASSERT(expr_type->IsETSArrayType() || expr_type->IsETSStringType()); + + st->Right()->Compile(etsg); + compiler::VReg obj_reg = etsg->AllocReg(); + etsg->StoreAccumulator(st, obj_reg); + + if (expr_type->IsETSArrayType()) { + etsg->LoadArrayLength(st, obj_reg); + } else { + etsg->LoadStringLength(st); + } + + compiler::VReg size_reg = etsg->AllocReg(); + etsg->StoreAccumulator(st, size_reg); + + compiler::LabelTarget label_target(etsg); + auto label_ctx = compiler::LabelContext(etsg, label_target); + + etsg->BranchIfFalse(st, label_target.BreakTarget()); + + compiler::VReg count_reg = etsg->AllocReg(); + etsg->MoveImmediateToRegister(st, count_reg, checker::TypeFlag::INT, static_cast(0)); + etsg->LoadAccumulatorInt(st, static_cast(0)); + + auto *const start_label = etsg->AllocLabel(); + etsg->SetLabel(st, start_label); + + auto lref = compiler::ETSLReference::Create(etsg, st->Left(), false); + + if (st->Right()->TsType()->IsETSArrayType()) { + etsg->LoadArrayElement(st, obj_reg); + } else { + etsg->LoadStringChar(st, obj_reg, count_reg); + } + + lref.SetValue(); + st->Body()->Compile(etsg); + + etsg->SetLabel(st, label_target.ContinueTarget()); + + etsg->IncrementImmediateRegister(st, count_reg, checker::TypeFlag::INT, static_cast(1)); + etsg->LoadAccumulator(st, count_reg); + + etsg->JumpCompareRegister(st, size_reg, start_label); + etsg->SetLabel(st, label_target.BreakTarget()); } void ETSCompiler::Compile(const ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::LocalRegScope decl_reg_scope(etsg, st->Scope()->DeclScope()->InitScope()); + + if (st->Init() != nullptr) { + ASSERT(st->Init()->IsVariableDeclaration() || st->Init()->IsExpression()); + st->Init()->Compile(etsg); + } + + auto *start_label = etsg->AllocLabel(); + compiler::LabelTarget label_target(etsg); + auto label_ctx = compiler::LabelContext(etsg, label_target); + etsg->SetLabel(st, start_label); + + { + compiler::LocalRegScope reg_scope(etsg, st->Scope()); + + if (st->Test() != nullptr) { + compiler::Condition::Compile(etsg, st->Test(), label_target.BreakTarget()); + } + + st->Body()->Compile(etsg); + etsg->SetLabel(st, label_target.ContinueTarget()); + } + + if (st->Update() != nullptr) { + st->Update()->Compile(etsg); + } + + etsg->Branch(st, start_label); + etsg->SetLabel(st, label_target.BreakTarget()); } -void ETSCompiler::Compile(const ir::FunctionDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::FunctionDeclaration *st) const { - (void)st; UNREACHABLE(); } void ETSCompiler::Compile(const ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + auto res = compiler::Condition::CheckConstantExpr(etsg, st->Test()); + if (res == compiler::Condition::Result::CONST_TRUE) { + st->Consequent()->Compile(etsg); + return; + } + + if (res == compiler::Condition::Result::CONST_FALSE) { + if (st->Alternate() != nullptr) { + st->Alternate()->Compile(etsg); + } + return; + } + + auto *consequent_end = etsg->AllocLabel(); + compiler::Label *statement_end = consequent_end; + + compiler::Condition::Compile(etsg, st->Test(), consequent_end); + + st->Consequent()->Compile(etsg); + + if (st->Alternate() != nullptr) { + statement_end = etsg->AllocLabel(); + etsg->Branch(etsg->Insns().back()->Node(), statement_end); + + etsg->SetLabel(st, consequent_end); + st->Alternate()->Compile(etsg); + } + + etsg->SetLabel(st, statement_end); +} + +void CompileImpl(const ir::LabelledStatement *self, ETSGen *cg) +{ + compiler::LabelContext label_ctx(cg, self); + self->Body()->Compile(cg); } void ETSCompiler::Compile(const ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } void ETSCompiler::Compile(const ir::ReturnStatement *st) const @@ -636,16 +1096,47 @@ void ETSCompiler::Compile(const ir::ReturnStatement *st) const etsg->ReturnAcc(st); } -void ETSCompiler::Compile(const ir::SwitchCaseStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::SwitchStatement *self, ETSGen *etsg) +{ + compiler::LocalRegScope lrs(etsg, self->Scope()); + compiler::SwitchBuilder builder(etsg, self); + compiler::VReg tag = etsg->AllocReg(); + + builder.CompileTagOfSwitch(tag); + uint32_t default_index = 0; + + for (size_t i = 0; i < self->Cases().size(); i++) { + const auto *clause = self->Cases()[i]; + + if (clause->Test() == nullptr) { + default_index = i; + continue; + } + + builder.JumpIfCase(tag, i); + } + + if (default_index > 0) { + builder.JumpToDefault(default_index); + } else { + builder.Break(); + } + + for (size_t i = 0; i < self->Cases().size(); i++) { + builder.SetCaseTarget(i); + builder.CompileCaseStatements(i); + } +} + void ETSCompiler::Compile(const ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } void ETSCompiler::Compile(const ir::ThrowStatement *st) const @@ -678,9 +1169,8 @@ void ETSCompiler::Compile(const ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -void ETSCompiler::Compile(const ir::TSAnyKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -702,9 +1192,8 @@ void ETSCompiler::Compile(const ir::TSBigintKeyword *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSBooleanKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -726,21 +1215,18 @@ void ETSCompiler::Compile(const ir::TSConstructorType *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSEnumDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSEnumDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSEnumMember *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSExternalModuleReference *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -846,15 +1332,13 @@ void ETSCompiler::Compile(const ir::TSNullKeyword *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSNumberKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSObjectKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -876,9 +1360,8 @@ void ETSCompiler::Compile(const ir::TSQualifiedName *expr) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSStringKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -954,9 +1437,8 @@ void ETSCompiler::Compile(const ir::TSTypeReference *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSUndefinedKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -966,16 +1448,14 @@ void ETSCompiler::Compile(const ir::TSUnionType *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSUnknownKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSVoidKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } -} // namespace panda::es2panda::compiler \ No newline at end of file +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSCompiler.h b/ets2panda/compiler/core/ETSCompiler.h index df72ed1699f577a79948cc5b408b0dd01789cb00..61447f878f5e2263cc1a0030068719d49e04d818 100644 --- a/ets2panda/compiler/core/ETSCompiler.h +++ b/ets2panda/compiler/core/ETSCompiler.h @@ -34,6 +34,10 @@ public: #undef DECLARE_ETSCOMPILER_COMPILE_METHOD private: + bool IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const; + void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &callee_reg) const; + void EmitCall(const ir::CallExpression *expr, compiler::VReg &callee_reg, bool is_static) const; + ETSGen *GetETSGen() const; }; diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index 10a894d364243fe8b74d0bd55d96c5d90df2551c..090f5f4ec79163bae0faa14f87f884d41aa6d6dd 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -18,6 +18,7 @@ #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" +#include "compiler/core/switchBuilder.h" #include "compiler/function/functionBuilder.h" #include "util/helpers.h" @@ -409,25 +410,30 @@ void JSCompiler::Compile([[maybe_unused]] const ir::Decorator *st) const void JSCompiler::Compile(const ir::MetaProperty *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (expr->Kind() == ir::MetaProperty::MetaPropertyKind::NEW_TARGET) { + pg->GetNewTarget(expr); + return; + } + + if (expr->Kind() == ir::MetaProperty::MetaPropertyKind::IMPORT_META) { + // NOTE + pg->Unimplemented(); + } } -void JSCompiler::Compile(const ir::MethodDefinition *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::Property *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ScriptFunction *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -437,27 +443,23 @@ void JSCompiler::Compile(const ir::SpreadElement *expr) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TemplateElement *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::TemplateElement *expr) const { - (void)expr; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSIndexSignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSMethodSignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSPropertySignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -572,50 +574,248 @@ void JSCompiler::Compile(const ir::AssignmentExpression *expr) const void JSCompiler::Compile(const ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::RegScope rs(pg); + + if (expr->Argument() != nullptr) { + expr->Argument()->Compile(pg); + } else { + pg->LoadConst(expr, compiler::Constant::JS_UNDEFINED); + } + + pg->EmitAwait(expr); +} + +static void CompileLogical(compiler::PandaGen *pg, const ir::BinaryExpression *expr) +{ + compiler::RegScope rs(pg); + compiler::VReg lhs = pg->AllocReg(); + + ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_OR || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING); + + auto *skip_right = pg->AllocLabel(); + auto *end_label = pg->AllocLabel(); + + // left -> acc -> lhs -> toboolean -> acc -> bool_lhs + expr->Left()->Compile(pg); + pg->StoreAccumulator(expr, lhs); + + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { + pg->ToBoolean(expr); + pg->BranchIfFalse(expr, skip_right); + } else if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_OR) { + pg->ToBoolean(expr); + pg->BranchIfTrue(expr, skip_right); + } else if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { + pg->BranchIfCoercible(expr, skip_right); + } + + // left is true/false(and/or) then right -> acc + expr->Right()->Compile(pg); + pg->Branch(expr, end_label); + + // left is false/true(and/or) then lhs -> acc + pg->SetLabel(expr, skip_right); + pg->LoadAccumulator(expr, lhs); + pg->SetLabel(expr, end_label); } void JSCompiler::Compile(const ir::BinaryExpression *expr) const +{ + PandaGen *pg = GetPandaGen(); + if (expr->IsLogical()) { + CompileLogical(pg, expr); + return; + } + + if (expr->OperatorType() == lexer::TokenType::KEYW_IN && expr->Left()->IsIdentifier() && + expr->Left()->AsIdentifier()->IsPrivateIdent()) { + compiler::RegScope rs(pg); + compiler::VReg ctor = pg->AllocReg(); + const auto &name = expr->Left()->AsIdentifier()->Name(); + compiler::Function::LoadClassContexts(expr, pg, ctor, name); + expr->Right()->Compile(pg); + pg->ClassPrivateFieldIn(expr, ctor, name); + return; + } + + compiler::RegScope rs(pg); + compiler::VReg lhs = pg->AllocReg(); + + expr->Left()->Compile(pg); + pg->StoreAccumulator(expr, lhs); + expr->Right()->Compile(pg); + + pg->Binary(expr, expr->OperatorType(), lhs); +} + +static compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg, const ir::CallExpression *expr) +{ + compiler::VReg args_obj = pg->AllocReg(); + pg->CreateArray(expr, expr->Arguments(), args_obj); + + return args_obj; +} + +void JSCompiler::Compile(const ir::BlockExpression *expr) const { (void)expr; UNREACHABLE(); } +void CompileSuperExprWithoutSpread(PandaGen *pg, const ir::CallExpression *expr) +{ + compiler::RegScope param_scope(pg); + compiler::VReg arg_start {}; + + if (expr->Arguments().empty()) { + arg_start = pg->AllocReg(); + pg->StoreConst(expr, arg_start, compiler::Constant::JS_UNDEFINED); + } else { + arg_start = pg->NextReg(); + } + + for (const auto *it : expr->Arguments()) { + compiler::VReg arg = pg->AllocReg(); + it->Compile(pg); + pg->StoreAccumulator(it, arg); + } + + pg->GetFunctionObject(expr); + pg->SuperCall(expr, arg_start, expr->Arguments().size()); +} + void JSCompiler::Compile(const ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::RegScope rs(pg); + bool contains_spread = util::Helpers::ContainSpreadElement(expr->Arguments()); + + if (expr->Callee()->IsSuperExpression()) { + if (contains_spread) { + compiler::RegScope param_scope(pg); + compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + + pg->GetFunctionObject(expr); + pg->SuperCallSpread(expr, args_obj); + } else { + CompileSuperExprWithoutSpread(pg, expr); + } + + compiler::VReg new_this = pg->AllocReg(); + pg->StoreAccumulator(expr, new_this); + + pg->GetThis(expr); + pg->ThrowIfSuperNotCorrectCall(expr, 1); + + pg->LoadAccumulator(expr, new_this); + pg->SetThis(expr); + + compiler::Function::CompileInstanceFields(pg, pg->RootNode()->AsScriptFunction()); + return; + } + + compiler::VReg callee = pg->AllocReg(); + compiler::VReg this_reg = compiler::VReg::Invalid(); + + if (expr->Callee()->IsMemberExpression()) { + this_reg = pg->AllocReg(); + + compiler::RegScope mrs(pg); + expr->Callee()->AsMemberExpression()->CompileToReg(pg, this_reg); + } else if (expr->Callee()->IsChainExpression()) { + this_reg = pg->AllocReg(); + + compiler::RegScope mrs(pg); + expr->Callee()->AsChainExpression()->CompileToReg(pg, this_reg); + } else { + expr->Callee()->Compile(pg); + } + + pg->StoreAccumulator(expr, callee); + pg->OptionalChainCheck(expr->IsOptional(), callee); + + if (contains_spread || expr->Arguments().size() >= compiler::PandaGen::MAX_RANGE_CALL_ARG) { + if (this_reg.IsInvalid()) { + this_reg = pg->AllocReg(); + pg->StoreConst(expr, this_reg, compiler::Constant::JS_UNDEFINED); + } + + compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + pg->CallSpread(expr, callee, this_reg, args_obj); + } else { + pg->Call(expr, callee, this_reg, expr->Arguments()); + } } void JSCompiler::Compile(const ir::ChainExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::OptionalChain chain(pg, expr); + expr->GetExpression()->Compile(pg); } void JSCompiler::Compile(const ir::ClassExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + expr->Definition()->Compile(pg); +} + +template +static void CompileImpl(const ir::ConditionalExpression *self, CodeGen *cg) +{ + auto *false_label = cg->AllocLabel(); + auto *end_label = cg->AllocLabel(); + + compiler::Condition::Compile(cg, self->Test(), false_label); + self->Consequent()->Compile(cg); + cg->Branch(self, end_label); + cg->SetLabel(self, false_label); + self->Alternate()->Compile(cg); + cg->SetLabel(self, end_label); } void JSCompiler::Compile(const ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(expr, pg); } void JSCompiler::Compile(const ir::DirectEvalExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (expr->Arguments().empty()) { + pg->LoadConst(expr, compiler::Constant::JS_UNDEFINED); + return; + } + + compiler::RegScope rs(pg); + bool contains_spread = util::Helpers::ContainSpreadElement(expr->Arguments()); + if (contains_spread) { + [[maybe_unused]] compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + pg->LoadObjByIndex(expr, 0); + } else { + compiler::VReg arg0 = pg->AllocReg(); + auto iter = expr->Arguments().cbegin(); + (*iter++)->Compile(pg); + pg->StoreAccumulator(expr, arg0); + + while (iter != expr->Arguments().cend()) { + (*iter++)->Compile(pg); + } + + pg->LoadAccumulator(expr, arg0); + } + + pg->DirectEval(expr, expr->parser_status_); } void JSCompiler::Compile(const ir::FunctionExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->DefineFunction(expr->Function(), expr->Function(), expr->Function()->Scope()->InternalName()); } void JSCompiler::Compile(const ir::Identifier *expr) const @@ -728,26 +928,34 @@ void JSCompiler::Compile(const ir::CharLiteral *expr) const void JSCompiler::Compile(const ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->LoadConst(expr, compiler::Constant::JS_NULL); } void JSCompiler::Compile(const ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (std::isnan(expr->Number().GetDouble())) { + pg->LoadConst(expr, compiler::Constant::JS_NAN); + } else if (!std::isfinite(expr->Number().GetDouble())) { + pg->LoadConst(expr, compiler::Constant::JS_INFINITY); + } else if (util::Helpers::IsInteger(expr->Number().GetDouble())) { + pg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetDouble())); + } else { + pg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); + } } void JSCompiler::Compile(const ir::RegExpLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->CreateRegExpWithLiteral(expr, expr->Pattern(), static_cast(expr->Flags())); } void JSCompiler::Compile(const ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->LoadAccumulatorString(expr, expr->Str()); } void JSCompiler::Compile(const ir::UndefinedLiteral *expr) const @@ -757,51 +965,44 @@ void JSCompiler::Compile(const ir::UndefinedLiteral *expr) const } // Compile methods for MODULE-related nodes in alphabetical order -void JSCompiler::Compile(const ir::ExportAllDeclaration *st) const -{ - (void)st; - UNREACHABLE(); -} +void JSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const {} void JSCompiler::Compile(const ir::ExportDefaultDeclaration *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + st->Decl()->Compile(pg); + pg->StoreModuleVar(st, "default"); } void JSCompiler::Compile(const ir::ExportNamedDeclaration *st) const { - (void)st; - UNREACHABLE(); -} + PandaGen *pg = GetPandaGen(); + if (st->Decl() == nullptr) { + return; + } -void JSCompiler::Compile(const ir::ExportSpecifier *st) const -{ - (void)st; - UNREACHABLE(); + st->Decl()->Compile(pg); } -void JSCompiler::Compile(const ir::ImportDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportDefaultSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportDeclaration *st) const {} + +void JSCompiler::Compile([[maybe_unused]] const ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportNamespaceSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // Compile methods for STATEMENTS in alphabetical order @@ -825,74 +1026,202 @@ void JSCompiler::Compile(const ir::BreakStatement *st) const void JSCompiler::Compile(const ir::ClassDeclaration *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + auto lref = compiler::JSLReference::Create(pg, st->Definition()->Ident(), true); + st->Definition()->Compile(pg); + lref.SetValue(); } -void JSCompiler::Compile(const ir::ContinueStatement *st) const +static void CompileImpl(const ir::ContinueStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + compiler::Label *target = cg->ControlFlowChangeContinue(self->Ident()); + cg->Branch(self, target); } -void JSCompiler::Compile(const ir::DebuggerStatement *st) const +void JSCompiler::Compile(const ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } -void JSCompiler::Compile(const ir::DoWhileStatement *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::DebuggerStatement *st) const {} + +static void CompileImpl(const ir::DoWhileStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + auto *start_label = cg->AllocLabel(); + compiler::LabelTarget label_target(cg); + + cg->SetLabel(self, start_label); + + { + compiler::LocalRegScope reg_scope(cg, self->Scope()); + compiler::LabelContext label_ctx(cg, label_target); + self->Body()->Compile(cg); + } + + cg->SetLabel(self, label_target.ContinueTarget()); + compiler::Condition::Compile(cg, self->Test(), label_target.BreakTarget()); + + cg->Branch(self, start_label); + cg->SetLabel(self, label_target.BreakTarget()); } -void JSCompiler::Compile(const ir::EmptyStatement *st) const +void JSCompiler::Compile(const ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } +void JSCompiler::Compile([[maybe_unused]] const ir::EmptyStatement *st) const {} + void JSCompiler::Compile(const ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + st->GetExpression()->Compile(pg); } void JSCompiler::Compile(const ir::ForInStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LabelTarget label_target(pg); + + compiler::RegScope rs(pg); + compiler::VReg iter = pg->AllocReg(); + compiler::VReg prop_name = pg->AllocReg(); + + // create enumerator + st->Right()->Compile(pg); + pg->GetPropIterator(st); + pg->StoreAccumulator(st, iter); + + pg->SetLabel(st, label_target.ContinueTarget()); + + // get next prop of enumerator + pg->GetNextPropName(st, iter); + pg->StoreAccumulator(st, prop_name); + pg->BranchIfUndefined(st, label_target.BreakTarget()); + + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + auto lref = compiler::JSLReference::Create(pg, st->Left(), false); + pg->LoadAccumulator(st, prop_name); + lref.SetValue(); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + + { + compiler::LoopEnvScope env_scope(pg, st->Scope(), label_target); + st->Body()->Compile(pg); + } + + pg->Branch(st, label_target.ContinueTarget()); + pg->SetLabel(st, label_target.BreakTarget()); } void JSCompiler::Compile(const ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + + st->Right()->Compile(pg); + + compiler::LabelTarget label_target(pg); + auto iterator_type = st->IsAwait() ? compiler::IteratorType::ASYNC : compiler::IteratorType::SYNC; + compiler::Iterator iterator(pg, st, iterator_type); + + pg->SetLabel(st, label_target.ContinueTarget()); + + iterator.Next(); + iterator.Complete(); + pg->BranchIfTrue(st, label_target.BreakTarget()); + + iterator.Value(); + pg->StoreAccumulator(st, iterator.NextResult()); + + auto lref = compiler::JSLReference::Create(pg, st->Left(), false); + + { + compiler::IteratorContext for_of_ctx(pg, iterator, label_target); + pg->LoadAccumulator(st, iterator.NextResult()); + lref.SetValue(); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + compiler::LoopEnvScope env_scope(pg, st->Scope(), {}); + st->Body()->Compile(pg); + } + + pg->Branch(st, label_target.ContinueTarget()); + pg->SetLabel(st, label_target.BreakTarget()); } void JSCompiler::Compile(const ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + + if (st->Init() != nullptr) { + ASSERT(st->Init()->IsVariableDeclaration() || st->Init()->IsExpression()); + st->Init()->Compile(pg); + } + + auto *start_label = pg->AllocLabel(); + compiler::LabelTarget label_target(pg); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + compiler::LoopEnvScope env_scope(pg, label_target, st->Scope()); + pg->SetLabel(st, start_label); + + { + compiler::LocalRegScope reg_scope(pg, st->Scope()); + + if (st->Test() != nullptr) { + compiler::Condition::Compile(pg, st->Test(), label_target.BreakTarget()); + } + + st->Body()->Compile(pg); + pg->SetLabel(st, label_target.ContinueTarget()); + env_scope.CopyPetIterationCtx(); + } + + if (st->Update() != nullptr) { + st->Update()->Compile(pg); + } + + pg->Branch(st, start_label); + pg->SetLabel(st, label_target.BreakTarget()); } -void JSCompiler::Compile(const ir::FunctionDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::FunctionDeclaration *st) const {} + +void JSCompiler::Compile(const ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + auto *consequent_end = pg->AllocLabel(); + compiler::Label *statement_end = consequent_end; + + compiler::Condition::Compile(pg, st->Test(), consequent_end); + st->Consequent()->Compile(pg); + + if (st->Alternate() != nullptr) { + statement_end = pg->AllocLabel(); + pg->Branch(pg->Insns().back()->Node(), statement_end); + + pg->SetLabel(st, consequent_end); + st->Alternate()->Compile(pg); + } + + pg->SetLabel(st, statement_end); } -void JSCompiler::Compile(const ir::IfStatement *st) const +void CompileImpl(const ir::LabelledStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + compiler::LabelContext label_ctx(cg, self); + self->Body()->Compile(cg); } void JSCompiler::Compile(const ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } void JSCompiler::Compile(const ir::ReturnStatement *st) const @@ -921,16 +1250,47 @@ void JSCompiler::Compile(const ir::ReturnStatement *st) const } } -void JSCompiler::Compile(const ir::SwitchCaseStatement *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::SwitchStatement *self, PandaGen *cg) +{ + compiler::LocalRegScope lrs(cg, self->Scope()); + compiler::SwitchBuilder builder(cg, self); + compiler::VReg tag = cg->AllocReg(); + + builder.CompileTagOfSwitch(tag); + uint32_t default_index = 0; + + for (size_t i = 0; i < self->Cases().size(); i++) { + const auto *clause = self->Cases()[i]; + + if (clause->Test() == nullptr) { + default_index = i; + continue; + } + + builder.JumpIfCase(tag, i); + } + + if (default_index > 0) { + builder.JumpToDefault(default_index); + } else { + builder.Break(); + } + + for (size_t i = 0; i < self->Cases().size(); i++) { + builder.SetCaseTarget(i); + builder.CompileCaseStatements(i); + } +} + void JSCompiler::Compile(const ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } void JSCompiler::Compile(const ir::ThrowStatement *st) const @@ -963,9 +1323,8 @@ void JSCompiler::Compile(const ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -void JSCompiler::Compile(const ir::TSAnyKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -987,9 +1346,8 @@ void JSCompiler::Compile(const ir::TSBigintKeyword *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSBooleanKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1011,21 +1369,18 @@ void JSCompiler::Compile(const ir::TSConstructorType *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSEnumDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSEnumDeclaration *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSEnumMember *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSExternalModuleReference *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -1131,15 +1486,13 @@ void JSCompiler::Compile(const ir::TSNullKeyword *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSNumberKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSObjectKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1161,9 +1514,8 @@ void JSCompiler::Compile(const ir::TSQualifiedName *expr) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSStringKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1239,9 +1591,8 @@ void JSCompiler::Compile(const ir::TSTypeReference *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSUndefinedKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1251,16 +1602,13 @@ void JSCompiler::Compile(const ir::TSUnionType *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSUnknownKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSVoidKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } - -} // namespace panda::es2panda::compiler \ No newline at end of file +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/compilerContext.h b/ets2panda/compiler/core/compilerContext.h index 420a9fb18bc3e2407b8a89b958dd07da2dfce6eb..96e7144d450cdf54b18000960397670e80c3850a 100644 --- a/ets2panda/compiler/core/compilerContext.h +++ b/ets2panda/compiler/core/compilerContext.h @@ -16,13 +16,11 @@ #ifndef ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H #define ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H -#include "macros.h" -#include "mem/arena_allocator.h" +#include + #include "es2panda.h" #include "compiler/base/literals.h" - -#include -#include +#include "parser/parserImpl.h" namespace panda::es2panda::varbinder { class VarBinder; @@ -41,7 +39,7 @@ class CodeGen; class ProgramElement; class AstCompiler; -class CompilerContext { +class CompilerContext final { public: using CodeGenCb = std::function; @@ -52,72 +50,83 @@ public: { } + CompilerContext() = delete; NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; - varbinder::VarBinder *VarBinder() const + [[nodiscard]] varbinder::VarBinder *VarBinder() const noexcept { return varbinder_; } - checker::Checker *Checker() const + [[nodiscard]] checker::Checker *Checker() const noexcept { return checker_; } - Emitter *GetEmitter() const + [[nodiscard]] parser::ParserImpl *GetParser() const noexcept + { + return parser_; + } + + void SetParser(parser::ParserImpl *const parser) noexcept + { + parser_ = parser; + } + + [[nodiscard]] Emitter *GetEmitter() const noexcept { return emitter_; } - void SetEmitter(Emitter *emitter) + void SetEmitter(Emitter *emitter) noexcept { emitter_ = emitter; } - const CodeGenCb &GetCodeGenCb() const + [[nodiscard]] const CodeGenCb &GetCodeGenCb() const noexcept { return code_gen_cb_; } - int32_t AddContextLiteral(LiteralBuffer &&literals) + [[nodiscard]] int32_t AddContextLiteral(LiteralBuffer &&literals) { buff_storage_.emplace_back(std::move(literals)); return buff_storage_.size() - 1; } - const std::vector &ContextLiterals() const + [[nodiscard]] const std::vector &ContextLiterals() const noexcept { return buff_storage_; } - const CompilerOptions *Options() const + [[nodiscard]] const CompilerOptions *Options() const noexcept { return &options_; } - bool IsDebug() const + [[nodiscard]] bool IsDebug() const noexcept { return options_.is_debug; } - bool DumpDebugInfo() const + [[nodiscard]] bool DumpDebugInfo() const noexcept { return options_.dump_debug_info; } - bool IsDirectEval() const + [[nodiscard]] bool IsDirectEval() const noexcept { return options_.is_direct_eval; } - bool IsFunctionEval() const + [[nodiscard]] bool IsFunctionEval() const noexcept { return options_.is_function_eval; } - bool IsEval() const + [[nodiscard]] bool IsEval() const noexcept { return options_.is_eval; } @@ -125,6 +134,7 @@ public: private: varbinder::VarBinder *varbinder_; checker::Checker *checker_; + parser::ParserImpl *parser_ = nullptr; Emitter *emitter_ {}; std::vector buff_storage_; CompilerOptions options_; diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 14bc8b7fbdbde505a5043aef2087f4e2f417a36d..0d33af9dd5f188d697279484eade4585c5a1668e 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -44,9 +44,6 @@ #include "es2panda.h" #include "util/declgenEts2Ts.h" -#include -#include - namespace panda::es2panda::compiler { void CompilerImpl::HandleContextLiterals(CompilerContext *context) @@ -115,6 +112,8 @@ static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const Phase auto emitter = Emitter(&context); context.SetEmitter(&emitter); + context.SetParser(&parser); + parser.ParseScript(unit.input, unit.options.compilation_mode == CompilationMode::GEN_STD_LIB); for (auto *phase : get_phases()) { diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 03ecf30834638433b677dd8cf385f568d88f2c15..b886773d149e2f2f50b6d334cf1aa4991e38df5c 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -15,9 +15,6 @@ // // This is a sample lowering, of little value by itself. -// NOTE: gobabr. -// - temporary variables are inserted into the current scope without any accompanying definition -// construction; most likely, a proper AST checker would complain. // // desc: A compound assignment expression of the form E1 op= E2 is equivalent to E1 = // ((E1) op (E2)) as T, where T is the type of E1, except that E1 is evaluated only @@ -25,22 +22,18 @@ // #include "opAssignment.h" -#include "checker/types/typeFlag.h" -#include "varbinder/variableFlags.h" + +#include "parser/ETSparser.h" +#include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" -#include "compiler/core/compilerContext.h" #include "compiler/lowering/util.h" -#include "ir/astNode.h" -#include "ir/expression.h" #include "ir/opaqueTypeNode.h" #include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/binaryExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/memberExpression.h" -#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/blockExpression.h" #include "ir/statements/blockStatement.h" -#include "ir/ts/tsAsExpression.h" -#include "lexer/token/tokenType.h" +#include "ir/statements/expressionStatement.h" namespace panda::es2panda::compiler { @@ -83,52 +76,6 @@ static lexer::TokenType OpEqualToOp(const lexer::TokenType op_equal) UNREACHABLE(); } -// This should probably be a virtual method of AstNode -static ir::AstNode *CloneNode(checker::ETSChecker *checker, ir::AstNode *ast) -{ - if (ast->IsIdentifier()) { - const auto *id = ast->AsIdentifier(); - auto *res = checker->AllocNode(id->Name(), id->TypeAnnotation(), checker->Allocator()); - res->SetVariable(id->Variable()); - res->SetOptional(id->IsOptional()); - res->SetReference(id->IsReference()); - - if (id->IsTdz()) { - res->SetTdz(); - } - - if (id->IsAccessor()) { - res->SetAccessor(); - } - - if (id->IsMutator()) { - res->SetMutator(); - } - - res->SetPrivate(id->IsPrivate()); - if (id->IsIgnoreBox()) { - res->SetIgnoreBox(); - } - - return res; - } - - ASSERT(ast->IsMemberExpression()); - - auto *me = ast->AsMemberExpression(); - auto *object = CloneNode(checker, me->Object())->AsExpression(); - auto *property = CloneNode(checker, me->Property())->AsExpression(); - - auto *res = - checker->AllocNode(object, property, me->Kind(), me->IsComputed(), me->IsOptional()); - res->SetPropVar(me->PropVar()); - if (me->IsIgnoreBox()) { - res->SetIgnoreBox(); - } - - return res; -} - void AdjustBoxingUnboxingFlags(ir::Expression *new_expr, const ir::Expression *old_expr) { // NOTE: gogabr. make sure that the checker never puts both a boxing and an unboxing flag on the same node. @@ -138,112 +85,128 @@ void AdjustBoxingUnboxingFlags(ir::Expression *new_expr, const ir::Expression *o const ir::BoxingUnboxingFlags old_unboxing_flag {old_expr->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG}; - if (new_expr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) && - old_boxing_flag != ir::BoxingUnboxingFlags::NONE) { + if (new_expr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { new_expr->SetBoxingUnboxingFlags(old_boxing_flag); - } else if (new_expr->TsType()->IsETSObjectType() && old_unboxing_flag != ir::BoxingUnboxingFlags::NONE) { + } else if (new_expr->TsType()->IsETSObjectType()) { new_expr->SetBoxingUnboxingFlags(old_unboxing_flag); } } -ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, ir::AssignmentExpression *assignment) +ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, parser::ETSParser *parser, + ir::AssignmentExpression *assignment) { if (assignment->TsType() == nullptr) { // hasn't been through checker return assignment; } - checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; + const auto op_equal = assignment->OperatorType(); + ASSERT(op_equal != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + ASSERT(parser != nullptr); - ir::Expression *tmp_assignment_for_obj = nullptr; - ir::Expression *tmp_assignment_for_prop = nullptr; - ir::Expression *left_adjusted = nullptr; + auto *const allocator = checker->Allocator(); - auto *left = assignment->Left(); - auto *right = assignment->Right(); + auto *const left = assignment->Left(); + auto *const right = assignment->Right(); + auto *const scope = NearestScope(assignment); - const auto op_equal = assignment->OperatorType(); - ASSERT(op_equal != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + std::string new_assignment_statements {}; - if (left->IsIdentifier() || (left->IsMemberExpression() && left->AsMemberExpression()->Object()->IsIdentifier() && - left->AsMemberExpression()->Property()->IsIdentifier())) { - left_adjusted = left->AsExpression(); - } else { - ASSERT(left->IsMemberExpression()); - - auto *left_memb = left->AsMemberExpression(); - auto *scope = NearestScope(assignment); - - auto *tmp_obj_var_id = Gensym(checker->Allocator()); - auto *tmp_obj_var = scope->AddDecl( - checker->Allocator(), tmp_obj_var_id->Name(), varbinder::VariableFlags::LOCAL); - tmp_obj_var->SetTsType(left_memb->Object()->TsType()); - tmp_obj_var_id->SetVariable(tmp_obj_var); - tmp_obj_var_id->SetTsType(tmp_obj_var->TsType()); - tmp_assignment_for_obj = checker->AllocNode( - tmp_obj_var_id, left_memb->Object(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - - tmp_assignment_for_obj->SetTsType(tmp_obj_var->TsType()); - - auto *property = left_memb->Property(); - if (!property->IsIdentifier()) { - auto *tmp_prop_var_id = Gensym(checker->Allocator()); - auto *tmp_prop_var = scope->AddDecl( - checker->Allocator(), tmp_prop_var_id->Name(), varbinder::VariableFlags::LOCAL); - tmp_prop_var->SetTsType(left_memb->Property()->TsType()); - tmp_prop_var_id->SetVariable(tmp_prop_var); - tmp_prop_var_id->SetTsType(tmp_prop_var->TsType()); - - tmp_assignment_for_prop = checker->AllocNode( - tmp_prop_var_id, left_memb->Property(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - tmp_assignment_for_prop->SetTsType(tmp_prop_var->TsType()); - property = tmp_prop_var_id; - } + ir::Identifier *ident1; + ir::Identifier *ident2 = nullptr; + ir::Expression *object = nullptr; + ir::Expression *property = nullptr; - left_adjusted = checker->AllocNode(tmp_obj_var_id, property, left_memb->Kind(), - left_memb->IsComputed(), left_memb->IsOptional()); - left_adjusted->AsMemberExpression()->SetPropVar(left_memb->PropVar()); - left_adjusted->AsMemberExpression()->SetObjectType(left_memb->ObjType()); - left_adjusted->SetTsType(left->TsType()); + checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; - if (left_memb->IsIgnoreBox()) { - left_adjusted->AsMemberExpression()->SetIgnoreBox(); + // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] + if (left->IsIdentifier()) { + ident1 = left->AsIdentifier(); + } else if (left->IsMemberExpression()) { + auto *const member_expression = left->AsMemberExpression(); + + if (object = member_expression->Object(); object->IsIdentifier()) { + ident1 = object->AsIdentifier(); + } else { + ident1 = Gensym(allocator); + new_assignment_statements = "let @@I1 = (@@E2); "; } - } - left_adjusted->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); // to be recomputed - auto *left_cloned = CloneNode(checker, left_adjusted)->AsExpression(); - auto *new_right = checker->AllocNode(left_cloned, right, OpEqualToOp(op_equal)); - - auto *lc_type = left_cloned->Check(checker); + if (property = member_expression->Property(); property->IsIdentifier()) { + ident2 = property->AsIdentifier(); + } else { + ident2 = Gensym(allocator); + new_assignment_statements += "let @@I3 = (@@E4); "; + } + } else { + UNREACHABLE(); + } + // Create proxy TypeNode for left hand of assignment expression + auto *lc_type = left->TsType(); if (auto *lc_type_as_primitive = checker->ETSBuiltinTypeAsPrimitiveType(lc_type); lc_type_as_primitive != nullptr) { lc_type = lc_type_as_primitive; } - - auto *lc_type_node = checker->AllocNode(lc_type); - auto *new_right_converted = checker->AllocNode(new_right, lc_type_node, false); - auto *new_assignment = checker->AllocNode(left_adjusted, new_right_converted, - lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - - ir::Expression *res = new_assignment; - if (tmp_assignment_for_obj != nullptr) { - ArenaVector seq_exprs {checker->Allocator()->Adapter()}; - seq_exprs.push_back(tmp_assignment_for_obj); - - if (tmp_assignment_for_prop != nullptr) { - seq_exprs.push_back(tmp_assignment_for_prop); + auto *expr_type = checker->AllocNode(lc_type); + + // Generate ArkTS code string for new lowered assignment expression: + std::string left_hand = "@@I5"; + std::string right_hand = "@@I7"; + + if (ident2 != nullptr) { + if (auto const kind = left->AsMemberExpression()->Kind(); kind == ir::MemberExpressionKind::PROPERTY_ACCESS) { + left_hand += ".@@I6"; + right_hand += ".@@I8"; + } else if (kind == ir::MemberExpressionKind::ELEMENT_ACCESS) { + left_hand += "[@@I6]"; + right_hand += "[@@I8]"; + } else { + UNREACHABLE(); } + } - seq_exprs.push_back(new_assignment); - auto *seq = checker->AllocNode(std::move(seq_exprs)); - res = seq; + new_assignment_statements += left_hand + " = (" + right_hand + ' ' + + std::string {lexer::TokenToString(OpEqualToOp(op_equal))} + " (@@E9)) as @@T10"; + // std::cout << "Lowering statements: " << new_assignment_statements << std::endl; + + // Parse ArkTS code string and create and process corresponding AST node(s) + auto expression_ctx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + auto *lowering_result = parser->CreateFormattedExpression( + new_assignment_statements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, property, + ident1->Clone(allocator), ident2 != nullptr ? ident2->Clone(allocator) : nullptr, ident1->Clone(allocator), + ident2 != nullptr ? ident2->Clone(allocator) : nullptr, right, expr_type); + lowering_result->SetParent(assignment->Parent()); + + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(lowering_result, scope); + lowering_result->Check(checker); + + // Adjust [un]boxing flag + ir::AssignmentExpression *new_assignment; + if (lowering_result->IsAssignmentExpression()) { + new_assignment = lowering_result->AsAssignmentExpression(); + } else if (lowering_result->IsBlockExpression() && !lowering_result->AsBlockExpression()->Statements().empty() && + lowering_result->AsBlockExpression()->Statements().back()->IsExpressionStatement() && + lowering_result->AsBlockExpression() + ->Statements() + .back() + ->AsExpressionStatement() + ->GetExpression() + ->IsAssignmentExpression()) { + new_assignment = lowering_result->AsBlockExpression() + ->Statements() + .back() + ->AsExpressionStatement() + ->GetExpression() + ->AsAssignmentExpression(); + } else { + UNREACHABLE(); } - res->SetParent(assignment->Parent()); - new_assignment->Check(checker); + // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. + // Then this code will become unnecessary. AdjustBoxingUnboxingFlags(new_assignment, assignment); - return res; + return lowering_result; } bool OpAssignmentLowering::Perform(CompilerContext *ctx, parser::Program *program) @@ -257,12 +220,13 @@ bool OpAssignmentLowering::Perform(CompilerContext *ctx, parser::Program *progra } } - checker::ETSChecker *checker = ctx->Checker()->AsETSChecker(); + auto *const checker = ctx->Checker()->AsETSChecker(); + auto *const parser = ctx->GetParser()->AsETSParser(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker, parser](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { - return HandleOpAssignment(checker, ast->AsAssignmentExpression()); + return HandleOpAssignment(checker, parser, ast->AsAssignmentExpression()); } return ast; diff --git a/ets2panda/compiler/lowering/util.cpp b/ets2panda/compiler/lowering/util.cpp index 247f182093c3aadccab01eb842fd1e022f4e33b9..ed4d02de6569c07202f896d403f315b4ef0074f7 100644 --- a/ets2panda/compiler/lowering/util.cpp +++ b/ets2panda/compiler/lowering/util.cpp @@ -31,17 +31,18 @@ varbinder::Scope *NearestScope(const ir::AstNode *ast) return ast->Scope(); } -static size_t GENSYM_COUNTER = 0; +ir::Identifier *Gensym(ArenaAllocator *const allocator) +{ + util::UString const s = GenName(allocator); + return allocator->New(s.View(), allocator); +} -ir::Identifier *Gensym(ArenaAllocator *allocator) +util::UString GenName(ArenaAllocator *const allocator) { - std::stringstream ss; - ss << "gensym$" << (GENSYM_COUNTER++); - const ArenaString s {allocator->Adapter()}; - const auto str = ss.str(); - auto *arena_pointer = allocator->Alloc(str.size() + 1); - std::memmove(arena_pointer, reinterpret_cast(str.c_str()), str.size() + 1); - return allocator->New(util::StringView(reinterpret_cast(arena_pointer)), allocator); + static std::string const GENSYM_CORE = "gensym$_"; + static std::size_t gensym_counter = 0U; + + return util::UString {GENSYM_CORE + std::to_string(++gensym_counter), allocator}; } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/util.h b/ets2panda/compiler/lowering/util.h index ba3d290a136019a4dff8fdbb411b61a20e9401e4..d8344157b1c0e8cf4e255b63c1ebc06478103f12 100644 --- a/ets2panda/compiler/lowering/util.h +++ b/ets2panda/compiler/lowering/util.h @@ -16,14 +16,13 @@ #ifndef ES2PANDA_COMPILER_LOWERING_UTIL_H #define ES2PANDA_COMPILER_LOWERING_UTIL_H -#include "varbinder/scope.h" -#include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" namespace panda::es2panda::compiler { varbinder::Scope *NearestScope(const ir::AstNode *ast); ir::Identifier *Gensym(ArenaAllocator *allocator); +util::UString GenName(ArenaAllocator *allocator); } // namespace panda::es2panda::compiler diff --git a/ets2panda/es2panda.h b/ets2panda/es2panda.h index 40774251e567cf0ba3ed97295b1960267869cddd..bd23a328c2a8803e5c685e647d08ffa317309dcb 100644 --- a/ets2panda/es2panda.h +++ b/ets2panda/es2panda.h @@ -93,6 +93,7 @@ struct CompilerOptions { bool is_direct_eval {}; bool is_function_eval {}; bool dump_ast {}; + bool op_dump_ast_only_silent {}; bool dump_checked_ast {}; bool dump_asm {}; bool dump_debug_info {}; diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index bceb87943b488f79aa83938d004a22ee54d1d161..4db50cff077bed7228d0102d09035f34df1efb3d 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -92,7 +92,7 @@ bool AstNode::IsAnyChild(const NodePredicate &cb) const void AnnotatedAstNode::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 950d346f6f7cd740eed5cb85242a15b16da29324..f164f1660c7d4bd4ae7438d7244faf93d3032686 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -448,6 +448,13 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, + [[maybe_unused]] AstNode *const parent = nullptr) + { + UNREACHABLE(); + } + virtual void TransformChildren(const NodeTransformer &cb) = 0; virtual void Iterate(const NodeTraverser &cb) const = 0; void TransformChildrenRecursively(const NodeTransformer &cb); diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 9b8099c6002ea06f40396c3c6ca3321c435bf49d..e05e9a9c2fe3cbcb6303983fc3fbe7aca42cdbb7 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -160,7 +160,8 @@ _(VARIABLE_DECLARATOR, VariableDeclarator) \ _(WHILE_STATEMENT, WhileStatement) \ _(YIELD_EXPRESSION, YieldExpression) \ - _(OPAQUE_TYPE_NODE, OpaqueTypeNode) + _(OPAQUE_TYPE_NODE, OpaqueTypeNode) \ + _(BLOCK_EXPRESSION, BlockExpression) #define AST_NODE_REINTERPRET_MAPPING(_) \ _(ARRAY_EXPRESSION, ARRAY_PATTERN, ArrayExpression, ArrayPattern) \ diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 12e57a0dbcb10ad54bb56bc9a9365d5a8a68fb37..31520c1ffd1097eb9e0e568d5258279d52443180 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 7341aab83e5a2787b52579e2eb10a6256299f4bf..b952989226c9e1f4d630395d56959aa89b51acef 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -50,6 +50,12 @@ DEFINE_BITOPS(ClassDefinitionModifiers) class ClassDefinition : public TypedAstNode { public: + ClassDefinition() = delete; + ~ClassDefinition() override = default; + + NO_COPY_SEMANTIC(ClassDefinition); + NO_MOVE_SEMANTIC(ClassDefinition); + explicit ClassDefinition(varbinder::LocalScope *scope, const util::StringView &private_id, Identifier *ident, TSTypeParameterDeclaration *type_params, TSTypeParameterInstantiation *super_type_params, ArenaVector &&implements, MethodDefinition *ctor, @@ -104,82 +110,82 @@ public: return scope_; } - const Identifier *Ident() const + [[nodiscard]] const Identifier *Ident() const noexcept { return ident_; } - Identifier *Ident() + [[nodiscard]] Identifier *Ident() noexcept { return ident_; } - void SetIdent(ir::Identifier *ident) + void SetIdent(ir::Identifier *ident) noexcept { ident_ = ident; } - const util::StringView &PrivateId() const + [[nodiscard]] const util::StringView &PrivateId() const noexcept { return private_id_; } - const util::StringView &InternalName() const + [[nodiscard]] const util::StringView &InternalName() const noexcept { return private_id_; } - void SetInternalName(util::StringView internal_name) + void SetInternalName(util::StringView internal_name) noexcept { private_id_ = internal_name; } - Expression *Super() + [[nodiscard]] Expression *Super() noexcept { return super_class_; } - const Expression *Super() const + [[nodiscard]] const Expression *Super() const noexcept { return super_class_; } - bool IsGlobal() const + [[nodiscard]] bool IsGlobal() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL) != 0; } - bool IsExtern() const + [[nodiscard]] bool IsExtern() const noexcept { return (modifiers_ & ClassDefinitionModifiers::EXTERN) != 0; } - bool IsInner() const + [[nodiscard]] bool IsInner() const noexcept { return (modifiers_ & ClassDefinitionModifiers::INNER) != 0; } - bool IsGlobalInitialized() const + [[nodiscard]] bool IsGlobalInitialized() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL_INITIALIZED) != 0; } - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const noexcept { return lang_; } - void SetGlobalInitialized() + void SetGlobalInitialized() noexcept { modifiers_ |= ClassDefinitionModifiers::GLOBAL_INITIALIZED; } - void SetInnerModifier() + void SetInnerModifier() noexcept { modifiers_ |= ClassDefinitionModifiers::INNER; } - ClassDefinitionModifiers Modifiers() const + [[nodiscard]] ClassDefinitionModifiers Modifiers() const noexcept { return modifiers_; } @@ -193,37 +199,37 @@ public: body_.insert(body_.end(), body.begin(), body.end()); } - ArenaVector &Body() + [[nodiscard]] ArenaVector &Body() noexcept { return body_; } - const ArenaVector &Body() const + [[nodiscard]] const ArenaVector &Body() const noexcept { return body_; } - MethodDefinition *Ctor() + [[nodiscard]] MethodDefinition *Ctor() noexcept { return ctor_; } - ArenaVector &Implements() + [[nodiscard]] ArenaVector &Implements() noexcept { return implements_; } - const ArenaVector &Implements() const + [[nodiscard]] const ArenaVector &Implements() const noexcept { return implements_; } - const ir::TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const ir::TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - ir::TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] ir::TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } @@ -235,7 +241,9 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 192aecf3038e85c9818b50e6e3161d8c24b5efe7..62b0ebb1003ff02519fe98bdc74c1bd7df759be1 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -20,17 +20,17 @@ namespace panda::es2panda::ir { -Identifier *ClassElement::Id() +Identifier *ClassElement::Id() noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -const Identifier *ClassElement::Id() const +const Identifier *ClassElement::Id() const noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -bool ClassElement::IsPrivateElement() const +bool ClassElement::IsPrivateElement() const noexcept { if (IsClassStaticBlock()) { return false; diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index ea99fb156653d56d229f50c4ff6972157bae7382..034f63036d56192ade204dce831d29fc520626be 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -23,8 +23,14 @@ class Expression; class ClassElement : public TypedStatement { public: - explicit ClassElement(AstNodeType element_type, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassElement() = delete; + ~ClassElement() override = default; + + NO_COPY_SEMANTIC(ClassElement); + NO_MOVE_SEMANTIC(ClassElement); + + explicit ClassElement(AstNodeType const element_type, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : TypedStatement(element_type, modifiers), key_(key), value_(value), @@ -33,37 +39,38 @@ public: { } - Identifier *Id(); - const Identifier *Id() const; + [[nodiscard]] Identifier *Id() noexcept; + + [[nodiscard]] const Identifier *Id() const noexcept; - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Value() + [[nodiscard]] Expression *Value() noexcept { return value_; } - const Expression *Value() const + [[nodiscard]] const Expression *Value() const noexcept { return value_; } - bool IsPrivateElement() const; + [[nodiscard]] bool IsPrivateElement() const noexcept; - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } - bool IsComputed() const + [[nodiscard]] bool IsComputed() const noexcept { return is_computed_; } @@ -73,7 +80,14 @@ public: decorators_ = std::move(decorators); } - virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; + void AddDecorator(ir::Decorator *const decorator) + { + if (decorator != nullptr) { + decorators_.emplace_back(decorator); + } + } + + [[nodiscard]] virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; protected: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 24bfd844c1b8dad6d7ee340955a11133a97a32bb..081a992abfc21948efc67dd5bda7052c2deb1e4d 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -26,9 +26,6 @@ #include "ir/expression.h" #include "ir/expressions/identifier.h" -#include -#include - namespace panda::es2panda::ir { void ClassProperty::TransformChildren(const NodeTransformer &cb) { @@ -100,4 +97,31 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const key = key_->Clone(allocator)->AsExpression(); + auto *const value = value_->Clone(allocator)->AsExpression(); + auto *const type_annotation = type_annotation_->Clone(allocator, this); + + if (auto *const clone = allocator->New(key, value, type_annotation, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + + key->SetParent(clone); + value->SetParent(clone); + type_annotation->SetParent(clone); + + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 82738acdab8b41e04f7d507aeed1a87b0bf62344..fc9773fc0f74a130cd2e1ae1dc09b92f07268081 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -28,28 +28,37 @@ class TypeNode; class ClassProperty : public ClassElement { public: - explicit ClassProperty(Expression *key, Expression *value, TypeNode *type_annotation, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassProperty() = delete; + ~ClassProperty() override = default; + + NO_COPY_SEMANTIC(ClassProperty); + NO_MOVE_SEMANTIC(ClassProperty); + + explicit ClassProperty(Expression *const key, Expression *const value, TypeNode *const type_annotation, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::CLASS_PROPERTY, key, value, modifiers, allocator, is_computed), type_annotation_(type_annotation) { } - // NOTE: csabahurton. friend relationship can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - TypeNode *TypeAnnotation() const + [[nodiscard]] TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - PrivateFieldKind ToPrivateFieldKind(bool is_static) const override + [[nodiscard]] PrivateFieldKind ToPrivateFieldKind(bool const is_static) const override { return is_static ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index 3b9e5c419b8f49dbde292e01e9850584245f5ac7..beb884f79b09a942806568245b84a242d24ee780 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -60,9 +60,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Statement *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index aadfb87af2223e923ce9840dd9e4690d50bea5ef..e85858d4b34eb4a7533e340431a087bf6e8908a1 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -37,7 +37,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Statement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index f88b13cc03b88649618baabbb677af035f4dce63..ed43fa1e0c5019d3e1fdc6f123eb67d6f794de51 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -15,10 +15,9 @@ #include "metaProperty.h" -#include "es2panda.h" -#include "compiler/core/pandagen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -45,32 +44,28 @@ void MetaProperty::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "MetaProperty"}, {"kind", kind}}); } -void MetaProperty::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void MetaProperty::Compile(compiler::PandaGen *pg) const { - if (kind_ == ir::MetaProperty::MetaPropertyKind::NEW_TARGET) { - pg->GetNewTarget(this); - return; - } + pg->GetAstCompiler()->Compile(this); +} - if (kind_ == ir::MetaProperty::MetaPropertyKind::IMPORT_META) { - // NOTE - pg->Unimplemented(); - } +void MetaProperty::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *MetaProperty::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *MetaProperty::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi. - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *MetaProperty::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *MetaProperty::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index 7a3d4e7f1736685ee21cd162a22f70506a014073..0ec7e846045e5b81b8200bd268980519223a1bf4 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -44,13 +44,14 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: MetaPropertyKind kind_; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index cff3cf3c6bd661e08997ecfc465c3c3b6208bd3c..a74af0796a389dc140a37f467529595aa4cfb475 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -16,34 +16,23 @@ #include "methodDefinition.h" #include "varbinder/scope.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/base/classDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/typeNode.h" -#include "checker/ETSchecker.h" - -#include +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { ScriptFunction *MethodDefinition::Function() { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } const ScriptFunction *MethodDefinition::Function() const { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } -PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool is_static) const +PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool const is_static) const { switch (kind_) { case MethodDefinitionKind::METHOD: { @@ -131,204 +120,57 @@ void MethodDefinition::Dump(ir::AstDumper *dumper) const {"decorators", decorators_}}); } -void MethodDefinition::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void MethodDefinition::Compile([[maybe_unused]] compiler::ETSGen *etsg) const {} - -checker::Type *MethodDefinition::Check([[maybe_unused]] checker::TSChecker *checker) +void MethodDefinition::Compile(compiler::PandaGen *pg) const { - return nullptr; + pg->GetAstCompiler()->Compile(this); } -checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) +void MethodDefinition::Compile(compiler::ETSGen *etsg) const { - auto *script_func = Function(); - - if (script_func->IsProxy()) { - return nullptr; - } - - // NOTE: aszilagyi. make it correctly check for open function not have body - if (!script_func->HasBody() && - !(IsAbstract() || IsNative() || IsDeclare() || checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { - checker->ThrowTypeError("Only abstract or native methods can't have body.", script_func->Start()); - } - - if (script_func->ReturnTypeAnnotation() == nullptr && (IsNative() || (IsDeclare() && !IsConstructor()))) { - checker->ThrowTypeError("Native and Declare methods should have explicit return type.", script_func->Start()); - } - - if (TsType() == nullptr) { - SetTsType(checker->BuildMethodSignature(this)); - } - - CheckMethodModifiers(checker); - - if (IsNative() && script_func->ReturnTypeAnnotation() == nullptr) { - checker->ThrowTypeError("'Native' method should have explicit return type", script_func->Start()); - } - - if (IsNative() && (script_func->IsGetter() || script_func->IsSetter())) { - checker->ThrowTypeError("'Native' modifier is invalid for Accessors", script_func->Start()); - } - - if (script_func->HasBody() && (IsNative() || IsAbstract() || IsDeclare())) { - checker->ThrowTypeError("Native, Abstract and Declare methods cannot have body.", script_func->Body()->Start()); - } - - if (script_func->IsAsyncFunc()) { - auto *ret_type = static_cast(script_func->Signature()->ReturnType()); - if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { - checker->ThrowTypeError("Return type of async function must be 'Promise'.", script_func->Start()); - } - } else if (script_func->HasBody() && !script_func->IsExternal()) { - checker::ScopeContext scope_ctx(checker, script_func->Scope()); - checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), - checker->Context().ContainingClass()); - checker->Context().SetContainingSignature(checker->GetSignatureFromMethodDefinition(this)); - - if (IsStatic() && !IsConstructor() && - !checker->Context().ContainingClass()->HasObjectFlag(checker::ETSObjectFlags::GLOBAL)) { - checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); - } - - if (IsConstructor()) { - checker->AddStatus(checker::CheckerStatus::IN_CONSTRUCTOR); - } - - if (IsExtensionMethod()) { - CheckExtensionMethod(checker, script_func); - } - - script_func->Body()->Check(checker); - - // In case of inferred function's return type set it forcedly to all return statements; - if (script_func->Signature()->HasSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE) && - script_func->ReturnTypeAnnotation() == nullptr && script_func->Body() != nullptr && - script_func->Body()->IsStatement()) { - script_func->Body()->AsStatement()->SetReturnType(checker, script_func->Signature()->ReturnType()); - } - - checker->Context().SetContainingSignature(nullptr); - } - - if (script_func->IsSetter() && (script_func->Signature()->ReturnType() != checker->GlobalBuiltinVoidType())) { - checker->ThrowTypeError("Setter must have void return type", script_func->Start()); - } - - if (script_func->IsGetter() && (script_func->Signature()->ReturnType() == checker->GlobalBuiltinVoidType())) { - checker->ThrowTypeError("Getter must return a value", script_func->Start()); - } - - checker->CheckOverride(TsType()->AsETSFunctionType()->FindSignature(Function())); - - for (auto *it : overloads_) { - it->Check(checker); - } - - if (script_func->IsRethrowing()) { - checker->CheckRethrowingFunction(script_func); - } - - return TsType(); + etsg->GetAstCompiler()->Compile(this); } -void MethodDefinition::CheckExtensionMethod(checker::ETSChecker *checker, ScriptFunction *extension_func) +checker::Type *MethodDefinition::Check(checker::TSChecker *checker) { - auto *const class_type = extension_func->Signature()->Params()[0]->TsType(); - if (!class_type->IsETSObjectType() || - (!class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CLASS) && - !class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::INTERFACE))) { - checker->ThrowTypeError("Extension function can only defined for class and interface type.", Start()); - } - - checker->AddStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD); - - checker::SignatureInfo *original_extension_sig_info = checker->Allocator()->New( - extension_func->Signature()->GetSignatureInfo(), checker->Allocator()); - original_extension_sig_info->min_arg_count -= 1; - original_extension_sig_info->params.erase(original_extension_sig_info->params.begin()); - checker::Signature *original_extension_sigature = checker->CreateSignature( - original_extension_sig_info, extension_func->Signature()->ReturnType(), extension_func); - - CheckExtensionIsShadowedByMethod(checker, class_type->AsETSObjectType(), extension_func, - original_extension_sigature); + return checker->GetAnalyzer()->Check(this); } -void MethodDefinition::CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, checker::Signature *sigature) +checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) { - if (obj_type == nullptr) { - return; - } - - CheckExtensionIsShadowedInCurrentClassOrInterface(checker, obj_type, extension_func, sigature); - - for (auto *interface : obj_type->Interfaces()) { - CheckExtensionIsShadowedByMethod(checker, interface, extension_func, sigature); - } - - CheckExtensionIsShadowedByMethod(checker, obj_type->SuperType(), extension_func, sigature); + return checker->GetAnalyzer()->Check(this); } -void MethodDefinition::CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, - checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, - checker::Signature *sigature) +// NOLINTNEXTLINE(google-default-arguments) +MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - const auto method_name = extension_func->Id()->Name(); - // Only check if there are class and interfaces' instance methods which would shadow instance extension method - auto *const variable = obj_type->GetOwnProperty(method_name); - if (variable == nullptr) { - return; - } + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; - const auto *const func_type = variable->TsType()->AsETSFunctionType(); - for (auto *func_signature : func_type->CallSignatures()) { - sigature->SetReturnType(func_signature->ReturnType()); - if (!checker->Relation()->IsIdenticalTo(sigature, func_signature)) { - continue; + if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); } - checker->ReportWarning({"extension is shadowed by a instance member function '", func_type->Name(), - func_signature, "' in class ", obj_type->Name()}, - extension_func->Body()->Start()); - return; - } -} - -void MethodDefinition::CheckMethodModifiers(checker::ETSChecker *checker) -{ - auto const not_valid_in_abstract = ir::ModifierFlags::NATIVE | ir::ModifierFlags::PRIVATE | - ir::ModifierFlags::OVERRIDE | ir::ModifierFlags::FINAL | - ir::ModifierFlags::STATIC; + if (key != nullptr) { + key->SetParent(clone); + } - if (IsAbstract() && (flags_ & not_valid_in_abstract) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): an abstract method can't have private, override, static, final or native " - "modifier.", - Start()); - } + if (value != nullptr) { + value->SetParent(clone); + } - if ((IsAbstract() || (!Function()->HasBody() && !IsNative() && !IsDeclare())) && - !(checker->HasStatus(checker::CheckerStatus::IN_ABSTRACT) || - checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { - checker->ThrowTypeError("Non abstract class has abstract method.", Start()); - } + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } - auto const not_valid_in_final = ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::STATIC | ir::ModifierFlags::NATIVE; + for (auto *const overloads : overloads_) { + clone->AddOverload(overloads->Clone(allocator, clone)); + } - if (IsFinal() && (flags_ & not_valid_in_final) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): a final method can't have abstract, static or native modifier.", Start()); + return clone; } - auto const not_valid_in_static = - ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::FINAL | ir::ModifierFlags::OVERRIDE; - - if (IsStatic() && (flags_ & not_valid_in_static) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): a static method can't have abstract, final or override modifier.", Start()); - } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index 079bddf66cfa20019c67274a2b4b1579b4c0af61..761e19374ffca0312c60496934cfd794e1c3c054 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -16,41 +16,54 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H #define ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H -#include "checker/types/ets/etsObjectType.h" -#include "checker/types/signature.h" #include "ir/base/classElement.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { + class Expression; +class ScriptFunction; enum class MethodDefinitionKind { NONE, CONSTRUCTOR, METHOD, EXTENSION_METHOD, GET, SET }; class MethodDefinition : public ClassElement { public: - explicit MethodDefinition(MethodDefinitionKind kind, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + MethodDefinition() = delete; + ~MethodDefinition() override = default; + + NO_COPY_SEMANTIC(MethodDefinition); + NO_MOVE_SEMANTIC(MethodDefinition); + + explicit MethodDefinition(MethodDefinitionKind const kind, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::METHOD_DEFINITION, key, value, modifiers, allocator, is_computed), kind_(kind), overloads_(allocator->Adapter()) { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + MethodDefinitionKind Kind() const { return kind_; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return kind_ == MethodDefinitionKind::CONSTRUCTOR; } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return kind_ == MethodDefinitionKind::EXTENSION_METHOD; } - const ArenaVector &Overloads() const + [[nodiscard]] const ArenaVector &Overloads() const noexcept { return overloads_; } @@ -60,12 +73,12 @@ public: overloads_ = std::move(overloads); } - void AddOverload(MethodDefinition *overload) + void AddOverload(MethodDefinition *const overload) { - overloads_.push_back(overload); + overloads_.emplace_back(overload); } - bool HasOverload(MethodDefinition *overload) + [[nodiscard]] bool HasOverload(MethodDefinition *overload) noexcept { return std::find(overloads_.begin(), overloads_.end(), overload) != overloads_.end(); } @@ -73,22 +86,18 @@ public: ScriptFunction *Function(); const ScriptFunction *Function() const; PrivateFieldKind ToPrivateFieldKind(bool is_static) const override; - void CheckMethodModifiers(checker::ETSChecker *checker); - void CheckExtensionMethod(checker::ETSChecker *checker, ScriptFunction *extension_func); - void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, checker::Signature *sigature); - void CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, - checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, - checker::Signature *sigature); + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: MethodDefinitionKind kind_; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index f607be57b12bc097976ea5ea62d080cc8809aac4..962be16443769caee63d58314ed3f6ee1164c249 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -16,29 +16,26 @@ #include "property.h" #include "es2panda.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/validationInfo.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -Property::Property([[maybe_unused]] Tag const tag, Expression *const key, Expression *const value) : Property(*this) +Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expression *const key, + Expression *const value) + : Property(other) { key_ = key; value_ = value; } // NOLINTNEXTLINE(google-default-arguments) -Expression *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator) : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator) : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; - if (auto *const clone = allocator->New(Tag {}, key, value); clone != nullptr) { + if (auto *const clone = allocator->New(Tag {}, *this, key, value); clone != nullptr) { if (key != nullptr) { key->SetParent(clone); } @@ -170,15 +167,23 @@ void Property::Dump(ir::AstDumper *dumper) const {"kind", kind}}); } -void Property::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void Property::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void Property::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *Property::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *Property::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *Property::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *Property::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index 91d91512c44d69921b94b4698ef2043ae9be9982..22759a0aca8344b9d2fb8fc578c1855ddef8de5d 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -50,7 +50,7 @@ public: { } - explicit Property(Tag tag, Expression *key, Expression *value); + explicit Property(Tag tag, Property const &other, Expression *key, Expression *value); [[nodiscard]] Expression *Key() noexcept { @@ -103,7 +103,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); @@ -111,9 +111,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; protected: Property(Property const &other) : Expression(static_cast(other)) diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index d7477e92b5b7cd519c9d50af95313d86ef5ba972..a058ba9da1a18793844609699b2cdbb007b279c1 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -16,36 +16,22 @@ #include "scriptFunction.h" #include "varbinder/scope.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/typeNode.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/blockStatement.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -bool ScriptFunction::HasBody() const -{ - return body_ != nullptr; -} -ir::ScriptFunctionFlags ScriptFunction::Flags() const +std::size_t ScriptFunction::FormalParamsLength() const noexcept { - return func_flags_; -} - -size_t ScriptFunction::FormalParamsLength() const -{ - size_t length = 0; + std::size_t length = 0U; for (const auto *param : params_) { if (param->IsRestElement() || param->IsAssignmentPattern()) { break; } - length++; + ++length; } return length; @@ -117,19 +103,22 @@ void ScriptFunction::Dump(ir::AstDumper *dumper) const } } -void ScriptFunction::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ScriptFunction::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ScriptFunction::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} +void ScriptFunction::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ScriptFunction::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ScriptFunction::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ScriptFunction::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ScriptFunction::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 93e134422716eda3f0635a8ab6982427df2d6bea..653a085db5ba2ebf1ee8ee71b4eb318ed201a530 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -30,7 +30,14 @@ class TSTypeParameterDeclaration; class TypeNode; class ScriptFunction : public AstNode { +private: public: + ScriptFunction() = delete; + ~ScriptFunction() override = default; + + NO_COPY_SEMANTIC(ScriptFunction); + NO_MOVE_SEMANTIC(ScriptFunction); + explicit ScriptFunction(varbinder::FunctionScope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, AstNode *body, TypeNode *return_type_annotation, ir::ScriptFunctionFlags func_flags, bool declare, Language lang) @@ -61,164 +68,167 @@ public: { } - const Identifier *Id() const + [[nodiscard]] const Identifier *Id() const noexcept { return id_; } - Identifier *Id() + [[nodiscard]] Identifier *Id() noexcept { return id_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - ArenaVector &Params() + [[nodiscard]] ArenaVector &Params() noexcept { return params_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } - const AstNode *Body() const + [[nodiscard]] const AstNode *Body() const noexcept { return body_; } - AstNode *Body() + [[nodiscard]] AstNode *Body() noexcept { return body_; } - void SetBody(AstNode *body) + void SetBody(AstNode *body) noexcept { body_ = body; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TypeNode *ReturnTypeAnnotation() + [[nodiscard]] TypeNode *ReturnTypeAnnotation() noexcept { return return_type_annotation_; } - void SetReturnTypeAnnotation(TypeNode *node) + void SetReturnTypeAnnotation(TypeNode *node) noexcept { return_type_annotation_ = node; } - bool IsEntryPoint() const + [[nodiscard]] bool IsEntryPoint() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENTRY_POINT) != 0; } - bool IsGenerator() const + [[nodiscard]] bool IsGenerator() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GENERATOR) != 0; } - bool IsAsyncFunc() const + [[nodiscard]] bool IsAsyncFunc() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ASYNC) != 0; } - bool IsArrow() const + [[nodiscard]] bool IsArrow() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ARROW) != 0; } - bool IsOverload() const + [[nodiscard]] bool IsOverload() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::OVERLOAD) != 0; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::CONSTRUCTOR) != 0; } - bool IsGetter() const + [[nodiscard]] bool IsGetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GETTER) != 0; } - bool IsSetter() const + [[nodiscard]] bool IsSetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::SETTER) != 0; } - bool IsMethod() const + [[nodiscard]] bool IsMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::METHOD) != 0; } - bool IsProxy() const + [[nodiscard]] bool IsProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::PROXY) != 0; } - bool IsStaticBlock() const + [[nodiscard]] bool IsStaticBlock() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::STATIC_BLOCK) != 0; } - bool IsEnum() const + [[nodiscard]] bool IsEnum() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENUM) != 0; } - bool IsHidden() const + [[nodiscard]] bool IsHidden() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::HIDDEN) != 0; } - bool IsExternal() const + [[nodiscard]] bool IsExternal() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::EXTERNAL) != 0; } - bool IsImplicitSuperCallNeeded() const + [[nodiscard]] bool IsImplicitSuperCallNeeded() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED) != 0; } - bool HasBody() const; + [[nodiscard]] bool HasBody() const noexcept + { + return body_ != nullptr; + } - bool IsThrowing() const + [[nodiscard]] bool IsThrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::THROWS) != 0; } - bool IsRethrowing() const + [[nodiscard]] bool IsRethrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - bool IsDefaultParamProxy() const noexcept + [[nodiscard]] bool IsDefaultParamProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0; } @@ -228,44 +238,47 @@ public: AddFlag(ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY); } - bool IsDynamic() const + [[nodiscard]] bool IsDynamic() const noexcept { return lang_.IsDynamic(); } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD) != 0; } - bool Declare() const + [[nodiscard]] bool Declare() const noexcept { return declare_; } - ir::ScriptFunctionFlags Flags() const; + [[nodiscard]] ir::ScriptFunctionFlags Flags() const noexcept + { + return func_flags_; + } - void SetIdent(Identifier *id) + void SetIdent(Identifier *id) noexcept { id_ = id; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *signature) noexcept { signature_ = signature; } - void AddFlag(ir::ScriptFunctionFlags flags) + void AddFlag(ir::ScriptFunctionFlags flags) noexcept { func_flags_ |= flags; } - void AddModifier(ir::ModifierFlags flags) + void AddModifier(ir::ModifierFlags flags) noexcept { flags_ |= flags; } - size_t FormalParamsLength() const; + [[nodiscard]] std::size_t FormalParamsLength() const noexcept; bool IsScopeBearer() const override { @@ -277,19 +290,19 @@ public: return scope_; } - void TransformChildren(const NodeTransformer &cb) override; - - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const { return lang_; } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::FunctionScope *scope_; diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index 1f995a1f1160a8f03d86f2b8c0199817629b6394..e7ff3e06229faacd354b5dd91279d5cbc2e63c54 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -31,16 +31,16 @@ SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const optional_ = other.optional_; if (other.argument_ != nullptr) { - argument_ = other.argument_->Clone(allocator, this); + argument_ = other.argument_->Clone(allocator, this)->AsExpression(); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 037cc59ca40d90174d64c54e4380f659c96ae2b5..11ef4991fb60be00ec832be185f5c5a30244eedd 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -69,7 +69,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool is_declaration, bool allow_pattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8a0e7d317ee2ca4c6cdd02508ea2490ef5eb7ca5..f77f0237072aa10032568825d48f6b597cb03ab9 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -15,10 +15,9 @@ #include "templateElement.h" -#include "es2panda.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "util/ustring.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,26 +31,28 @@ void TemplateElement::Dump(ir::AstDumper *dumper) const }); } -void TemplateElement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TemplateElement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} -void TemplateElement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void TemplateElement::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorString(this, raw_); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *TemplateElement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TemplateElement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TemplateElement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TemplateElement::Check(checker::ETSChecker *checker) { - SetTsType(checker->CreateETSStringLiteralType(raw_)); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index b373d7aff8cc660a598824361c10e65c2e93ef3c..0f9e6b7a90c3ebd0a1560e003eb8cb968cb8e79d 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -45,15 +45,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView raw_ {}; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index 09598d5b2488039e1ebf0c31c6900265cb77e31a..2bea99f714334c9e2337bd36192b2f155d89129c 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -15,14 +15,12 @@ #include "tsIndexSignature.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/expressions/identifier.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const +TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const noexcept { return param_->AsIdentifier()->TypeAnnotation()->IsTSNumberKeyword() ? TSIndexSignatureKind::NUMBER : TSIndexSignatureKind::STRING; @@ -48,34 +46,43 @@ void TSIndexSignature::Dump(ir::AstDumper *dumper) const {"readonly", readonly_}}); } -void TSIndexSignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSIndexSignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSIndexSignature::Compile(compiler::PandaGen *pg) const { - if (TsType() != nullptr) { - return TsType(); - } + pg->GetAstCompiler()->Compile(this); +} - const util::StringView ¶m_name = param_->AsIdentifier()->Name(); - type_annotation_->Check(checker); - checker::Type *index_type = type_annotation_->GetType(checker); - checker::IndexInfo *info = - checker->Allocator()->New(index_type, param_name, readonly_, this->Start()); - checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); - checker::ObjectType *placeholder = checker->Allocator()->New(desc); +void TSIndexSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - if (Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { - placeholder->Desc()->number_index_info = info; - } else { - placeholder->Desc()->string_index_info = info; - } +checker::Type *TSIndexSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - SetTsType(placeholder); - return placeholder; +checker::Type *TSIndexSignature::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSIndexSignature::Check([[maybe_unused]] checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - return nullptr; + auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = type_annotation_->Clone(allocator); + + if (auto *const clone = allocator->New(param, type_annotation, readonly_); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (param != nullptr) { + param->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index db29746c9150d9f768b760e68477280096771d64..f7ed2de9f43d054ca3143c72b50d2e2309676410 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -16,44 +16,61 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" + +namespace panda::es2panda::checker { +class TSAnalyzer; +} // namespace panda::es2panda::checker namespace panda::es2panda::ir { class TSIndexSignature : public TypedAstNode { public: enum class TSIndexSignatureKind { NUMBER, STRING }; - explicit TSIndexSignature(Expression *param, TypeNode *type_annotation, bool readonly) + TSIndexSignature() = delete; + ~TSIndexSignature() override = default; + + NO_COPY_SEMANTIC(TSIndexSignature); + NO_MOVE_SEMANTIC(TSIndexSignature); + + explicit TSIndexSignature(Expression *const param, TypeNode *const type_annotation, bool const readonly) : TypedAstNode(AstNodeType::TS_INDEX_SIGNATURE), param_(param), type_annotation_(type_annotation), readonly_(readonly) { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; - const Expression *Param() const + [[nodiscard]] const Expression *Param() const noexcept { return param_; } - const TypeNode *TypeAnnotation() const + [[nodiscard]] const TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } - TSIndexSignatureKind Kind() const; + [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *param_; diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index c6f203b24b91e353de82a43c3fc37a2cd96349f9..f94bde70c69bc998bdab28280a94daaea126b1ea 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -16,12 +16,9 @@ #include "tsMethodSignature.h" #include "varbinder/scope.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSMethodSignature::TransformChildren(const NodeTransformer &cb) @@ -69,35 +66,23 @@ void TSMethodSignature::Dump(ir::AstDumper *dumper) const {"typeAnnotation", AstDumper::Optional(return_type_annotation_)}}); } -void TSMethodSignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSMethodSignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSMethodSignature::Compile(compiler::PandaGen *pg) const { - if (computed_) { - checker->CheckComputedPropertyName(key_); - } - - checker::ScopeContext scope_ctx(checker, scope_); - - auto *signature_info = checker->Allocator()->New(checker->Allocator()); - checker->CheckFunctionParameterDeclarations(params_, signature_info); - - auto *call_signature = checker->Allocator()->New(signature_info, checker->GlobalAnyType()); - Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(call_signature)); - - if (return_type_annotation_ == nullptr) { - checker->ThrowTypeError( - "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", Start()); - } + pg->GetAstCompiler()->Compile(this); +} - return_type_annotation_->Check(checker); - call_signature->SetReturnType(return_type_annotation_->GetType(checker)); +void TSMethodSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - return nullptr; +checker::Type *TSMethodSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSMethodSignature::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSMethodSignature::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsMethodSignature.h b/ets2panda/ir/base/tsMethodSignature.h index ffa4dca38709fca21aa9ff37fc4382ca0e2e69cd..b0e66768a73660e930496d15a5cc6aec97a21fb4 100644 --- a/ets2panda/ir/base/tsMethodSignature.h +++ b/ets2panda/ir/base/tsMethodSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -16,13 +16,24 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" + +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker namespace panda::es2panda::ir { class TSTypeParameterDeclaration; class TSMethodSignature : public AstNode { public: + TSMethodSignature() = delete; + ~TSMethodSignature() override = default; + + NO_COPY_SEMANTIC(TSMethodSignature); + NO_MOVE_SEMANTIC(TSMethodSignature); + explicit TSMethodSignature(varbinder::Scope *scope, Expression *key, TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, TypeNode *return_type_annotation, bool computed, bool optional) @@ -37,6 +48,9 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + bool IsScopeBearer() const override { return true; @@ -47,47 +61,49 @@ public: return scope_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::Scope *scope_; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 3cfddf1f7fa1cb06cf888cd07f5a517fa545388e..ee863b4b7c55c56b1d8f9cbd01cfef6206233a21 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -15,10 +15,9 @@ #include "tsPropertySignature.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSPropertySignature::TransformChildren(const NodeTransformer &cb) @@ -49,29 +48,44 @@ void TSPropertySignature::Dump(ir::AstDumper *dumper) const {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); } -void TSPropertySignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSPropertySignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSPropertySignature::Compile(compiler::PandaGen *pg) const { - if (TypeAnnotation() != nullptr) { - TypeAnnotation()->Check(checker); - } + pg->GetAstCompiler()->Compile(this); +} - if (computed_) { - checker->CheckComputedPropertyName(key_); - } +void TSPropertySignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - if (TypeAnnotation() != nullptr) { - Variable()->SetTsType(TypeAnnotation()->GetType(checker)); - return nullptr; - } +checker::Type *TSPropertySignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - checker->ThrowTypeError("Property implicitly has an 'any' type.", Start()); - return nullptr; +checker::Type *TSPropertySignature::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSPropertySignature::Check([[maybe_unused]] checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - return nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = TypeAnnotation()->Clone(allocator); + + if (auto *const clone = allocator->New(key, type_annotation, computed_, optional_, readonly_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (key != nullptr) { + key->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index b39ebfdd0dc38b3e327f4905f11ab52012768d2f..929e74dc15b315b945c6dcbb5373bbdd946905e6 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -23,6 +23,12 @@ class TypeNode; class TSPropertySignature : public AnnotatedAstNode { public: + TSPropertySignature() = delete; + ~TSPropertySignature() override = default; + + NO_COPY_SEMANTIC(TSPropertySignature); + NO_MOVE_SEMANTIC(TSPropertySignature); + explicit TSPropertySignature(Expression *key, TypeNode *type_annotation, bool computed, bool optional, bool readonly) : AnnotatedAstNode(AstNodeType::TS_PROPERTY_SIGNATURE, type_annotation), @@ -33,37 +39,42 @@ public: { } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *key_; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index 734c4613f9cdd7b80be713cadb2c229dd837689d..a36cf714a6a1d619871eb8b804e8240d92575d13 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 diff --git a/ets2panda/ir/base/tsSignatureDeclaration.h b/ets2panda/ir/base/tsSignatureDeclaration.h index bd89af7fa3b833cc3542d3b60d05ae871697f8e6..20028f3aa848702267ad4baf9d862a158343e16d 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.h +++ b/ets2panda/ir/base/tsSignatureDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -16,7 +16,7 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H -#include "ir/statement.h" +#include "ir/astNode.h" namespace panda::es2panda::ir { class TSTypeParameterDeclaration; @@ -25,9 +25,15 @@ class TSSignatureDeclaration : public TypedAstNode { public: enum class TSSignatureDeclarationKind { CALL_SIGNATURE, CONSTRUCT_SIGNATURE }; - explicit TSSignatureDeclaration(varbinder::Scope *scope, TSSignatureDeclarationKind kind, - TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, - TypeNode *return_type_annotation) + TSSignatureDeclaration() = delete; + ~TSSignatureDeclaration() override = default; + + NO_COPY_SEMANTIC(TSSignatureDeclaration); + NO_MOVE_SEMANTIC(TSSignatureDeclaration); + + explicit TSSignatureDeclaration(varbinder::Scope *const scope, TSSignatureDeclarationKind const kind, + TSTypeParameterDeclaration *const type_params, ArenaVector &¶ms, + TypeNode *const return_type_annotation) : TypedAstNode(AstNodeType::TS_SIGNATURE_DECLARATION), scope_(scope), kind_(kind), @@ -47,29 +53,31 @@ public: return scope_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TSSignatureDeclarationKind Kind() const + [[nodiscard]] TSSignatureDeclarationKind Kind() const noexcept { return kind_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index 79c11f531ecd7fc26d5fb88e412abc91c73b012b..9d461309a1ecac09ea49b28c67e735499e41a92d 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -77,9 +77,9 @@ checker::Type *ETSClassLiteral::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsTypeNode() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 64dadfd65bbfb304b5a993444ee73cbba8bbe36f..44fbf9c8ba0179b0caf85783579f81727f302c11 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -31,7 +31,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index f5d880a47f87fba81be68b8bcdd7c9ea5d3983b0..280a1f05e2531d5bc58e42805d5a69a6ae531f7b 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -117,9 +117,9 @@ bool ETSLaunchExpression::IsStaticCall() const } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsCallExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index db99d9e6a58b6fd1a65e0be5066bdb06cb764bed..2863db9948045ae9f94f5adba6606e7e2333e716 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -33,7 +33,7 @@ public: explicit ETSLaunchExpression(CallExpression *expr); // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index bf3d63aafe6f8230f4e2f8cb39ebd7dc9b536ce3..b56d07341e770bf2117b4091904345c98e01cbfa 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -71,10 +71,11 @@ checker::Type *ETSNewArrayInstanceExpression::Check([[maybe_unused]] checker::ET } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { - auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator)->AsTypeNode() : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator) : nullptr; + auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(type_ref, dimension); clone != nullptr) { if (type_ref != nullptr) { diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index 553bb75120377bf84d5ead2276bf5323fbf855b6..9cafcc56e83cd9a827e29f86a5ff96b4be39be7a 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -36,7 +36,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 0e55a8ac981c704ab2e0c4719cf31b7094de37d2..e0a0ce1b2db3d3c27225f514e5e99143699d9d2f 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -184,4 +184,30 @@ checker::Type *ETSNewClassInstanceExpression::Check([[maybe_unused]] checker::ET return TsType(); } + +ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, + ArenaAllocator *const allocator) + : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this)->AsExpression(); + class_def_ = other.class_def_->Clone(allocator, this)->AsClassDefinition(); + + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index ffed6e65cdd9747a1bde4c1841d2ce62757f987f..25cd7607ff939b0d2b1de559525514646d09be1c 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -29,8 +29,15 @@ class ClassDefinition; class ETSNewClassInstanceExpression : public Expression { public: - explicit ETSNewClassInstanceExpression(ir::Expression *type_reference, ArenaVector &&arguments, - ir::ClassDefinition *class_definition) + ETSNewClassInstanceExpression() = delete; + ~ETSNewClassInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewClassInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewClassInstanceExpression); + + explicit ETSNewClassInstanceExpression(ir::Expression *const type_reference, + ArenaVector &&arguments, + ir::ClassDefinition *const class_definition) : Expression(AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION), type_reference_(type_reference), arguments_(std::move(arguments)), @@ -38,22 +45,24 @@ public: { } - ir::ClassDefinition *ClassDefinition() + explicit ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] ir::ClassDefinition *ClassDefinition() noexcept { return class_def_; } - const ir::ClassDefinition *ClassDefinition() const + [[nodiscard]] const ir::ClassDefinition *ClassDefinition() const noexcept { return class_def_; } - ir::Expression *GetTypeRef() const + [[nodiscard]] ir::Expression *GetTypeRef() const noexcept { return type_reference_; } - ArenaVector GetArguments() const + [[nodiscard]] ArenaVector GetArguments() const noexcept { return arguments_; } @@ -67,9 +76,14 @@ public: ir::Expression *name, checker::Signature *signature, const ArenaVector &arguments); + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + 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; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 3671c96b28d60c2b1e9c1f9b1465aea951eb4738..73a9fafa1f10cac753fe217a3b28092a44d9a4c7 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -71,4 +71,31 @@ checker::Type *ETSNewMultiDimArrayInstanceExpression::Check([[maybe_unused]] che signature_ = checker->CreateBuiltinArraySignature(element_type->AsETSArrayType(), dimensions_.size()); return TsType(); } + +ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( + ETSNewMultiDimArrayInstanceExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + dimensions_(allocator->Adapter()), + signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this); + + for (auto *const dimension : other.dimensions_) { + dimensions_.emplace_back(dimension->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 1cf38efa643435cccf347872aed8957b3912a35d..2ee2a3d4d4c5b1a458c446d808ff5694d67417a3 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -26,7 +26,13 @@ namespace panda::es2panda::ir { class ETSNewMultiDimArrayInstanceExpression : public Expression { public: - explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *type_reference, + ETSNewMultiDimArrayInstanceExpression() = delete; + ~ETSNewMultiDimArrayInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + + explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *const type_reference, ArenaVector &&dimensions) : Expression(AstNodeType::ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION), type_reference_(type_reference), @@ -34,19 +40,28 @@ public: { } - checker::Signature *Signature() + explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, + ArenaAllocator *allocator); + + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, + AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + 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; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index b31ed8e71ba451b99890227ca2d99567b4091c56..d78bc70007436b6924d85215c7adc11893d39c97 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -50,4 +50,21 @@ checker::Type *ETSPackageDeclaration::Check([[maybe_unused]] checker::ETSChecker { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; + if (auto *const clone = allocator->New(name); clone != nullptr) { + if (name != nullptr) { + name->SetParent(clone); + } + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 8ca20442d3d93240c979767e8aae6325cd873180..50249d8c681dcf6dad4c8d05bda130833c8b1a85 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -22,13 +22,25 @@ namespace panda::es2panda::ir { class ETSPackageDeclaration : public Statement { public: - explicit ETSPackageDeclaration(ir::Expression *name) : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) + ETSPackageDeclaration() = delete; + ~ETSPackageDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSPackageDeclaration); + NO_MOVE_SEMANTIC(ETSPackageDeclaration); + + explicit ETSPackageDeclaration(ir::Expression *const name) + : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) { } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + 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; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index bb0172b423fb8709b45b962774c37a9c49063fb6..3d00268107796fc5b6a597b7f68a6067443080a1 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -163,11 +163,11 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident_or_spread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator) : nullptr; + auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(ident_or_spread, initializer); clone != nullptr) { ident_or_spread->SetParent(clone); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index 4ea4ed1e32ad11db3db905048e24868de9c89732..7786d77fc3080a6e8cbb0e956982ba3ae1423283 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -65,7 +65,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 8bd7ed765a9957726b5a8c9f231372d41af095e9..14f7101ad09c6d056deac938079fd3ada3aa2508 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -68,4 +68,27 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def, allocator); clone != nullptr) { + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + if (def != nullptr) { + def->SetParent(clone); + } + + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index 90a448f581dfdf1ad83d074484be39a8ffb47acb..2368350de75f494537b0767da3b728a9acd2e84f 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -21,22 +21,28 @@ namespace panda::es2panda::ir { class ETSStructDeclaration : public Statement { public: - explicit ETSStructDeclaration(ClassDefinition *def, ArenaAllocator *allocator) + ETSStructDeclaration() = delete; + ~ETSStructDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSStructDeclaration); + NO_MOVE_SEMANTIC(ETSStructDeclaration); + + explicit ETSStructDeclaration(ClassDefinition *const def, ArenaAllocator *const allocator) : Statement(AstNodeType::STRUCT_DECLARATION), def_(def), decorators_(allocator->Adapter()) { } - ClassDefinition *Definition() + [[nodiscard]] ClassDefinition *Definition() noexcept { return def_; } - const ClassDefinition *Definition() const + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } @@ -46,14 +52,24 @@ public: decorators_ = std::move(decorators); } + void AddDecorator(Decorator *const decorator) + { + decorators_.emplace_back(decorator); + } + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override { return true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index ca7207a6f0227fe0102187d16dcc86d02a07d258..add1f500347c2dbfbe2ecd874f1a9de2ea0dfc1f 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -81,6 +81,7 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) if (prev_ == nullptr) { checker::Type *base_type = checker->GetReferencedTypeBase(name_); + ASSERT(base_type != nullptr); if (base_type->IsETSObjectType()) { checker::InstantiationContext ctx(checker, base_type->AsETSObjectType(), type_params_, Start()); return ctx.Result(); diff --git a/ets2panda/ir/expression.cpp b/ets2panda/ir/expression.cpp index 6d117c469e9c17a316e203beb5ab5dbcd4c70df4..6415d5e1726f58ee8e492c07629383dc60bf3c87 100644 --- a/ets2panda/ir/expression.cpp +++ b/ets2panda/ir/expression.cpp @@ -21,7 +21,7 @@ namespace panda::es2panda::ir { void AnnotatedExpression::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 833fa1589022a98d75abb71694b7a8f4066b86fe..5b5479c3d62b939468e87b32b872f5c3b26cc9bd 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -97,14 +97,6 @@ public: return reinterpret_cast(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Expression *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Expression(AstNodeType const type) : TypedAstNode(type) {} explicit Expression(AstNodeType const type, ModifierFlags const flags) : TypedAstNode(type, flags) {} diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index c3c36bef08d178a73a9bc23e6ce871535cb73f3e..6b46553a1db6a6056dc7b3861fd1441f719e0535 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -46,16 +46,16 @@ ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression optional_ = other.optional_; for (auto *element : other.elements_) { - elements_.emplace_back(element->Clone(allocator, this)); + elements_.emplace_back(element->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 5848b480b54f641968a51e5abaddad04fa2a09ed..bbe3c830fd3821c261f45761942007d95714d70e 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -99,7 +99,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 0cb1b3b65fda36d2382bd984c471d1ff3110e718..c07a110c37a3952c267fa4028396b2a7cf2ff257 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -61,4 +61,33 @@ checker::Type *ArrowFunctionExpression::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + captured_vars_(allocator->Adapter()), + propagate_this_(other.propagate_this_) +{ + func_ = other.func_->Clone(allocator, this)->AsScriptFunction(); + + for (auto *const variable : other.captured_vars_) { + captured_vars_.emplace_back(variable); + } + + if (other.resolved_lambda_ != nullptr) { + resolved_lambda_ = other.resolved_lambda_->Clone(allocator, this)->AsClassDefinition(); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2d78a104125f5e3f2f1d7ff3e10f53e32ae864f9..0cc830afadcb529bd436b6ec84c39eb381f6bd05 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -27,53 +27,65 @@ class ScriptFunction; class ArrowFunctionExpression : public Expression { public: - explicit ArrowFunctionExpression(ArenaAllocator *allocator, ScriptFunction *func) + ArrowFunctionExpression() = delete; + ~ArrowFunctionExpression() override = default; + + NO_COPY_SEMANTIC(ArrowFunctionExpression); + NO_MOVE_SEMANTIC(ArrowFunctionExpression); + + explicit ArrowFunctionExpression(ArenaAllocator *const allocator, ScriptFunction *const func) : Expression(AstNodeType::ARROW_FUNCTION_EXPRESSION), func_(func), captured_vars_(allocator->Adapter()) { } + + explicit ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *allocator); + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields friend class compiler::ETSCompiler; - const ScriptFunction *Function() const + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } - const ClassDefinition *ResolvedLambda() const + [[nodiscard]] const ClassDefinition *ResolvedLambda() const noexcept { return resolved_lambda_; } - ClassDefinition *ResolvedLambda() + [[nodiscard]] ClassDefinition *ResolvedLambda() noexcept { return resolved_lambda_; } - ArenaVector &CapturedVars() + [[nodiscard]] ArenaVector &CapturedVars() noexcept { return captured_vars_; } - const ArenaVector &CapturedVars() const + [[nodiscard]] const ArenaVector &CapturedVars() const noexcept { return captured_vars_; } - void SetResolvedLambda(ClassDefinition *lambda) + void SetResolvedLambda(ClassDefinition *const lambda) noexcept { resolved_lambda_ = lambda; } - void SetPropagateThis() + void SetPropagateThis() noexcept { propagate_this_ = true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index a6ba7d6ee0528ee4b948d9be668fe3a275f21027..4c3d14510fcfa13de7075c78b778596fc9d5fa17 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -322,10 +322,10 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } // NOLINTNEXTLINE(google-default-arguments) -Expression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 5f14a1c1cff1321beae8fb22326bc89d9c25353a..bebc40be2a0bd06dea49ac23f2057a4a317de1b1 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -108,7 +108,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool must_be_pattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 636a7e5bc25ab705db10bbefabee403e2d0fc139..f0fac3d9b4137445cdb5c17883b24b020d4cd30c 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -15,15 +15,10 @@ #include "awaitExpression.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/regScope.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" #include "ir/astDump.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/arrowFunctionExpression.h" namespace panda::es2panda::ir { void AwaitExpression::TransformChildren(const NodeTransformer &cb) @@ -47,56 +42,28 @@ void AwaitExpression::Dump(ir::AstDumper *dumper) const void AwaitExpression::Compile(compiler::PandaGen *pg) const { - compiler::RegScope rs(pg); - - if (argument_ != nullptr) { - argument_->Compile(pg); - } else { - pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); - } - - pg->EmitAwait(this); + pg->GetAstCompiler()->Compile(this); } void AwaitExpression::Compile(compiler::ETSGen *etsg) const { - static constexpr bool IS_UNCHECKED_CAST = false; - compiler::RegScope rs(etsg); - compiler::VReg argument_reg = etsg->AllocReg(); - argument_->Compile(etsg); - etsg->StoreAccumulator(this, argument_reg); - etsg->CallThisVirtual0(argument_, argument_reg, compiler::Signatures::BUILTIN_PROMISE_AWAIT_RESOLUTION); - etsg->CastToArrayOrObject(argument_, TsType(), IS_UNCHECKED_CAST); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *AwaitExpression::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *AwaitExpression::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - - checker::Type *arg_type = argument_->Check(checker); - // Check the argument type of await expression - if (!arg_type->IsETSObjectType() || - (arg_type->AsETSObjectType()->AssemblerName() != compiler::Signatures::BUILTIN_PROMISE)) { - checker->ThrowTypeError("'await' expressions require Promise object as argument.", argument_->Start()); - } - - SetTsType(arg_type->AsETSObjectType()->TypeArguments().at(0)); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index 17240df98c3efcdf6ca7e22e01545aa4a293e8f9..cc1f3f9415bb4a5dec79f5b00ea7fa1eae6f0dc4 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -18,6 +18,10 @@ #include "ir/expression.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class AwaitExpression : public Expression { public: @@ -29,13 +33,16 @@ public: explicit AwaitExpression(Expression *argument) : Expression(AstNodeType::AWAIT_EXPRESSION), argument_(argument) {} + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Argument() const noexcept { return argument_; } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -43,7 +50,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *argument_; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 440afa17f2d760db3d417e9bc88304214c0a7f85..4da4ae6df90367cfee6b8b20a34fbc287ffe06bf 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -15,14 +15,9 @@ #include "binaryExpression.h" -#include "varbinder/variable.h" -#include "compiler/core/function.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/expressions/identifier.h" namespace panda::es2panda::ir { void BinaryExpression::TransformChildren(const NodeTransformer &cb) @@ -45,261 +40,31 @@ void BinaryExpression::Dump(ir::AstDumper *dumper) const {"right", right_}}); } -void BinaryExpression::CompileLogical(compiler::PandaGen *pg) const -{ - compiler::RegScope rs(pg); - compiler::VReg lhs = pg->AllocReg(); - - ASSERT(operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || - operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR || - operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING); - - auto *skip_right = pg->AllocLabel(); - auto *end_label = pg->AllocLabel(); - - // left -> acc -> lhs -> toboolean -> acc -> bool_lhs - left_->Compile(pg); - pg->StoreAccumulator(this, lhs); - - if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { - pg->ToBoolean(this); - pg->BranchIfFalse(this, skip_right); - } else if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR) { - pg->ToBoolean(this); - pg->BranchIfTrue(this, skip_right); - } else if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - pg->BranchIfCoercible(this, skip_right); - } - - // left is true/false(and/or) then right -> acc - right_->Compile(pg); - pg->Branch(this, end_label); - - // left is false/true(and/or) then lhs -> acc - pg->SetLabel(this, skip_right); - pg->LoadAccumulator(this, lhs); - pg->SetLabel(this, end_label); -} - void BinaryExpression::Compile(compiler::PandaGen *pg) const { - if (IsLogical()) { - CompileLogical(pg); - return; - } - - if (operator_ == lexer::TokenType::KEYW_IN && left_->IsIdentifier() && left_->AsIdentifier()->IsPrivateIdent()) { - compiler::RegScope rs(pg); - compiler::VReg ctor = pg->AllocReg(); - const auto &name = left_->AsIdentifier()->Name(); - compiler::Function::LoadClassContexts(this, pg, ctor, name); - right_->Compile(pg); - pg->ClassPrivateFieldIn(this, ctor, name); - return; - } - - compiler::RegScope rs(pg); - compiler::VReg lhs = pg->AllocReg(); - - left_->Compile(pg); - pg->StoreAccumulator(this, lhs); - right_->Compile(pg); - - pg->Binary(this, operator_, lhs); + pg->GetAstCompiler()->Compile(this); } void BinaryExpression::Compile(compiler::ETSGen *etsg) const { - if (etsg->TryLoadConstantExpression(this)) { - return; - } - - auto ttctx = compiler::TargetTypeContext(etsg, operation_type_); - - if (IsLogical()) { - CompileLogical(etsg); - etsg->ApplyConversion(this, operation_type_); - return; - } - - compiler::RegScope rs(etsg); - compiler::VReg lhs = etsg->AllocReg(); - - if (operator_ == lexer::TokenType::PUNCTUATOR_PLUS && - (left_->TsType()->IsETSStringType() || right_->TsType()->IsETSStringType())) { - etsg->BuildString(this); - return; - } - - left_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operation_type_); - right_->Compile(etsg); - etsg->ApplyConversion(right_, operation_type_); - if (operator_ >= lexer::TokenType::PUNCTUATOR_LEFT_SHIFT && - operator_ <= lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT) { - etsg->ApplyCast(right_, operation_type_); - } - - etsg->Binary(this, operator_, lhs); -} - -static void CompileNullishCoalescing(BinaryExpression const *const node, compiler::ETSGen *etsg) -{ - auto const compile_operand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { - etsg->CompileAndCheck(expr); - etsg->ApplyConversion(expr, optype); - }; - - compile_operand(node->Left()); - - if (!node->Left()->TsType()->IsNullishOrNullLike()) { - // fallthrough - } else if (node->Left()->TsType()->IsETSNullLike()) { - compile_operand(node->Right()); - } else { - auto *if_left_nullish = etsg->AllocLabel(); - auto *end_label = etsg->AllocLabel(); - - etsg->BranchIfNullish(node, if_left_nullish); - - etsg->ConvertToNonNullish(node); - etsg->ApplyConversion(node->Left(), node->OperationType()); - etsg->JumpTo(node, end_label); - - etsg->SetLabel(node, if_left_nullish); - compile_operand(node->Right()); - - etsg->SetLabel(node, end_label); - } - etsg->SetAccumulatorType(node->TsType()); -} - -void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const -{ - if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - CompileNullishCoalescing(this, etsg); - return; - } - - ASSERT(IsLogicalExtended()); - auto ttctx = compiler::TargetTypeContext(etsg, OperationType()); - compiler::RegScope rs(etsg); - auto lhs = etsg->AllocReg(); - auto rhs = etsg->AllocReg(); - left_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(left_, lhs, OperationType()); - - auto *end_label = etsg->AllocLabel(); - - auto left_false_label = etsg->AllocLabel(); - if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { - etsg->ResolveConditionalResultIfFalse(left_, left_false_label); - etsg->BranchIfFalse(this, left_false_label); - - right_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(right_, rhs, OperationType()); - etsg->Branch(this, end_label); - - etsg->SetLabel(this, left_false_label); - etsg->LoadAccumulator(this, lhs); - } else { - etsg->ResolveConditionalResultIfFalse(left_, left_false_label); - etsg->BranchIfFalse(this, left_false_label); - - etsg->LoadAccumulator(this, lhs); - etsg->Branch(this, end_label); - - etsg->SetLabel(this, left_false_label); - right_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(right_, rhs, OperationType()); - } - - etsg->SetLabel(this, end_label); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *BinaryExpression::Check(checker::TSChecker *checker) { - auto *left_type = left_->Check(checker); - auto *right_type = right_->Check(checker); - - switch (operator_) { - case lexer::TokenType::PUNCTUATOR_MULTIPLY: - case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: - case lexer::TokenType::PUNCTUATOR_DIVIDE: - case lexer::TokenType::PUNCTUATOR_MOD: - case lexer::TokenType::PUNCTUATOR_MINUS: - case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: - case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: - case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: - case lexer::TokenType::PUNCTUATOR_BITWISE_AND: - case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: - case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { - return checker->CheckBinaryOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_PLUS: { - return checker->CheckPlusOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_LESS_THAN: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN: { - return checker->CheckCompareOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_EQUAL: - case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: - case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: - case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: { - if (checker->IsTypeEqualityComparableTo(left_type, right_type) || - checker->IsTypeEqualityComparableTo(right_type, left_type)) { - return checker->GlobalBooleanType(); - } - - checker->ThrowBinaryLikeError(operator_, left_type, right_type, Start()); - } - case lexer::TokenType::KEYW_INSTANCEOF: { - return checker->CheckInstanceofExpression(left_type, right_type, right_, this); - } - case lexer::TokenType::KEYW_IN: { - return checker->CheckInExpression(left_type, right_type, left_, right_, this); - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - return checker->CheckAndOperator(left_type, right_type, left_); - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - return checker->CheckOrOperator(left_type, right_type, left_); - } - case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { - // NOTE: Csaba Repasi. Implement checker for nullish coalescing - return checker->GlobalAnyType(); - } - case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { - checker->CheckAssignmentOperator(operator_, left_, left_type, right_type); - return right_type; - } - default: { - UNREACHABLE(); - break; - } - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - checker::Type *new_ts_type {nullptr}; - std::tie(new_ts_type, operation_type_) = checker->CheckBinaryOperator(left_, right_, this, operator_, Start()); - SetTsType(new_ts_type); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operation_type_ != nullptr) { diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c2a1a47bbbc2943a56b1b2822cfa2227ecd71963..98416dc89f6ebc5a57cda74ccdc29435ff180bf8 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -19,6 +19,10 @@ #include "ir/expression.h" #include "lexer/token/tokenType.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class BinaryExpression : public Expression { public: @@ -33,6 +37,9 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Left() const noexcept { return left_; @@ -113,17 +120,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; - void CompileLogical(compiler::PandaGen *pg) const; - void CompileLogical(compiler::ETSGen *etsg) const; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *left_ = nullptr; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp new file mode 100644 index 0000000000000000000000000000000000000000..02e3ff477e246e528a8228340ac990ac50948f50 --- /dev/null +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2023 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. + */ + +#include "blockExpression.h" + +#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "checker/ETSchecker.h" +#include "ir/astNode.h" + +namespace panda::es2panda::ir { + +BlockExpression::BlockExpression(ArenaVector &&statements) + : Expression(AstNodeType::BLOCK_EXPRESSION), statements_(std::move(statements)) +{ + for (auto *const node : statements_) { + node->SetParent(this); + } +} + +BlockExpression::BlockExpression([[maybe_unused]] Tag const tag, BlockExpression const &other, + ArenaAllocator *const allocator) + : Expression(static_cast(other)), statements_(allocator->Adapter()) +{ + for (auto *const node : other.statements_) { + statements_.emplace_back(node->Clone(allocator, this)->AsStatement()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + +void BlockExpression::TransformChildren(const NodeTransformer &cb) +{ + for (auto *&node : statements_) { + node = cb(node)->AsStatement(); + } +} + +void BlockExpression::Iterate(const NodeTraverser &cb) const +{ + for (auto *const node : statements_) { + cb(node); + } +} + +void BlockExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BlockExpression"}, {"statements", statements_}}); +} + +void BlockExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + UNREACHABLE(); +} + +void BlockExpression::Compile(compiler::ETSGen *etsg) const +{ + for (auto const *const node : statements_) { + node->Compile(etsg); + } +} + +checker::Type *BlockExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + UNREACHABLE(); +} + +checker::Type *BlockExpression::Check(checker::ETSChecker *checker) +{ + if (TsType() == nullptr) { + for (auto *const node : statements_) { + if (auto *const expr_type = node->Check(checker); expr_type != nullptr) { + SetTsType(expr_type); + } + } + } + return TsType(); +} +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h new file mode 100644 index 0000000000000000000000000000000000000000..ef4f0b8b58dc9d0876ca3bc6bcba49a137dec549 --- /dev/null +++ b/ets2panda/ir/expressions/blockExpression.h @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2023 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_IR_EXPRESSION_BLOCK_EXPRESSION_H +#define ES2PANDA_IR_EXPRESSION_BLOCK_EXPRESSION_H + +#include "ir/astNode.h" +#include "ir/expression.h" +#include "ir/statement.h" + +namespace panda::es2panda::ir { + +class BlockExpression : public Expression { +private: + struct Tag {}; + +public: + BlockExpression() = delete; + ~BlockExpression() override = default; + + NO_COPY_SEMANTIC(BlockExpression); + NO_MOVE_SEMANTIC(BlockExpression); + + explicit BlockExpression(ArenaVector &&statements); + explicit BlockExpression(Tag tag, BlockExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] ArenaVector const &Statements() const noexcept + { + return statements_; + } + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + +private: + ArenaVector statements_; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index b74f16794da9ce5f8877d48db9208e8a2afb4f3b..ede576373ea70522612a61638b02c15583b846f2 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -15,29 +15,9 @@ #include "callExpression.h" -#include "util/helpers.h" -#include "compiler/core/function.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/regScope.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsDynamicFunctionType.h" -#include "checker/types/ts/objectType.h" -#include "checker/types/signature.h" -#include "ir/astDump.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/chainExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/statements/blockStatement.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsEnumMember.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void CallExpression::TransformChildren(const NodeTransformer &cb) @@ -79,287 +59,19 @@ void CallExpression::Dump(ir::AstDumper *dumper) const {"typeParameters", AstDumper::Optional(type_params_)}}); } -compiler::VReg CallExpression::CreateSpreadArguments(compiler::PandaGen *pg) const -{ - compiler::VReg args_obj = pg->AllocReg(); - pg->CreateArray(this, arguments_, args_obj); - - return args_obj; -} - -void CallExpression::ConvertRestArguments(checker::ETSChecker *const checker) const -{ - if (signature_->RestVar() != nullptr) { - std::size_t const argument_count = arguments_.size(); - std::size_t const parameter_count = signature_->MinArgCount(); - ASSERT(argument_count >= parameter_count); - - auto &arguments = const_cast &>(arguments_); - std::size_t i = parameter_count; - - if (i < argument_count && arguments_[i]->IsSpreadElement()) { - arguments[i] = arguments_[i]->AsSpreadElement()->Argument(); - } else { - ArenaVector elements(checker->Allocator()->Adapter()); - for (; i < argument_count; ++i) { - elements.emplace_back(arguments_[i]); - } - auto *array_expression = checker->AllocNode(std::move(elements), checker->Allocator()); - array_expression->SetParent(const_cast(this)); - array_expression->SetTsType(signature_->RestVar()->TsType()); - arguments.erase(arguments_.begin() + parameter_count, arguments_.end()); - arguments.emplace_back(array_expression); - } - } -} - void CallExpression::Compile(compiler::PandaGen *pg) const { - compiler::RegScope rs(pg); - bool contains_spread = util::Helpers::ContainSpreadElement(arguments_); - - if (callee_->IsSuperExpression()) { - if (contains_spread) { - compiler::RegScope param_scope(pg); - compiler::VReg args_obj = CreateSpreadArguments(pg); - - pg->GetFunctionObject(this); - pg->SuperCallSpread(this, args_obj); - } else { - compiler::RegScope param_scope(pg); - compiler::VReg arg_start {}; - - if (arguments_.empty()) { - arg_start = pg->AllocReg(); - pg->StoreConst(this, arg_start, compiler::Constant::JS_UNDEFINED); - } else { - arg_start = pg->NextReg(); - } - - for (const auto *it : arguments_) { - compiler::VReg arg = pg->AllocReg(); - it->Compile(pg); - pg->StoreAccumulator(it, arg); - } - - pg->GetFunctionObject(this); - pg->SuperCall(this, arg_start, arguments_.size()); - } - - compiler::VReg new_this = pg->AllocReg(); - pg->StoreAccumulator(this, new_this); - - pg->GetThis(this); - pg->ThrowIfSuperNotCorrectCall(this, 1); - - pg->LoadAccumulator(this, new_this); - pg->SetThis(this); - - compiler::Function::CompileInstanceFields(pg, pg->RootNode()->AsScriptFunction()); - return; - } - - compiler::VReg callee = pg->AllocReg(); - compiler::VReg this_reg = compiler::VReg::Invalid(); - - if (callee_->IsMemberExpression()) { - this_reg = pg->AllocReg(); - - compiler::RegScope mrs(pg); - callee_->AsMemberExpression()->CompileToReg(pg, this_reg); - } else if (callee_->IsChainExpression()) { - this_reg = pg->AllocReg(); - - compiler::RegScope mrs(pg); - callee_->AsChainExpression()->CompileToReg(pg, this_reg); - } else { - callee_->Compile(pg); - } - - pg->StoreAccumulator(this, callee); - pg->OptionalChainCheck(IsOptional(), callee); - - if (contains_spread || arguments_.size() >= compiler::PandaGen::MAX_RANGE_CALL_ARG) { - if (this_reg.IsInvalid()) { - this_reg = pg->AllocReg(); - pg->StoreConst(this, this_reg, compiler::Constant::JS_UNDEFINED); - } - - compiler::VReg args_obj = CreateSpreadArguments(pg); - pg->CallSpread(this, callee, this_reg, args_obj); - } else { - pg->Call(this, callee, this_reg, arguments_); - } + pg->GetAstCompiler()->Compile(this); } void CallExpression::Compile(compiler::ETSGen *etsg) const { - compiler::RegScope rs(etsg); - compiler::VReg callee_reg = etsg->AllocReg(); - - const auto is_proxy = signature_->HasSignatureFlag(checker::SignatureFlags::PROXY); - - if (is_proxy && callee_->IsMemberExpression()) { - auto *const callee_object = callee_->AsMemberExpression()->Object(); - - auto const *const enum_interface = [callee_type = - callee_object->TsType()]() -> checker::ETSEnumInterface const * { - if (callee_type->IsETSEnumType()) { - return callee_type->AsETSEnumType(); - } - if (callee_type->IsETSStringEnumType()) { - return callee_type->AsETSStringEnumType(); - } - return nullptr; - }(); - - if (enum_interface != nullptr) { - ArenaVector arguments(etsg->Allocator()->Adapter()); - - checker::Signature *const signature = [this, callee_object, enum_interface, &arguments]() { - const auto &member_proxy_method_name = signature_->InternalName(); - - if (member_proxy_method_name == checker::ETSEnumType::TO_STRING_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->ToStringMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::GET_VALUE_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->GetValueMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::GET_NAME_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->GetNameMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::VALUES_METHOD_NAME) { - return enum_interface->ValuesMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::VALUE_OF_METHOD_NAME) { - arguments.push_back(arguments_.front()); - return enum_interface->ValueOfMethod().global_signature; - } - UNREACHABLE(); - }(); - - ASSERT(signature->ReturnType() == signature_->ReturnType()); - etsg->CallStatic(this, signature, arguments); - etsg->SetAccumulatorType(TsType()); - return; - } - } - - bool is_static = signature_->HasSignatureFlag(checker::SignatureFlags::STATIC); - bool is_reference = signature_->HasSignatureFlag(checker::SignatureFlags::TYPE); - bool is_dynamic = callee_->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); - - ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker())); - - compiler::VReg dyn_param2; - - // Helper function to avoid branching in non optional cases - auto emit_call = [this, etsg, is_static, is_dynamic, &callee_reg, &dyn_param2]() { - if (is_dynamic) { - etsg->CallDynamic(this, callee_reg, dyn_param2, signature_, arguments_); - } else if (is_static) { - etsg->CallStatic(this, signature_, arguments_); - } else if (signature_->HasSignatureFlag(checker::SignatureFlags::PRIVATE) || IsETSConstructorCall() || - (callee_->IsMemberExpression() && callee_->AsMemberExpression()->Object()->IsSuperExpression())) { - etsg->CallThisStatic(this, callee_reg, signature_, arguments_); - } else { - etsg->CallThisVirtual(this, callee_reg, signature_, arguments_); - } - etsg->SetAccumulatorType(TsType()); - }; - - if (is_dynamic) { - dyn_param2 = etsg->AllocReg(); - - ir::Expression *obj = callee_; - std::vector parts; - - while (obj->IsMemberExpression() && obj->AsMemberExpression()->ObjType()->IsETSDynamicType()) { - auto *mem_expr = obj->AsMemberExpression(); - obj = mem_expr->Object(); - parts.push_back(mem_expr->Property()->AsIdentifier()->Name()); - } - - if (!obj->IsMemberExpression() && obj->IsIdentifier()) { - auto *var = obj->AsIdentifier()->Variable(); - auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); - if (data != nullptr) { - auto *import = data->import; - auto *specifier = data->specifier; - ASSERT(import->Language().IsDynamic()); - etsg->LoadAccumulatorDynamicModule(this, import); - if (specifier->IsImportSpecifier()) { - parts.push_back(specifier->AsImportSpecifier()->Imported()->Name()); - } - } else { - obj->Compile(etsg); - } - } else { - obj->Compile(etsg); - } - - etsg->StoreAccumulator(this, callee_reg); - - if (!parts.empty()) { - std::stringstream ss; - for_each(parts.rbegin(), parts.rend(), [&ss](util::StringView sv) { ss << "." << sv; }); - - etsg->LoadAccumulatorString(this, util::UString(ss.str(), etsg->Allocator()).View()); - } else { - auto lang = callee_->TsType()->IsETSDynamicFunctionType() - ? callee_->TsType()->AsETSDynamicFunctionType()->Language() - : callee_->TsType()->AsETSDynamicType()->Language(); - - etsg->LoadUndefinedDynamic(this, lang); - } - - etsg->StoreAccumulator(this, dyn_param2); - - emit_call(); - - if (signature_->ReturnType() != TsType()) { - etsg->ApplyConversion(this, TsType()); - } - } else if (!is_reference && callee_->IsIdentifier()) { - if (!is_static) { - etsg->LoadThis(this); - etsg->StoreAccumulator(this, callee_reg); - } - emit_call(); - } else if (!is_reference && callee_->IsMemberExpression()) { - if (!is_static) { - callee_->AsMemberExpression()->Object()->Compile(etsg); - etsg->StoreAccumulator(this, callee_reg); - } - emit_call(); - } else if (callee_->IsSuperExpression() || callee_->IsThisExpression()) { - ASSERT(!is_reference && IsETSConstructorCall()); - callee_->Compile(etsg); // ctor is not a value! - etsg->SetVRegType(callee_reg, etsg->GetAccumulatorType()); - emit_call(); - } else { - ASSERT(is_reference); - etsg->CompileAndCheck(callee_); - etsg->StoreAccumulator(this, callee_reg); - etsg->EmitMaybeOptional(this, emit_call, IsOptional()); - } + etsg->GetAstCompiler()->Compile(this); } checker::Type *CallExpression::Check(checker::TSChecker *checker) { - checker::Type *callee_type = callee_->Check(checker); - - // NOTE: aszilagyi. handle optional chain - if (callee_type->IsObjectType()) { - checker::ObjectType *callee_obj = callee_type->AsObjectType(); - return checker->ResolveCallOrNewExpression(callee_obj->CallSignatures(), arguments_, Start()); - } - - checker->ThrowTypeError("This expression is not callable.", Start()); - return nullptr; + return checker->GetAnalyzer()->Check(this); } bool CallExpression::IsETSConstructorCall() const @@ -367,170 +79,40 @@ bool CallExpression::IsETSConstructorCall() const return callee_->IsThisExpression() || callee_->IsSuperExpression(); } -checker::Signature *CallExpression::ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, - checker::ETSChecker *checker) +checker::Type *CallExpression::Check(checker::ETSChecker *checker) { - auto *member_expr = callee_->AsMemberExpression(); - arguments_.insert(arguments_.begin(), member_expr->Object()); - auto *signature = checker->ResolveCallExpressionAndTrailingLambda(function_type->CallSignatures(), this, Start()); - if (!signature->Function()->IsExtensionMethod()) { - checker->ThrowTypeError({"Property '", member_expr->Property()->AsIdentifier()->Name(), - "' does not exist on type '", member_expr->ObjType()->Name(), "'"}, - member_expr->Property()->Start()); - } - this->SetSignature(signature); - this->SetCallee(member_expr->Property()); - member_expr->Property()->AsIdentifier()->SetParent(this); - this->Arguments()[0]->SetParent(this); - checker->HandleUpdatedCallExpressionNode(this); - // Set TsType for new Callee(original member expression's Object) - this->Callee()->Check(checker); - return signature; + return checker->GetAnalyzer()->Check(this); } -checker::Signature *CallExpression::ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, - checker::ETSChecker *checker) +CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *const allocator) + : MaybeOptionalExpression(static_cast(other)), + arguments_(allocator->Adapter()), + signature_(other.signature_), + trailing_comma_(other.trailing_comma_), + is_trailing_block_in_new_line_(other.is_trailing_block_in_new_line_) { - checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda( - type->ClassMethodType()->CallSignatures(), this, Start(), checker::TypeRelationFlag::NO_THROW); + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); + type_params_ = other.type_params_->Clone(allocator, this); - if (signature != nullptr) { - return signature; + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } - return ResolveCallExtensionFunction(type->ExtensionMethodType(), checker); + if (other.trailing_block_ != nullptr) { + trailing_block_ = other.trailing_block_->Clone(allocator, this)->AsBlockStatement(); + } } -checker::Type *CallExpression::Check(checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - if (TsType() != nullptr) { - return TsType(); - } - auto *old_callee = callee_; - checker::Type *callee_type = callee_->Check(checker); - if (callee_ != old_callee) { - // If it is a static invoke, the callee will be transformed from an identifier to a member expression - // Type check the callee again for member expression - callee_type = callee_->Check(checker); - } - if (!IsOptional()) { - checker->CheckNonNullishType(callee_type, callee_->Start()); - } - checker::Type *return_type; - if (callee_type->IsETSDynamicType() && !callee_type->AsETSDynamicType()->HasDecl()) { - // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` - checker->EnsureValidCurlyBrace(this); - auto lang = callee_type->AsETSDynamicType()->Language(); - signature_ = checker->ResolveDynamicCallExpression(callee_, arguments_, lang, false); - return_type = signature_->ReturnType(); - } else { - bool constructor_call = IsETSConstructorCall(); - bool functional_interface = - callee_type->IsETSObjectType() && - callee_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::FUNCTIONAL_INTERFACE); - bool ets_extension_func_helper_type = callee_type->IsETSExtensionFuncHelperType(); - bool extension_function_type = callee_->IsMemberExpression() && checker->ExtensionETSFunctionType(callee_type); - - if (callee_->IsArrowFunctionExpression()) { - callee_type = InitAnonymousLambdaCallee(checker, callee_, callee_type); - functional_interface = true; - } - - if (!functional_interface && !callee_type->IsETSFunctionType() && !constructor_call && - !ets_extension_func_helper_type) { - checker->ThrowTypeError("This expression is not callable.", Start()); - } - - checker::Signature *signature = nullptr; - - if (ets_extension_func_helper_type) { - signature = ResolveCallForETSExtensionFuncHelperType(callee_type->AsETSExtensionFuncHelperType(), checker); - } else { - if (extension_function_type) { - signature = ResolveCallExtensionFunction(callee_type->AsETSFunctionType(), checker); - } else { - auto &signatures = constructor_call ? callee_type->AsETSObjectType()->ConstructSignatures() - : functional_interface - ? callee_type->AsETSObjectType() - ->GetOwnProperty("invoke") - ->TsType() - ->AsETSFunctionType() - ->CallSignatures() - : callee_type->AsETSFunctionType()->CallSignatures(); - signature = checker->ResolveCallExpressionAndTrailingLambda(signatures, this, Start()); - if (signature->Function()->IsExtensionMethod()) { - checker->ThrowTypeError({"No matching call signature"}, Start()); - } - } + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); } - - checker->CheckObjectLiteralArguments(signature, arguments_); - - checker->AddUndefinedParamsForDefaultParams(signature, arguments_, checker); - - if (!functional_interface) { - checker::ETSObjectType *callee_obj {}; - if (constructor_call) { - callee_obj = callee_type->AsETSObjectType(); - } else if (callee_->IsIdentifier()) { - callee_obj = checker->Context().ContainingClass(); - } else { - ASSERT(callee_->IsMemberExpression()); - callee_obj = callee_->AsMemberExpression()->ObjType(); - } - - checker->ValidateSignatureAccessibility(callee_obj, signature, Start()); - } - - ASSERT(signature->Function() != nullptr); - - if (signature->Function()->IsThrowing() || signature->Function()->IsRethrowing()) { - checker->CheckThrowingStatements(this); - } - - if (signature->Function()->IsDynamic()) { - ASSERT(signature->Function()->IsDynamic()); - auto lang = signature->Function()->Language(); - signature_ = checker->ResolveDynamicCallExpression(callee_, signature->Params(), lang, false); - } else { - ASSERT(!signature->Function()->IsDynamic()); - signature_ = signature; - } - - return_type = signature->ReturnType(); - } - - if (signature_->RestVar() != nullptr) { - auto *const element_type = signature_->RestVar()->TsType()->AsETSArrayType()->ElementType(); - auto *const array_type = checker->CreateETSArrayType(element_type)->AsETSArrayType(); - checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); - } - - if (signature_->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { - signature_->OwnerVar()->Declaration()->Node()->Check(checker); - return_type = signature_->ReturnType(); + return clone; } - SetOptionalType(return_type); - if (IsOptional() && callee_type->IsNullishOrNullLike()) { - checker->Relation()->SetNode(this); - return_type = checker->CreateOptionalResultType(return_type); - checker->Relation()->SetNode(nullptr); - } - SetTsType(return_type); - return TsType(); -} -checker::Type *CallExpression::InitAnonymousLambdaCallee(checker::ETSChecker *checker, Expression *callee, - checker::Type *callee_type) -{ - auto *const arrow_func = callee->AsArrowFunctionExpression()->Function(); - auto orig_params = arrow_func->Params(); - auto *func_type = checker->Allocator()->New( - arrow_func->Scope()->AsFunctionScope()->ParamScope(), std::move(orig_params), nullptr, - arrow_func->ReturnTypeAnnotation(), ir::ScriptFunctionFlags::NONE); - auto *const func_iface = func_type->Check(checker); - checker->Relation()->SetNode(callee); - checker->Relation()->IsAssignableTo(callee_type, func_iface); - return func_iface; + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index d68ca9daca725252c798de103c0eac2180193eca..1bdf683c065408420b8eaf3c186f94a9327eca2d 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -21,16 +21,30 @@ #include "ir/expression.h" namespace panda::es2panda::checker { +class ETSAnalyzer; +class TSAnalyzer; class Signature; } // namespace panda::es2panda::checker +namespace panda::es2panda::compiler { +class JSCompiler; +class ETSCompiler; +} // namespace panda::es2panda::compiler + namespace panda::es2panda::ir { class TSTypeParameterInstantiation; class CallExpression : public MaybeOptionalExpression { public: - explicit CallExpression(Expression *callee, ArenaVector &&arguments, - TSTypeParameterInstantiation *type_params, bool optional, bool trailing_comma = false) + CallExpression() = delete; + ~CallExpression() override = default; + + NO_COPY_SEMANTIC(CallExpression); + NO_MOVE_SEMANTIC(CallExpression); + + explicit CallExpression(Expression *const callee, ArenaVector &&arguments, + TSTypeParameterInstantiation *const type_params, bool const optional, + bool const trailing_comma = false) : MaybeOptionalExpression(AstNodeType::CALL_EXPRESSION, optional), callee_(callee), arguments_(std::move(arguments)), @@ -39,101 +53,107 @@ public: { } + explicit CallExpression(CallExpression const &other, ArenaAllocator *allocator); + + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + friend class checker::ETSAnalyzer; + friend class compiler::JSCompiler; + friend class compiler::ETSCompiler; + const Expression *Callee() const { return callee_; } - Expression *Callee() + [[nodiscard]] Expression *Callee() noexcept { return callee_; } - void SetCallee(Expression *callee) + void SetCallee(Expression *callee) noexcept { callee_ = callee; } - const TSTypeParameterInstantiation *TypeParams() const + [[nodiscard]] const TSTypeParameterInstantiation *TypeParams() const noexcept { return type_params_; } - TSTypeParameterInstantiation *TypeParams() + [[nodiscard]] TSTypeParameterInstantiation *TypeParams() noexcept { return type_params_; } - const ArenaVector &Arguments() const + [[nodiscard]] const ArenaVector &Arguments() const noexcept { return arguments_; } - ArenaVector &Arguments() + [[nodiscard]] ArenaVector &Arguments() noexcept { return arguments_; } - bool HasTrailingComma() const + [[nodiscard]] bool HasTrailingComma() const noexcept { return trailing_comma_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - checker::Signature *Signature() const + [[nodiscard]] checker::Signature *Signature() const noexcept { return signature_; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *const signature) noexcept { signature_ = signature; } - void SetTypeParams(TSTypeParameterInstantiation *type_params) + void SetTypeParams(TSTypeParameterInstantiation *const type_params) noexcept { type_params_ = type_params; } - void SetTrailingBlock(ir::BlockStatement *block) + void SetTrailingBlock(ir::BlockStatement *const block) noexcept { trailing_block_ = block; } - ir::BlockStatement *TrailingBlock() const + [[nodiscard]] ir::BlockStatement *TrailingBlock() const noexcept { return trailing_block_; } - void SetIsTrailingBlockInNewLine(bool is_new_line) + void SetIsTrailingBlockInNewLine(bool const is_new_line) noexcept { is_trailing_block_in_new_line_ = is_new_line; } - bool IsTrailingBlockInNewLine() const + [[nodiscard]] bool IsTrailingBlockInNewLine() const noexcept { return is_trailing_block_in_new_line_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; - checker::Signature *ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, - checker::ETSChecker *checker); - checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, - checker::ETSChecker *checker); + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; protected: - compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg) const; - // NOLINTBEGIN(misc-non-private-member-variables-in-classes) Expression *callee_; ArenaVector arguments_; @@ -149,7 +169,6 @@ private: bool IsETSConstructorCall() const; checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, Expression *callee, checker::Type *callee_type); - void ConvertRestArguments(checker::ETSChecker *checker) const; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index ce71eac838816b664bcb6cbfc04018e05cfb1b23..c7bddde72b0cdfb24d548f66af60e3e756b21a62 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -15,12 +15,11 @@ #include "chainExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/memberExpression.h" -#include "compiler/base/optionalChain.h" -#include "compiler/core/regScope.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" +#include "ir/expressions/memberExpression.h" namespace panda::es2panda::ir { void ChainExpression::TransformChildren(const NodeTransformer &cb) @@ -38,10 +37,9 @@ void ChainExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ChainExpression"}, {"expression", expression_}}); } -void ChainExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ChainExpression::Compile(compiler::PandaGen *pg) const { - compiler::OptionalChain chain(pg, this); - expression_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_reg) const @@ -57,20 +55,25 @@ void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_r } } -checker::Type *ChainExpression::Check([[maybe_unused]] checker::TSChecker *checker) +void ChainExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +checker::Type *ChainExpression::Check(checker::TSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } -checker::Type *ChainExpression::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ChainExpression::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator) : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 252ece9500b899c32839e359942a82ab5d196360..6aa823aeae17686e707e455a872ef0e38c297a08 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -19,6 +19,10 @@ #include "ir/expression.h" #include "ir/irnode.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class ChainExpression : public Expression { public: @@ -33,21 +37,25 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + const Expression *GetExpression() const noexcept { return expression_; } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; void CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_reg) const; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expression_; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index ecefc3a8faa98819a7af97b4a76a6d32be7280c2..b2fb7234fb02998b0509564d21397749e2fe10b0 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -15,8 +15,10 @@ #include "classExpression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "ir/astDump.h" -#include "ir/base/classDefinition.h" namespace panda::es2panda::ir { void ClassExpression::TransformChildren(const NodeTransformer &cb) @@ -34,18 +36,41 @@ void ClassExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ClassExpression"}, {"definition", def_}}); } -void ClassExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ClassExpression::Compile(compiler::PandaGen *pg) const { - def_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ClassExpression::Check([[maybe_unused]] checker::TSChecker *checker) +void ClassExpression::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ClassExpression::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ClassExpression::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassExpression::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +// NOLINTNEXTLINE(google-default-arguments) +ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (def != nullptr) { + def->SetParent(clone); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 1ab8e4a09cef41e69b7982dadee50bf1f4d269bb..0d2ca9b101617bb19f523c3c0d0c58ed97a07b2c 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -23,19 +23,30 @@ class ClassDefinition; class ClassExpression : public Expression { public: - explicit ClassExpression(ClassDefinition *def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + ClassExpression() = delete; + ~ClassExpression() override = default; - const ClassDefinition *Definition() const + NO_COPY_SEMANTIC(ClassExpression); + NO_MOVE_SEMANTIC(ClassExpression); + + explicit ClassExpression(ClassDefinition *const def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ClassDefinition *def_; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index b60d48679a534d877a6043bcf2a4da23c1f8b8d2..7c6c572c9f5beb283c48e87899eb7e5068f3cfcd 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -15,11 +15,9 @@ #include "conditionalExpression.h" -#include "compiler/base/condition.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ConditionalExpression::TransformChildren(const NodeTransformer &cb) @@ -42,119 +40,32 @@ void ConditionalExpression::Dump(ir::AstDumper *dumper) const {{"type", "ConditionalExpression"}, {"test", test_}, {"consequent", consequent_}, {"alternate", alternate_}}); } -template -void CompileImpl(const ConditionalExpression *self, CodeGen *cg) -{ - auto *false_label = cg->AllocLabel(); - auto *end_label = cg->AllocLabel(); - - compiler::Condition::Compile(cg, self->Test(), false_label); - self->Consequent()->Compile(cg); - cg->Branch(self, end_label); - cg->SetLabel(self, false_label); - self->Alternate()->Compile(cg); - cg->SetLabel(self, end_label); -} - void ConditionalExpression::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } void ConditionalExpression::Compile(compiler::ETSGen *etsg) const { - auto *false_label = etsg->AllocLabel(); - auto *end_label = etsg->AllocLabel(); - - compiler::Condition::Compile(etsg, Test(), false_label); - - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - - Consequent()->Compile(etsg); - etsg->ApplyConversion(Consequent()); - etsg->Branch(this, end_label); - etsg->SetLabel(this, false_label); - Alternate()->Compile(etsg); - etsg->ApplyConversion(Alternate()); - etsg->SetLabel(this, end_label); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *ConditionalExpression::Check(checker::TSChecker *checker) { - checker::Type *test_type = test_->Check(checker); - - checker->CheckTruthinessOfType(test_type, test_->Start()); - checker->CheckTestingKnownTruthyCallableOrAwaitableType(test_, test_type, consequent_); - - checker::Type *consequent_type = consequent_->Check(checker); - checker::Type *alternate_type = alternate_->Check(checker); - - return checker->CreateUnionType({consequent_type, alternate_type}); + return checker->GetAnalyzer()->Check(this); } checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - - checker->CheckTruthinessOfType(test_); - - checker::Type *consequent_type = consequent_->Check(checker); - checker::Type *alternate_type = alternate_->Check(checker); - - auto *primitive_consequent_type = checker->ETSBuiltinTypeAsPrimitiveType(consequent_type); - auto *primitive_alter_type = checker->ETSBuiltinTypeAsPrimitiveType(alternate_type); - - if (primitive_consequent_type != nullptr && primitive_alter_type != nullptr) { - if (checker->IsTypeIdenticalTo(consequent_type, alternate_type)) { - SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequent_type)); - } else if (checker->IsTypeIdenticalTo(primitive_consequent_type, primitive_alter_type)) { - checker->FlagExpressionWithUnboxing(consequent_->TsType(), primitive_consequent_type, consequent_); - checker->FlagExpressionWithUnboxing(alternate_->TsType(), primitive_alter_type, alternate_); - - SetTsType(primitive_consequent_type); - } else if (primitive_consequent_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) && - primitive_alter_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { - checker->FlagExpressionWithUnboxing(consequent_->TsType(), primitive_consequent_type, consequent_); - checker->FlagExpressionWithUnboxing(alternate_->TsType(), primitive_alter_type, alternate_); - - SetTsType( - checker->ApplyConditionalOperatorPromotion(checker, primitive_consequent_type, primitive_alter_type)); - } else { - checker->ThrowTypeError("Type error", this->range_.start); - } - } else { - if (!(consequent_type->IsETSArrayType() || alternate_type->IsETSArrayType()) && - !(consequent_type->IsETSObjectType() && alternate_type->IsETSObjectType())) { - checker->ThrowTypeError("Type error", this->range_.start); - } else { - checker->Relation()->SetNode(consequent_); - auto builtin_conseq_type = checker->PrimitiveTypeAsETSBuiltinType(consequent_type); - auto builtin_alternate_type = checker->PrimitiveTypeAsETSBuiltinType(alternate_type); - - if (builtin_conseq_type == nullptr) { - builtin_conseq_type = consequent_type; - } - - if (builtin_alternate_type == nullptr) { - builtin_alternate_type = alternate_type; - } - - SetTsType(checker->FindLeastUpperBound(builtin_conseq_type, builtin_alternate_type)); - } - } - - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator) : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator) : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator) : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index 8e0e7a10d8f05320189fb05223dedd18f2d73dea..e15219d556a5de372ce90e99c2c596a681e6cdb5 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -18,6 +18,11 @@ #include "ir/expression.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class ConditionalExpression : public Expression { public: @@ -32,6 +37,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Test() const noexcept { return test_; @@ -58,7 +67,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/directEvalExpression.cpp b/ets2panda/ir/expressions/directEvalExpression.cpp index 356301fb15468c40b02608ae59669c30bd649465..95cb09e36775f8723343bdc0e58c9e2184637a57 100644 --- a/ets2panda/ir/expressions/directEvalExpression.cpp +++ b/ets2panda/ir/expressions/directEvalExpression.cpp @@ -17,36 +17,29 @@ #include "directEvalExpression.h" -#include "util/helpers.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "compiler/core/regScope.h" namespace panda::es2panda::ir { void DirectEvalExpression::Compile(compiler::PandaGen *pg) const { - if (arguments_.empty()) { - pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); - return; - } - - compiler::RegScope rs(pg); - bool contains_spread = util::Helpers::ContainSpreadElement(arguments_); - if (contains_spread) { - [[maybe_unused]] compiler::VReg args_obj = CreateSpreadArguments(pg); - pg->LoadObjByIndex(this, 0); - } else { - compiler::VReg arg0 = pg->AllocReg(); - auto iter = arguments_.cbegin(); - (*iter++)->Compile(pg); - pg->StoreAccumulator(this, arg0); - - while (iter != arguments_.cend()) { - (*iter++)->Compile(pg); - } - - pg->LoadAccumulator(this, arg0); - } - - pg->DirectEval(this, parser_status_); + 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::Type *DirectEvalExpression::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/directEvalExpression.h b/ets2panda/ir/expressions/directEvalExpression.h index eca191333919c1ad2372095147cc0326165dbdca..3ee2b05badd356fe2ac6ba59dfb6a9a6ef3d003f 100644 --- a/ets2panda/ir/expressions/directEvalExpression.h +++ b/ets2panda/ir/expressions/directEvalExpression.h @@ -16,6 +16,10 @@ #ifndef ES2PANDA_IR_EXPRESSION_DIRECT_EVAL_H #define ES2PANDA_IR_EXPRESSION_DIRECT_EVAL_H +namespace panda::es2panda::compiler { +class JSCompiler; +} // namespace panda::es2panda::compiler + #include "ir/expressions/callExpression.h" namespace panda::es2panda::ir { @@ -28,7 +32,13 @@ public: type_ = AstNodeType::DIRECT_EVAL; } - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class compiler::JSCompiler; + + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: uint32_t parser_status_ {}; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 7f9c194231c0aed7c6c2b7a3d46b99df5c074fff..f8add6e7234e48c6f4a74b28da9f7b43106c9fdc 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -15,13 +15,10 @@ #include "functionExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "ir/astDump.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/variableDeclarator.h" namespace panda::es2panda::ir { void FunctionExpression::TransformChildren(const NodeTransformer &cb) @@ -41,45 +38,37 @@ void FunctionExpression::Dump(ir::AstDumper *dumper) const void FunctionExpression::Compile(compiler::PandaGen *pg) const { - pg->DefineFunction(func_, func_, func_->Scope()->InternalName()); + pg->GetAstCompiler()->Compile(this); } -void FunctionExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void FunctionExpression::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } checker::Type *FunctionExpression::Check(checker::TSChecker *checker) { - varbinder::Variable *func_var = nullptr; - - if (func_->Parent()->Parent() != nullptr && func_->Parent()->Parent()->IsVariableDeclarator() && - func_->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { - func_var = func_->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Variable(); - } - - checker::ScopeContext scope_ctx(checker, func_->Scope()); - - auto *signature_info = checker->Allocator()->New(checker->Allocator()); - checker->CheckFunctionParameterDeclarations(func_->Params(), signature_info); - - auto *signature = - checker->Allocator()->New(signature_info, checker->GlobalResolvingReturnType(), func_); - checker::Type *func_type = checker->CreateFunctionTypeWithSignature(signature); - - if (func_var != nullptr && func_var->TsType() == nullptr) { - func_var->SetTsType(func_type); - } - - signature->SetReturnType(checker->HandleFunctionReturn(func_)); - - func_->Body()->Check(checker); - - return func_type; + return checker->GetAnalyzer()->Check(this); } checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +// NOLINTNEXTLINE(google-default-arguments) +FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const func = func_->Clone(allocator)->AsScriptFunction(); + + if (auto *const clone = allocator->New(func); clone != nullptr) { + func->SetParent(clone); + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index 4b2191857876d40e841c41400d5ce63f5f3de283..52f716d6f8fe28cbac2cc2c16ec6762faca413b3 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -23,25 +23,37 @@ class ScriptFunction; class FunctionExpression : public Expression { public: - explicit FunctionExpression(ScriptFunction *func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) {} + FunctionExpression() = delete; + ~FunctionExpression() override = default; - const ScriptFunction *Function() const + NO_COPY_SEMANTIC(FunctionExpression); + NO_MOVE_SEMANTIC(FunctionExpression); + + explicit FunctionExpression(ScriptFunction *const func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) + { + } + + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ScriptFunction *func_; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index e1f2b3cd2a574197000bf42a07baec92d04bfec7..1ff485d89490f0b56436f3e1936399fd242f3099 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -35,12 +35,12 @@ Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, variable_ = other.variable_; for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index a6ee3dd78ef7aaa4e9400a3bb702c9cd6a3ddc0b..5cfa53c9c227544e6c4d8fe7a85d844206f5cae7 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -186,7 +186,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index e812123c13e5fbc49ccd6910fa2868d0bbde7c13..d9b39dcd391d6028b91e9e4243710f49e5bce488 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -50,9 +50,9 @@ checker::Type *ImportExpression::Check([[maybe_unused]] checker::ETSChecker *che } // NOLINTNEXTLINE(google-default-arguments) -Expression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator) : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index d275dd9a9a4e87384f2455bf2f8a0fa934ec7ca4..884e3dbc294eb82c14fe0166cbe67d9f667af18c 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -30,7 +30,7 @@ public: explicit ImportExpression(Expression *source) : Expression(AstNodeType::IMPORT_EXPRESSION), source_(source) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index b59d2f83c9ae771c68c70ca915af97c031505b6d..5887c20cd73cb0fc8aebd1a34de9e631d1e5d146 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -51,7 +51,7 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index a017c4912ac80e3d975aa02b7b965edbae1793a1..32d4c40d30351f22165c52ebadbaa4c55e770d4e 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -36,7 +36,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 81fc1cb14718f2c6e99534c32beca2b02f6e38fb..d73eed1c05f8c58868b7de42bc5e2e452b273e1e 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -54,7 +54,7 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check } // NOLINTNEXTLINE(google-default-arguments) -Expression *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 8643f5b573c262cff61edab9c12c9e406e5c1fb7..e2a69e617e72b01de88b1323c0ae24dea309540c 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -35,7 +35,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index 6596de257711f061e06f4395377b7ac1fea59ac0..4f333ee45fda52941941b61b3ec75a9600bee506 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -52,7 +52,7 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 048d73884fd2e5dad47d59ef47e11306d7af5867..f1bf1e8f105e8268c35cb28b040c8fe46dadc36d 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -41,7 +41,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 10868ce8325bb18e32378cdc0cce05e2578a7ede..f04d88b766385a9e260d2f7cc285ff2736a5938d 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -15,11 +15,9 @@ #include "nullLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,29 +30,26 @@ void NullLiteral::Dump(ir::AstDumper *dumper) const void NullLiteral::Compile(compiler::PandaGen *pg) const { - pg->LoadConst(this, compiler::Constant::JS_NULL); + pg->GetAstCompiler()->Compile(this); } void NullLiteral::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorNull(this, TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *NullLiteral::Check(checker::TSChecker *checker) { - return checker->GlobalNullType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *NullLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *NullLiteral::Check(checker::ETSChecker *checker) { - if (TsType() == nullptr) { - SetTsType(checker->GlobalETSNullType()); - } - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 1fa60a74f0fa783d1d44d8106f99a51ea01d32c5..1fd823acca97cb1848e56d4cd3018b2621e06738 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -29,7 +29,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -37,7 +37,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index d411de92385590e1760a15ad0e1145ef357cb244..af42b4f5124cb49f114ad9383fa0336e0685bf90 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -15,12 +15,9 @@ #include "numberLiteral.h" -#include "util/helpers.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void NumberLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -33,85 +30,26 @@ void NumberLiteral::Dump(ir::AstDumper *dumper) const void NumberLiteral::Compile(compiler::PandaGen *pg) const { - if (std::isnan(number_.GetDouble())) { - pg->LoadConst(this, compiler::Constant::JS_NAN); - } else if (!std::isfinite(number_.GetDouble())) { - pg->LoadConst(this, compiler::Constant::JS_INFINITY); - } else if (util::Helpers::IsInteger(number_.GetDouble())) { - pg->LoadAccumulatorInt(this, static_cast(number_.GetDouble())); - } else { - pg->LoadAccumulatorDouble(this, number_.GetDouble()); - } + pg->GetAstCompiler()->Compile(this); } void NumberLiteral::Compile(compiler::ETSGen *etsg) const { - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - if (number_.IsInt()) { - if (util::Helpers::IsTargetFitInSourceRange( - number_.GetInt())) { - etsg->LoadAccumulatorByte(this, static_cast(number_.GetInt())); - return; - } - - if (util::Helpers::IsTargetFitInSourceRange( - number_.GetInt())) { - etsg->LoadAccumulatorShort(this, static_cast(number_.GetInt())); - return; - } - - etsg->LoadAccumulatorInt(this, static_cast(number_.GetInt())); - return; - } - - if (number_.IsLong()) { - etsg->LoadAccumulatorWideInt(this, number_.GetLong()); - return; - } - - if (number_.IsFloat()) { - etsg->LoadAccumulatorFloat(this, number_.GetFloat()); - return; - } - - etsg->LoadAccumulatorDouble(this, number_.GetDouble()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *NumberLiteral::Check(checker::TSChecker *checker) { - auto search = checker->NumberLiteralMap().find(number_.GetDouble()); - if (search != checker->NumberLiteralMap().end()) { - return search->second; - } - - auto *new_num_literal_type = checker->Allocator()->New(number_.GetDouble()); - checker->NumberLiteralMap().insert({number_.GetDouble(), new_num_literal_type}); - return new_num_literal_type; + return checker->GetAnalyzer()->Check(this); } -checker::Type *NumberLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *NumberLiteral::Check(checker::ETSChecker *checker) { - if (number_.IsInt()) { - SetTsType(checker->CreateIntType(number_.GetInt())); - return TsType(); - } - - if (number_.IsLong()) { - SetTsType(checker->CreateLongType(number_.GetLong())); - return TsType(); - } - - if (number_.IsFloat()) { - SetTsType(checker->CreateFloatType(number_.GetFloat())); - return TsType(); - } - - SetTsType(checker->CreateDoubleType(number_.GetDouble())); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index e7391b8e40398b77f86ecd401c3e64d6517acdfa..00b97c52583aa580f2faa537b1c9c9106f0ad260 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -50,7 +50,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -58,7 +58,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: lexer::Number number_; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index d278513f9fe09ca26e43472a2f48dc2ec46a2fbd..353d8fabb251a080ece8fdfb2bce87b42201acf2 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -19,7 +19,7 @@ #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,21 +32,26 @@ void RegExpLiteral::Dump(ir::AstDumper *dumper) const void RegExpLiteral::Compile(compiler::PandaGen *pg) const { - pg->CreateRegExpWithLiteral(this, pattern_, static_cast(flags_)); + pg->GetAstCompiler()->Compile(this); +} + +void RegExpLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } checker::Type *RegExpLiteral::Check(checker::TSChecker *checker) { - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *RegExpLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *RegExpLiteral::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flags_str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 8ee1c453e535964d0a1c483a91f7f276a99d7e85..61ffde4bc4a96415c9f61aa9278dca433306683b 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -45,14 +45,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView pattern_; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 2c45cb252ecda5adb8c4d5b410bef4345cf508af..1406de9d88d2740d1acc685cfea6bdffbb35e3da 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -15,11 +15,9 @@ #include "stringLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,38 +30,26 @@ void StringLiteral::Dump(ir::AstDumper *dumper) const void StringLiteral::Compile(compiler::PandaGen *pg) const { - pg->LoadAccumulatorString(this, str_); + pg->GetAstCompiler()->Compile(this); } void StringLiteral::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorString(this, str_); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *StringLiteral::Check(checker::TSChecker *checker) { - auto search = checker->StringLiteralMap().find(str_); - if (search != checker->StringLiteralMap().end()) { - return search->second; - } - - auto *new_str_literal_type = checker->Allocator()->New(str_); - checker->StringLiteralMap().insert({str_, new_str_literal_type}); - - return new_str_literal_type; + return checker->GetAnalyzer()->Check(this); } -checker::Type *StringLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *StringLiteral::Check(checker::ETSChecker *checker) { - if (TsType() == nullptr) { - SetTsType(checker->CreateETSStringLiteralType(str_)); - } - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index da7f22fdadbab4187e7988f6e37c7e7fcf8041fb..a6191f8c641cffaeda2ff56f8b2620a2c8a685bd 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -42,7 +42,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -50,7 +50,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView str_; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 44936411def8039ca48d27983c70f5b50f85269e..eda32a4f54bc8b03bc90d84116794cfc99a46cad 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -15,28 +15,14 @@ #include "memberExpression.h" -#include "checker/types/typeRelation.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/function.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsExtensionFuncHelperType.h" -#include "checker/types/ets/etsFunctionType.h" -#include "checker/types/signature.h" -#include "ir/astDump.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/ts/tsEnumMember.h" -#include "util/helpers.h" namespace panda::es2panda::ir { -MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, Expression *const object, Expression *const property) - : MemberExpression(*this) +MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, MemberExpression const &other, + Expression *const object, Expression *const property) + : MemberExpression(other) { object_ = object; if (object_ != nullptr) { @@ -469,12 +455,12 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator) : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator) : nullptr; + auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; + auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; - if (auto *const clone = allocator->New(Tag {}, object, property); clone != nullptr) { + if (auto *const clone = allocator->New(Tag {}, *this, object, property); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 47c172e843045b4e1361a60898a1fbd5630f39b7..7b638ddffec515f5712ffac6680ccb603c5378b0 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -57,7 +57,7 @@ public: { } - explicit MemberExpression(Tag tag, Expression *object, Expression *property); + explicit MemberExpression(Tag tag, MemberExpression const &other, Expression *object, Expression *property); [[nodiscard]] Expression *Object() noexcept { @@ -142,7 +142,7 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index 565ba8caa42aac382506643a66d32de7706a6e23..ada998946446ca1934c1292feb440c4929caadf4 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -28,16 +28,16 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const : Expression(static_cast(other)), arguments_(allocator->Adapter()) { if (other.callee_ != nullptr) { - callee_ = other.callee_->Clone(allocator, this); + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); } for (auto *argument : other.arguments_) { - arguments_.emplace_back(argument->Clone(allocator, this)); + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index 2cefd3ce6d746341f26e6e2d26aca857bb0219c0..6fc447c38150639e107c1602e038233d3b586182 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index f3b4b4ebff09da14eb37d8fd2e2cedca2209ae1e..c5e6218895dade1202d23708083679ab2fe8fb6d 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -58,16 +58,16 @@ ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpress optional_ = other.optional_; for (auto *property : other.properties_) { - properties_.emplace_back(property->Clone(allocator, this)); + properties_.emplace_back(property->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index b258313d0b93de38a1d3b55eab3cae03dfbc5123..70121771fe53fdf4d2754e6b786fdf7e0ff429c5 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -83,7 +83,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index b24ea45bebab63c11dc55a32528f0a71ea030e1e..ab2a356ac6b9b8ee39d989fc697c0cf6c348091b 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -40,7 +40,7 @@ checker::Type *OmittedExpression::Check([[maybe_unused]] checker::ETSChecker *ch } // NOLINTNEXTLINE(google-default-arguments) -Expression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index ee722bf0c336ee9e36d8d58fc9d017e7f02ca9db..20f7f5ead9e959abb84db7903320aebd3a0c81c7 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -31,7 +31,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index cde77a042f784b3d3574295e4c64f03e31ef02f6..f855c5826d318cf7049e68b19dce7948dc290a28 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -24,12 +24,12 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE : Expression(static_cast(other)), sequence_(allocator->Adapter()) { for (auto *sequence : other.sequence_) { - sequence_.emplace_back(sequence->Clone(allocator, this)); + sequence_.emplace_back(sequence->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 29a1fd2aec43f64f48f98152123afb97c7f8a0d6..79e9974db8d061a6b10ca30193b9eea37c4cf63a 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 8858bffbc9e4ff10e2b72a72c26d99b24b8b8f17..b7d291a57f39b93f74a0cd3b4f45b3c238fd4904 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -65,7 +65,7 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 31b2835975906406105493339f80923749dc2e28..27d45416083710a98f04330679c5a7f43f2bcb7b 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -29,7 +29,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 3960c0d1c3ee7c915b032ecb59f765e754cdf4d2..b68a413ab31afb6b1ea12d6e08e51467ae94f2bf 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -83,12 +83,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec } // NOLINTNEXTLINE(google-default-arguments) -Expression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator) : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator)->AsTemplateLiteral() : nullptr; - auto *const type_params = - type_params_ != nullptr ? type_params_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; + auto *const type_params = type_params_ != nullptr ? type_params_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(tag, quasi, type_params); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index 194571cf79c12eda61595a57a64efd753b6d948c..6aeabf80f7bcebc9d807cfe829c990ec7c1e40d2 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -52,7 +52,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 82a52458f67c586989cd81b76cccedc736d56c51..61c58acd1ee21815bdafb39788b142d871287703 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -30,16 +30,16 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral expressions_(allocator->Adapter()) { for (auto *quasy : other.quasis_) { - quasis_.emplace_back(quasy->Clone(allocator, this)->AsTemplateElement()); + quasis_.emplace_back(quasy->Clone(allocator, this)); } for (auto *expression : other.expressions_) { - expressions_.emplace_back(expression->Clone(allocator, this)); + expressions_.emplace_back(expression->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 3ec24e8007cc43548ee7074e6060b0ff1d30bc3c..bc2d31666dcfc2116ad025c3b5c2a9af7b73d47f 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -49,7 +49,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 4bfd27544111932efed650ee506898500715312c..0c91e916486119c26058cbf27f381ee4c87ace5a 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -109,7 +109,7 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index a98f7f39df074533882dbf48b0053b24524724f1..6ffa359d07232aedc724f3e53b009f4f6d9fe493 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -29,7 +29,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 2f6ced1150f5be10b5062bbd0193e929d5722955..a73cbef0771f745f05549cd07d211661f5374add 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -305,9 +305,9 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index 1e2fb24c0b3e260332e46efe3022f22b27dd2987..ade78126852b73f78907de3db4bc4954627ca53e 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index e72ca193e8daeafe42af10f01d419cdbdc17b9f4..ae49e98ae65b35975ade9f7f3a03571012e813f3 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -149,9 +149,9 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 34901b1845bbf46306de88a9c286b86845db85dd..494fbaf2981e13e3c443338068176a4fb929d465 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 4aadc7a54582364feea1d450fdf0c06c3361bad6..465498c428b001ee02f60fd2e9cabb698570705b 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -70,9 +70,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 9e8e85608b77f19cfcdf8a788394cb66af1fa9de..3c2f5282e2fc6549926d84443e13f0e9a8e1fc23 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -47,7 +47,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/module/exportAllDeclaration.cpp b/ets2panda/ir/module/exportAllDeclaration.cpp index 9867f99848a1b6bac1430a33d5f7a758011eb814..c34cb356e49c57204f7920e1862daed02a77ec6d 100644 --- a/ets2panda/ir/module/exportAllDeclaration.cpp +++ b/ets2panda/ir/module/exportAllDeclaration.cpp @@ -15,9 +15,9 @@ #include "exportAllDeclaration.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportAllDeclaration::TransformChildren(const NodeTransformer &cb) @@ -43,15 +43,23 @@ void ExportAllDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullish(exported_)}}); } -void ExportAllDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportAllDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportAllDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportAllDeclaration::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportAllDeclaration.h b/ets2panda/ir/module/exportAllDeclaration.h index afcdea02dc0642a422c4a88e6935da6cfaafb38e..89926b4ec8ba4af0a07361fcf324be8611a1eedb 100644 --- a/ets2panda/ir/module/exportAllDeclaration.h +++ b/ets2panda/ir/module/exportAllDeclaration.h @@ -42,9 +42,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: StringLiteral *source_; diff --git a/ets2panda/ir/module/exportDefaultDeclaration.cpp b/ets2panda/ir/module/exportDefaultDeclaration.cpp index 657179005ad193df5ed6ec2b95386b1f2c72077f..82e090025be581f9ea29b24ed39d83d1c7bc210f 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.cpp +++ b/ets2panda/ir/module/exportDefaultDeclaration.cpp @@ -15,8 +15,9 @@ #include "exportDefaultDeclaration.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ExportDefaultDeclaration::TransformChildren(const NodeTransformer &cb) @@ -35,19 +36,23 @@ void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}}); } -void ExportDefaultDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const { - decl_->Compile(pg); - pg->StoreModuleVar(this, "default"); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void ExportDefaultDeclaration::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportDefaultDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportDefaultDeclaration::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportDefaultDeclaration.h b/ets2panda/ir/module/exportDefaultDeclaration.h index 38af658d5fd2109cc40f22b083b4cf0526b5b33a..6d32882db58427972a6495ba267d3c04cb356173 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.h +++ b/ets2panda/ir/module/exportDefaultDeclaration.h @@ -44,9 +44,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *decl_; diff --git a/ets2panda/ir/module/exportNamedDeclaration.cpp b/ets2panda/ir/module/exportNamedDeclaration.cpp index 5bbd501593ea5ebbc42befcf2b5d8808ecb93f0d..ff886326fd879b9e8fe06e74fdf6dde74a11d3d6 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.cpp +++ b/ets2panda/ir/module/exportNamedDeclaration.cpp @@ -15,12 +15,9 @@ #include "exportNamedDeclaration.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/exportSpecifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportNamedDeclaration::TransformChildren(const NodeTransformer &cb) @@ -70,27 +67,23 @@ void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const {"specifiers", specifiers_}}); } -void ExportNamedDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const { - if (decl_ == nullptr) { - return; - } - - decl_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -void ExportNamedDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ExportNamedDeclaration::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportNamedDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportNamedDeclaration::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportNamedDeclaration.h b/ets2panda/ir/module/exportNamedDeclaration.h index e794931975cb496b4ff75af645ee64f51e014fb2..f455b8985e6a3c51e15f4bd2832950257da1806c 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.h +++ b/ets2panda/ir/module/exportNamedDeclaration.h @@ -78,10 +78,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ArenaVector decorators_; diff --git a/ets2panda/ir/module/exportSpecifier.cpp b/ets2panda/ir/module/exportSpecifier.cpp index e308dd2b06e10d8ac06045377dea3290fad64075..2aa19dee82c77cf7cb630552fde92cc83c183f9c 100644 --- a/ets2panda/ir/module/exportSpecifier.cpp +++ b/ets2panda/ir/module/exportSpecifier.cpp @@ -15,8 +15,9 @@ #include "exportSpecifier.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportSpecifier::TransformChildren(const NodeTransformer &cb) @@ -36,15 +37,23 @@ void ExportSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExportSpecifier"}, {"local", local_}, {"exported", exported_}}); } -void ExportSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportSpecifier.h b/ets2panda/ir/module/exportSpecifier.h index f6bfefbd9f576fc633d063ff5ac4fa8df07eba16..d50d2bee59f714f3f87dc48258fd4c268bfe6a74 100644 --- a/ets2panda/ir/module/exportSpecifier.h +++ b/ets2panda/ir/module/exportSpecifier.h @@ -41,9 +41,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index b946fbd1b679d90f467435cc458cbd68d79a3dbe..e1208b0d02a56bb3b2eb6ba72753ec14817a2ede 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -15,11 +15,9 @@ #include "importDeclaration.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/importNamespaceSpecifier.h" -#include "ir/module/importSpecifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportDeclaration::TransformChildren(const NodeTransformer &cb) @@ -45,27 +43,23 @@ void ImportDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportDeclaration"}, {"source", source_}, {"specifiers", specifiers_}}); } -void ImportDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void ImportDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ImportDeclaration::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void ImportDeclaration::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportDeclaration::Check(checker::TSChecker *checker) { - checker::Type *type = nullptr; - for (auto *spec : specifiers_) { - if (spec->IsImportNamespaceSpecifier()) { - type = spec->AsImportNamespaceSpecifier()->Check(checker); - } - } + return checker->GetAnalyzer()->Check(this); +} - return type; +checker::Type *ImportDeclaration::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importDeclaration.h b/ets2panda/ir/module/importDeclaration.h index 18594b35e398f98c9fe13b2b31e26f42c2272922..fc8e923882bad9d6d0b209670f82e88cf8a5f284 100644 --- a/ets2panda/ir/module/importDeclaration.h +++ b/ets2panda/ir/module/importDeclaration.h @@ -47,10 +47,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: StringLiteral *source_; diff --git a/ets2panda/ir/module/importDefaultSpecifier.cpp b/ets2panda/ir/module/importDefaultSpecifier.cpp index 2413efb897afcfa10a9ee7636f5f788fa027f7a9..ea4a43b93e199df6aa0178d0fbca81eb82e89459 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.cpp +++ b/ets2panda/ir/module/importDefaultSpecifier.cpp @@ -15,11 +15,9 @@ #include "importDefaultSpecifier.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportDefaultSpecifier::TransformChildren(const NodeTransformer &cb) @@ -37,15 +35,23 @@ void ImportDefaultSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportDefaultSpecifier"}, {"local", local_}}); } -void ImportDefaultSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ImportDefaultSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ImportDefaultSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportDefaultSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importDefaultSpecifier.h b/ets2panda/ir/module/importDefaultSpecifier.h index 7d39425a088c59f202e41c07c2acbc619f0478d3..0ad73508467408f9477946cf9ec2a776aac1a244 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.h +++ b/ets2panda/ir/module/importDefaultSpecifier.h @@ -35,9 +35,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importNamespaceSpecifier.cpp b/ets2panda/ir/module/importNamespaceSpecifier.cpp index 9607da9ba6a098627b7b78b4c0d9d03a15096575..44660316c6ed0e0860617c2d976c7e8f2a24316b 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.cpp +++ b/ets2panda/ir/module/importNamespaceSpecifier.cpp @@ -15,12 +15,10 @@ #include "importNamespaceSpecifier.h" -#include "checker/ETSchecker.h" #include "varbinder/ETSBinder.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportNamespaceSpecifier::TransformChildren(const NodeTransformer &cb) @@ -38,81 +36,23 @@ void ImportNamespaceSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportNamespaceSpecifier"}, {"local", local_}}); } -void ImportNamespaceSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +void ImportNamespaceSpecifier::Compile(compiler::PandaGen *pg) const { - return nullptr; + pg->GetAstCompiler()->Compile(this); } -checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +void ImportNamespaceSpecifier::Compile(compiler::ETSGen *etsg) const { - if (Local()->Name().Empty()) { - return nullptr; - } - - if (Local()->AsIdentifier()->TsType() != nullptr) { - return local_->TsType(); - } - - auto *import_decl = Parent()->AsETSImportDeclaration(); - auto import_path = import_decl->Source()->Str(); - - if (import_decl->IsPureDynamic()) { - auto *type = checker->GlobalBuiltinDynamicType(import_decl->Language()); - checker->SetrModuleObjectTsType(local_, type); - return type; - } - - std::string package_name = - (import_decl->Module() == nullptr) ? import_path.Mutf8() : import_decl->Module()->Str().Mutf8(); - - std::replace(package_name.begin(), package_name.end(), '/', '.'); - util::UString package_path(package_name, checker->Allocator()); - std::vector synthetic_names = checker->GetNameForSynteticObjectType(package_path.View()); - - ASSERT(!synthetic_names.empty()); - - auto assembler_name = synthetic_names[0]; - if (import_decl->Module() != nullptr) { - assembler_name = util::UString(assembler_name.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), - checker->Allocator()) - .View(); - } - - auto *module_object_type = - checker->Allocator()->New(checker->Allocator(), synthetic_names[0], assembler_name, - local_->AsIdentifier(), checker::ETSObjectFlags::CLASS); - - auto *root_decl = checker->Allocator()->New(synthetic_names[0]); - varbinder::LocalVariable *root_var = - checker->Allocator()->New(root_decl, varbinder::VariableFlags::NONE); - root_var->SetTsType(module_object_type); - - synthetic_names.erase(synthetic_names.begin()); - checker::ETSObjectType *last_object_type(module_object_type); - - for (const auto &synthetic_name : synthetic_names) { - auto *synthetic_obj_type = - checker->Allocator()->New(checker->Allocator(), synthetic_name, synthetic_name, - local_->AsIdentifier(), checker::ETSObjectFlags::NO_OPTS); - - auto *class_decl = checker->Allocator()->New(synthetic_name); - varbinder::LocalVariable *var = - checker->Allocator()->New(class_decl, varbinder::VariableFlags::CLASS); - var->SetTsType(synthetic_obj_type); - last_object_type->AddProperty(var); - synthetic_obj_type->SetEnclosingType(last_object_type); - last_object_type = synthetic_obj_type; - } + etsg->GetAstCompiler()->Compile(this); +} - checker->SetPropertiesForModuleObject( - last_object_type, - (import_decl->Module() != nullptr) - ? util::UString(import_path.Mutf8() + import_decl->Module()->Str().Mutf8(), checker->Allocator()).View() - : import_path); - checker->SetrModuleObjectTsType(local_, last_object_type); +checker::Type *ImportNamespaceSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - return module_object_type; +checker::Type *ImportNamespaceSpecifier::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importNamespaceSpecifier.h b/ets2panda/ir/module/importNamespaceSpecifier.h index 0af20262ba57e28274a7974262ef5ca60a22978a..e725cce1aef38761c90498c64939d19eeabf2c45 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.h +++ b/ets2panda/ir/module/importNamespaceSpecifier.h @@ -41,9 +41,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importSpecifier.cpp b/ets2panda/ir/module/importSpecifier.cpp index 343614347e2e30cb5af932d939965a43cac4ba45..984e4137d5861c8b746bb2fc0bbe2a63f02e5559 100644 --- a/ets2panda/ir/module/importSpecifier.cpp +++ b/ets2panda/ir/module/importSpecifier.cpp @@ -15,11 +15,9 @@ #include "importSpecifier.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/importDeclaration.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportSpecifier::TransformChildren(const NodeTransformer &cb) @@ -43,19 +41,22 @@ void ImportSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportSpecifier"}, {"local", ir::AstDumper::Optional(local_)}, {"imported", imported_}}); } -void ImportSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ImportSpecifier::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ImportSpecifier::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); +} +void ImportSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ImportSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importSpecifier.h b/ets2panda/ir/module/importSpecifier.h index 9a0c1311abb9eee8973fb19ac1479b050cfabe99..c59fba3bed65f9dadc3658fc27678a920357a5c9 100644 --- a/ets2panda/ir/module/importSpecifier.h +++ b/ets2panda/ir/module/importSpecifier.h @@ -51,10 +51,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *imported_; diff --git a/ets2panda/ir/statement.cpp b/ets2panda/ir/statement.cpp index 8eb886a24eab5ca13ccc2fd3120d1c20620b2d7c..4bec7797487312b9b7890b59b00376ff685e0095 100644 --- a/ets2panda/ir/statement.cpp +++ b/ets2panda/ir/statement.cpp @@ -20,7 +20,7 @@ namespace panda::es2panda::ir { void AnnotatedStatement::CloneTypeAnnotation(ArenaAllocator *const allocator) { if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + SetTsTypeAnnotation(annotation->Clone(allocator, this)); } } diff --git a/ets2panda/ir/statement.h b/ets2panda/ir/statement.h index 76e05d1d4bf3c4b6365e58329741e29455b92e6a..c1004f771cfe403cbaa9616532c0e3ff1630f3bd 100644 --- a/ets2panda/ir/statement.h +++ b/ets2panda/ir/statement.h @@ -36,14 +36,6 @@ public: virtual void SetReturnType([[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *type) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Statement *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Statement(AstNodeType type) : AstNode(type) {} explicit Statement(AstNodeType type, ModifierFlags flags) : AstNode(type, flags) {} diff --git a/ets2panda/ir/statements/classDeclaration.cpp b/ets2panda/ir/statements/classDeclaration.cpp index 6c0822d5f27188bd9be8fa96bf140895ef367ece..627e9bece0a42037e8d65b33e331a28d9073671d 100644 --- a/ets2panda/ir/statements/classDeclaration.cpp +++ b/ets2panda/ir/statements/classDeclaration.cpp @@ -15,13 +15,9 @@ #include "classDeclaration.h" -#include "compiler/base/lreference.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/base/classDefinition.h" -#include "ir/base/decorator.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ClassDeclaration::TransformChildren(const NodeTransformer &cb) @@ -47,26 +43,23 @@ void ClassDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ClassDeclaration"}, {"definition", def_}, {"decorators", AstDumper::Optional(decorators_)}}); } -void ClassDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ClassDeclaration::Compile(compiler::PandaGen *pg) const { - auto lref = compiler::JSLReference::Create(pg, def_->Ident(), true); - def_->Compile(pg); - lref.SetValue(); + pg->GetAstCompiler()->Compile(this); } -void ClassDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ClassDeclaration::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ClassDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ClassDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *ClassDeclaration::Check(checker::ETSChecker *checker) { - def_->Check(checker); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/classDeclaration.h b/ets2panda/ir/statements/classDeclaration.h index c2e535c0740205f0be808f6d4e772d51b8f8e7b1..8984cf0651ff6dcaf30a39b62ea9db4a58f2fb9f 100644 --- a/ets2panda/ir/statements/classDeclaration.h +++ b/ets2panda/ir/statements/classDeclaration.h @@ -54,11 +54,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ClassDefinition *def_; diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index 74536dc361990216d18cc453b69cb7bc40b21b77..da58f870ae1043602b4e21bcb8460c06f4742262 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -15,10 +15,9 @@ #include "continueStatement.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "checker/ETSchecker.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ContinueStatement::TransformChildren(const NodeTransformer &cb) @@ -40,34 +39,23 @@ void ContinueStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); } -template -void CompileImpl(const ContinueStatement *self, [[maybe_unused]] CodeGen *cg) -{ - compiler::Label *target = cg->ControlFlowChangeContinue(self->Ident()); - cg->Branch(self, target); -} - -void ContinueStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ContinueStatement::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } -void ContinueStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ContinueStatement::Compile(compiler::ETSGen *etsg) const { - if (etsg->ExtendWithFinalizer(parent_, this)) { - return; - } - CompileImpl(this, etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ContinueStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ContinueStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *ContinueStatement::Check(checker::ETSChecker *checker) { - target_ = checker->FindJumpTarget(Type(), this, ident_); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/continueStatement.h b/ets2panda/ir/statements/continueStatement.h index 2eead3db014edee313f4d7df437480dc734736f2..4468f9e76b0e8d51d521619c0951a482f7225535 100644 --- a/ets2panda/ir/statements/continueStatement.h +++ b/ets2panda/ir/statements/continueStatement.h @@ -19,12 +19,24 @@ #include "ir/statement.h" #include "ir/expressions/identifier.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + +namespace panda::es2panda::compiler { +class ETSCompiler; +} // namespace panda::es2panda::compiler + namespace panda::es2panda::ir { class ContinueStatement : public Statement { public: explicit ContinueStatement() : Statement(AstNodeType::CONTINUE_STATEMENT) {} explicit ContinueStatement(Identifier *ident) : Statement(AstNodeType::CONTINUE_STATEMENT), ident_(ident) {} + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class compiler::ETSCompiler; + const Identifier *Ident() const { return ident_; @@ -38,10 +50,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *ident_ {}; diff --git a/ets2panda/ir/statements/debuggerStatement.cpp b/ets2panda/ir/statements/debuggerStatement.cpp index 506daf50ae480818324ae2a6532fa1dc2cd1ba5b..b0bb23faadd70a585650ec54cd7d21c5988d5c0f 100644 --- a/ets2panda/ir/statements/debuggerStatement.cpp +++ b/ets2panda/ir/statements/debuggerStatement.cpp @@ -15,7 +15,9 @@ #include "debuggerStatement.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -26,15 +28,23 @@ void DebuggerStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "DebuggerStatement"}}); } -void DebuggerStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *DebuggerStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *DebuggerStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *DebuggerStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/debuggerStatement.h b/ets2panda/ir/statements/debuggerStatement.h index d9858dbfd48308a8c4f381539a0c05f9936ab209..792af73b967f1e99bf3c29aa1a3b22ffe6e35131 100644 --- a/ets2panda/ir/statements/debuggerStatement.h +++ b/ets2panda/ir/statements/debuggerStatement.h @@ -26,9 +26,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: }; diff --git a/ets2panda/ir/statements/doWhileStatement.cpp b/ets2panda/ir/statements/doWhileStatement.cpp index e36442c438d676836f8e153234cd403a5ea8ac23..93d2a413e6a8e2efabe04fa0d386c38083230573 100644 --- a/ets2panda/ir/statements/doWhileStatement.cpp +++ b/ets2panda/ir/statements/doWhileStatement.cpp @@ -21,8 +21,6 @@ #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" namespace panda::es2panda::ir { void DoWhileStatement::TransformChildren(const NodeTransformer &cb) @@ -42,55 +40,23 @@ void DoWhileStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "DoWhileStatement"}, {"body", body_}, {"test", test_}}); } -template -void CompileImpl(const DoWhileStatement *self, [[maybe_unused]] CodeGen *cg) +void DoWhileStatement::Compile(compiler::PandaGen *pg) const { - auto *start_label = cg->AllocLabel(); - compiler::LabelTarget label_target(cg); - - cg->SetLabel(self, start_label); - - { - compiler::LocalRegScope reg_scope(cg, self->Scope()); - compiler::LabelContext label_ctx(cg, label_target); - self->Body()->Compile(cg); - } - - cg->SetLabel(self, label_target.ContinueTarget()); - compiler::Condition::Compile(cg, self->Test(), label_target.BreakTarget()); - - cg->Branch(self, start_label); - cg->SetLabel(self, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } -void DoWhileStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void DoWhileStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, pg); + etsg->GetAstCompiler()->Compile(this); } -void DoWhileStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +checker::Type *DoWhileStatement::Check(checker::TSChecker *checker) { - CompileImpl(this, etsg); + return checker->GetAnalyzer()->Check(this); } -checker::Type *DoWhileStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *DoWhileStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - checker::Type *test_type = Test()->Check(checker); - checker->CheckTruthinessOfType(test_type, Test()->Start()); - Body()->Check(checker); - - return nullptr; -} - -checker::Type *DoWhileStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - checker::ScopeContext scope_ctx(checker, Scope()); - - checker->CheckTruthinessOfType(Test()); - Body()->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/doWhileStatement.h b/ets2panda/ir/statements/doWhileStatement.h index 58b970bfdcecebd33c19ab6b66e1d7fcb69ce851..bc811edca2c361e570539a30fa61467242c010c3 100644 --- a/ets2panda/ir/statements/doWhileStatement.h +++ b/ets2panda/ir/statements/doWhileStatement.h @@ -62,10 +62,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Statement *body_; diff --git a/ets2panda/ir/statements/emptyStatement.cpp b/ets2panda/ir/statements/emptyStatement.cpp index 5da09fdd2284bad2b67f115767bb55cd0e163517..4c00f2a89ee6f42aea577b5c9121229994a54b11 100644 --- a/ets2panda/ir/statements/emptyStatement.cpp +++ b/ets2panda/ir/statements/emptyStatement.cpp @@ -15,7 +15,9 @@ #include "emptyStatement.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -26,15 +28,23 @@ void EmptyStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "EmptyStatement"}}); } -void EmptyStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void EmptyStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void EmptyStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *EmptyStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *EmptyStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *EmptyStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *EmptyStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/emptyStatement.h b/ets2panda/ir/statements/emptyStatement.h index 44c82b2fba26420907ff6388cb687a08da889b22..a815449fbadf23621f73dfd5ba1ba21070799c57 100644 --- a/ets2panda/ir/statements/emptyStatement.h +++ b/ets2panda/ir/statements/emptyStatement.h @@ -26,9 +26,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: }; diff --git a/ets2panda/ir/statements/expressionStatement.cpp b/ets2panda/ir/statements/expressionStatement.cpp index 61ebaca008147e8c817413c5420f97726aaa5de2..d4750832be8cdad6688db5c3f34f4f80185336df 100644 --- a/ets2panda/ir/statements/expressionStatement.cpp +++ b/ets2panda/ir/statements/expressionStatement.cpp @@ -15,8 +15,9 @@ #include "expressionStatement.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExpressionStatement::TransformChildren(const NodeTransformer &cb) @@ -34,23 +35,23 @@ void ExpressionStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExpressionStatement"}, {"expression", expression_}}); } -void ExpressionStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExpressionStatement::Compile(compiler::PandaGen *pg) const { - expression_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -void ExpressionStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ExpressionStatement::Compile(compiler::ETSGen *etsg) const { - expression_->Compile(etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExpressionStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExpressionStatement::Check(checker::TSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExpressionStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExpressionStatement::Check(checker::ETSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/expressionStatement.h b/ets2panda/ir/statements/expressionStatement.h index 2f80d87221946a812a42877339724d51be7cad30..56ea20363273428ddb7a53d833ecd72818830d1f 100644 --- a/ets2panda/ir/statements/expressionStatement.h +++ b/ets2panda/ir/statements/expressionStatement.h @@ -38,10 +38,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expression_; diff --git a/ets2panda/ir/statements/forInStatement.cpp b/ets2panda/ir/statements/forInStatement.cpp index b21b387e5d819c361781df5ef246153ef6dd3d6d..331be2f2fff94081c1ae8d4b1b8527e784c91c1a 100644 --- a/ets2panda/ir/statements/forInStatement.cpp +++ b/ets2panda/ir/statements/forInStatement.cpp @@ -20,9 +20,7 @@ #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" #include "checker/TSchecker.h" - -#include "ir/astDump.h" -#include "ir/expression.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void ForInStatement::TransformChildren(const NodeTransformer &cb) @@ -44,49 +42,23 @@ void ForInStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ForInStatement"}, {"left", left_}, {"right", right_}, {"body", body_}}); } -void ForInStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForInStatement::Compile(compiler::PandaGen *pg) const { - compiler::LabelTarget label_target(pg); - - compiler::RegScope rs(pg); - compiler::VReg iter = pg->AllocReg(); - compiler::VReg prop_name = pg->AllocReg(); - - // create enumerator - right_->Compile(pg); - pg->GetPropIterator(this); - pg->StoreAccumulator(this, iter); - - pg->SetLabel(this, label_target.ContinueTarget()); - - // get next prop of enumerator - pg->GetNextPropName(this, iter); - pg->StoreAccumulator(this, prop_name); - pg->BranchIfUndefined(this, label_target.BreakTarget()); - - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - auto lref = compiler::JSLReference::Create(pg, left_, false); - pg->LoadAccumulator(this, prop_name); - lref.SetValue(); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - - { - compiler::LoopEnvScope env_scope(pg, Scope(), label_target); - body_->Compile(pg); - } + pg->GetAstCompiler()->Compile(this); +} - pg->Branch(this, label_target.ContinueTarget()); - pg->SetLabel(this, label_target.BreakTarget()); +void ForInStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForInStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForInStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ForInStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ForInStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forInStatement.h b/ets2panda/ir/statements/forInStatement.h index 1089e3ffa4875d5b9040c3d74c90e07c7c9dc9f0..78d482e827d98b8884b84ddea5abec50275b01ef 100644 --- a/ets2panda/ir/statements/forInStatement.h +++ b/ets2panda/ir/statements/forInStatement.h @@ -72,9 +72,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *left_; diff --git a/ets2panda/ir/statements/forOfStatement.cpp b/ets2panda/ir/statements/forOfStatement.cpp index 1b7ae5a7cc17222bc20fb1a1eda01b3978f74d1f..50cb1e9d1c9e63c719ed6236d68ed35d2f2d12e8 100644 --- a/ets2panda/ir/statements/forOfStatement.cpp +++ b/ets2panda/ir/statements/forOfStatement.cpp @@ -19,14 +19,9 @@ #include "compiler/base/iterators.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/superExpression.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/statements/variableDeclaration.h" namespace panda::es2panda::ir { void ForOfStatement::TransformChildren(const NodeTransformer &cb) @@ -49,176 +44,23 @@ void ForOfStatement::Dump(ir::AstDumper *dumper) const {{"type", "ForOfStatement"}, {"await", is_await_}, {"left", left_}, {"right", right_}, {"body", body_}}); } -void ForOfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForOfStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - - right_->Compile(pg); - - compiler::LabelTarget label_target(pg); - auto iterator_type = is_await_ ? compiler::IteratorType::ASYNC : compiler::IteratorType::SYNC; - compiler::Iterator iterator(pg, this, iterator_type); - - pg->SetLabel(this, label_target.ContinueTarget()); - - iterator.Next(); - iterator.Complete(); - pg->BranchIfTrue(this, label_target.BreakTarget()); - - iterator.Value(); - pg->StoreAccumulator(this, iterator.NextResult()); - - auto lref = compiler::JSLReference::Create(pg, left_, false); - - { - compiler::IteratorContext for_of_ctx(pg, iterator, label_target); - pg->LoadAccumulator(this, iterator.NextResult()); - lref.SetValue(); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - compiler::LoopEnvScope env_scope(pg, Scope(), {}); - body_->Compile(pg); - } - - pg->Branch(this, label_target.ContinueTarget()); - pg->SetLabel(this, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } void ForOfStatement::Compile(compiler::ETSGen *etsg) const { - compiler::LocalRegScope decl_reg_scope(etsg, Scope()->DeclScope()->InitScope()); - - checker::Type const *const expr_type = right_->TsType(); - ASSERT(expr_type->IsETSArrayType() || expr_type->IsETSStringType()); - - right_->Compile(etsg); - compiler::VReg obj_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, obj_reg); - - if (expr_type->IsETSArrayType()) { - etsg->LoadArrayLength(this, obj_reg); - } else { - etsg->LoadStringLength(this); - } - - compiler::VReg size_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, size_reg); - - compiler::LabelTarget label_target(etsg); - auto label_ctx = compiler::LabelContext(etsg, label_target); - - etsg->BranchIfFalse(this, label_target.BreakTarget()); - - compiler::VReg count_reg = etsg->AllocReg(); - etsg->MoveImmediateToRegister(this, count_reg, checker::TypeFlag::INT, static_cast(0)); - etsg->LoadAccumulatorInt(this, static_cast(0)); - - auto *const start_label = etsg->AllocLabel(); - etsg->SetLabel(this, start_label); - - auto lref = compiler::ETSLReference::Create(etsg, left_, false); - - if (right_->TsType()->IsETSArrayType()) { - etsg->LoadArrayElement(this, obj_reg); - } else { - etsg->LoadStringChar(this, obj_reg, count_reg); - } - - lref.SetValue(); - body_->Compile(etsg); - - etsg->SetLabel(this, label_target.ContinueTarget()); - - etsg->IncrementImmediateRegister(this, count_reg, checker::TypeFlag::INT, static_cast(1)); - etsg->LoadAccumulator(this, count_reg); - - etsg->JumpCompareRegister(this, size_reg, start_label); - etsg->SetLabel(this, label_target.BreakTarget()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForOfStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForOfStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -// NOLINTBEGIN(modernize-avoid-c-arrays) -static constexpr char const INVALID_SOURCE_EXPR_TYPE[] = - "'For-of' statement source expression should be either a string or an array."; -static constexpr char const INVALID_CONST_ASSIGNMENT[] = "Cannot assign a value to a constant variable "; -static constexpr char const ITERATOR_TYPE_ABSENT[] = "Cannot obtain iterator type in 'for-of' statement."; -// NOLINTEND(modernize-avoid-c-arrays) - checker::Type *ForOfStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - checker::Type *const expr_type = right_->Check(checker); - checker::Type *elem_type; - - if (expr_type == nullptr || (!expr_type->IsETSArrayType() && !expr_type->IsETSStringType())) { - checker->ThrowTypeError(INVALID_SOURCE_EXPR_TYPE, right_->Start()); - } else if (expr_type->IsETSStringType()) { - elem_type = checker->GetGlobalTypesHolder()->GlobalCharType(); - } else { - elem_type = expr_type->AsETSArrayType()->ElementType()->Instantiate(checker->Allocator(), checker->Relation(), - checker->GetGlobalTypesHolder()); - elem_type->RemoveTypeFlag(checker::TypeFlag::CONSTANT); - } - - left_->Check(checker); - checker::Type *iter_type = nullptr; - - // Just to avoid extra nested level(s) - auto const get_iter_type = [checker, elem_type](ir::VariableDeclarator *const declarator) -> checker::Type * { - if (declarator->TsType() == nullptr) { - if (auto *resolved = checker->FindVariableInFunctionScope(declarator->Id()->AsIdentifier()->Name()); - resolved != nullptr) { - resolved->SetTsType(elem_type); - return elem_type; - } - } else { - return declarator->TsType(); - } - return nullptr; - }; - - if (left_->IsIdentifier()) { - if (auto *const variable = left_->AsIdentifier()->Variable(); variable != nullptr) { - if (variable->Declaration()->IsConstDecl()) { - checker->ThrowTypeError({INVALID_CONST_ASSIGNMENT, variable->Name()}, - variable->Declaration()->Node()->Start()); - } - } - iter_type = left_->AsIdentifier()->TsType(); - } else if (left_->IsVariableDeclaration()) { - if (auto const &declarators = left_->AsVariableDeclaration()->Declarators(); !declarators.empty()) { - iter_type = get_iter_type(declarators.front()); - } - } - - if (iter_type == nullptr) { - checker->ThrowTypeError(ITERATOR_TYPE_ABSENT, left_->Start()); - } - - auto *const relation = checker->Relation(); - relation->SetFlags(checker::TypeRelationFlag::ASSIGNMENT_CONTEXT); - relation->SetNode(checker->AllocNode()); // Dummy node to avoid assertion! - - if (!relation->IsAssignableTo(elem_type, iter_type)) { - std::stringstream ss {}; - ss << "Source element type '"; - elem_type->ToString(ss); - ss << "' is not assignable to the loop iterator type '"; - iter_type->ToString(ss); - ss << "'."; - checker->ThrowTypeError(ss.str(), Start()); - } - - relation->SetNode(nullptr); - relation->SetFlags(checker::TypeRelationFlag::NONE); - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forOfStatement.h b/ets2panda/ir/statements/forOfStatement.h index 51a99573c8ca30a73b4e6e2a4bb42a9a3e27ea36..0043c78a7c6e7e4d3b3244df1bf12b8251bc3a39 100644 --- a/ets2panda/ir/statements/forOfStatement.h +++ b/ets2panda/ir/statements/forOfStatement.h @@ -82,10 +82,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *left_; diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 378dbcf36dc89fad9af9431ff94c135a8e04c791..09ccc206027021f9ecad28e5c682212f9ad238f8 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -23,8 +23,6 @@ #include "compiler/core/ETSGen.h" #include "compiler/core/dynamicContext.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" namespace panda::es2panda::ir { void ForUpdateStatement::TransformChildren(const NodeTransformer &cb) @@ -68,115 +66,23 @@ void ForUpdateStatement::Dump(ir::AstDumper *dumper) const {"body", body_}}); } -void ForUpdateStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForUpdateStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - - if (init_ != nullptr) { - ASSERT(init_->IsVariableDeclaration() || init_->IsExpression()); - init_->Compile(pg); - } - - auto *start_label = pg->AllocLabel(); - compiler::LabelTarget label_target(pg); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - compiler::LoopEnvScope env_scope(pg, label_target, Scope()); - pg->SetLabel(this, start_label); - - { - compiler::LocalRegScope reg_scope(pg, Scope()); - - if (test_ != nullptr) { - compiler::Condition::Compile(pg, test_, label_target.BreakTarget()); - } - - body_->Compile(pg); - pg->SetLabel(this, label_target.ContinueTarget()); - env_scope.CopyPetIterationCtx(); - } - - if (update_ != nullptr) { - update_->Compile(pg); - } - - pg->Branch(this, start_label); - pg->SetLabel(this, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } -void ForUpdateStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ForUpdateStatement::Compile(compiler::ETSGen *etsg) const { - compiler::LocalRegScope decl_reg_scope(etsg, Scope()->DeclScope()->InitScope()); - - if (init_ != nullptr) { - ASSERT(init_->IsVariableDeclaration() || init_->IsExpression()); - init_->Compile(etsg); - } - - auto *start_label = etsg->AllocLabel(); - compiler::LabelTarget label_target(etsg); - auto label_ctx = compiler::LabelContext(etsg, label_target); - etsg->SetLabel(this, start_label); - - { - compiler::LocalRegScope reg_scope(etsg, Scope()); - - if (test_ != nullptr) { - compiler::Condition::Compile(etsg, test_, label_target.BreakTarget()); - } - - body_->Compile(etsg); - etsg->SetLabel(this, label_target.ContinueTarget()); - } - - if (update_ != nullptr) { - update_->Compile(etsg); - } - - etsg->Branch(this, start_label); - etsg->SetLabel(this, label_target.BreakTarget()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForUpdateStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForUpdateStatement::Check(checker::TSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - if (init_ != nullptr) { - init_->Check(checker); - } - - if (test_ != nullptr) { - checker::Type *test_type = test_->Check(checker); - checker->CheckTruthinessOfType(test_type, Start()); - } - - if (update_ != nullptr) { - update_->Check(checker); - } - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ForUpdateStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ForUpdateStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - if (init_ != nullptr) { - init_->Check(checker); - } - - if (test_ != nullptr) { - checker->CheckTruthinessOfType(test_); - } - - if (update_ != nullptr) { - update_->Check(checker); - } - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forUpdateStatement.h b/ets2panda/ir/statements/forUpdateStatement.h index f79166695e3efc93d0e6fa272d6def0f8de14a68..9e39b8b0d47c7b71e5201107ac0999ceab72d3ae 100644 --- a/ets2panda/ir/statements/forUpdateStatement.h +++ b/ets2panda/ir/statements/forUpdateStatement.h @@ -87,10 +87,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *init_; diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index 578a8b1e7883d21a2eeafba08f3a00431f5c3245..a5c9e3a6148b417654cc2360ad5ad0b80fc3934d 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -19,14 +19,7 @@ #include "varbinder/scope.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsFunctionType.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/base/spreadElement.h" -#include "ir/base/decorator.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void FunctionDeclaration::TransformChildren(const NodeTransformer &cb) @@ -54,37 +47,23 @@ void FunctionDeclaration::Dump(ir::AstDumper *dumper) const {"function", func_}}); } -void FunctionDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void FunctionDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void FunctionDeclaration::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); } -checker::Type *FunctionDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void FunctionDeclaration::Compile(compiler::ETSGen *etsg) const { - if (func_->IsOverload()) { - return nullptr; - } - - const util::StringView &func_name = func_->Id()->Name(); - auto result = checker->Scope()->Find(func_name); - ASSERT(result.variable); - - checker::ScopeContext scope_ctx(checker, func_->Scope()); - - if (result.variable->TsType() == nullptr) { - checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.variable); - } - - func_->Body()->Check(checker); + etsg->GetAstCompiler()->Compile(this); +} - return nullptr; +checker::Type *FunctionDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *FunctionDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *FunctionDeclaration::Check(checker::ETSChecker *checker) { - UNREACHABLE(); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/functionDeclaration.h b/ets2panda/ir/statements/functionDeclaration.h index 0c00928b77c77239586cc8f93347ddc1cd002ad2..26bed64a5df7b0c8b4a5d95c192dfe669bbd3c75 100644 --- a/ets2panda/ir/statements/functionDeclaration.h +++ b/ets2panda/ir/statements/functionDeclaration.h @@ -51,10 +51,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ArenaVector decorators_; diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index 02d9091d064a664cdc3999ec5e4de66e24c09bef..05b30ac4114a462e1148d45887c8a54fea6758d4 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -15,12 +15,9 @@ #include "ifStatement.h" -#include "compiler/base/condition.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void IfStatement::TransformChildren(const NodeTransformer &cb) @@ -51,84 +48,23 @@ void IfStatement::Dump(ir::AstDumper *dumper) const {"alternate", AstDumper::Nullish(alternate_)}}); } -void IfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void IfStatement::Compile(compiler::PandaGen *pg) const { - auto *consequent_end = pg->AllocLabel(); - compiler::Label *statement_end = consequent_end; - - compiler::Condition::Compile(pg, test_, consequent_end); - consequent_->Compile(pg); - - if (alternate_ != nullptr) { - statement_end = pg->AllocLabel(); - pg->Branch(pg->Insns().back()->Node(), statement_end); - - pg->SetLabel(this, consequent_end); - alternate_->Compile(pg); - } - - pg->SetLabel(this, statement_end); + pg->GetAstCompiler()->Compile(this); } -void IfStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void IfStatement::Compile(compiler::ETSGen *etsg) const { - auto res = compiler::Condition::CheckConstantExpr(etsg, test_); - - if (res == compiler::Condition::Result::CONST_TRUE) { - consequent_->Compile(etsg); - return; - } - - if (res == compiler::Condition::Result::CONST_FALSE) { - if (alternate_ != nullptr) { - alternate_->Compile(etsg); - } - return; - } - - auto *consequent_end = etsg->AllocLabel(); - compiler::Label *statement_end = consequent_end; - - compiler::Condition::Compile(etsg, test_, consequent_end); - - consequent_->Compile(etsg); - - if (alternate_ != nullptr) { - statement_end = etsg->AllocLabel(); - etsg->Branch(etsg->Insns().back()->Node(), statement_end); - - etsg->SetLabel(this, consequent_end); - alternate_->Compile(etsg); - } - - etsg->SetLabel(this, statement_end); + etsg->GetAstCompiler()->Compile(this); } checker::Type *IfStatement::Check([[maybe_unused]] checker::TSChecker *checker) { - checker::Type *test_type = test_->Check(checker); - checker->CheckTruthinessOfType(test_type, Start()); - checker->CheckTestingKnownTruthyCallableOrAwaitableType(test_, test_type, consequent_); - - consequent_->Check(checker); - - if (alternate_ != nullptr) { - alternate_->Check(checker); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *IfStatement::Check([[maybe_unused]] checker::ETSChecker *checker) { - checker->CheckTruthinessOfType(test_); - - consequent_->Check(checker); - - if (alternate_ != nullptr) { - alternate_->Check(checker); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/ifStatement.h b/ets2panda/ir/statements/ifStatement.h index b2596d77bc4043995a8fca37e3c52555433dac39..e124967507389f106356031ac29b6e8827a49598 100644 --- a/ets2panda/ir/statements/ifStatement.h +++ b/ets2panda/ir/statements/ifStatement.h @@ -18,6 +18,11 @@ #include "ir/statement.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Expression; @@ -28,6 +33,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class checker::TSAnalyzer; + const Expression *Test() const { return test_; @@ -56,10 +65,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *test_; diff --git a/ets2panda/ir/statements/labelledStatement.cpp b/ets2panda/ir/statements/labelledStatement.cpp index be77a04fdcb42c826352d2467bebf1c37e54b8bc..c43d30ebf809b61b750156899434574fa474ec94 100644 --- a/ets2panda/ir/statements/labelledStatement.cpp +++ b/ets2panda/ir/statements/labelledStatement.cpp @@ -15,11 +15,9 @@ #include "labelledStatement.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/labelTarget.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void LabelledStatement::TransformChildren(const NodeTransformer &cb) @@ -39,13 +37,6 @@ void LabelledStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "LabelledStatement"}, {"label", ident_}, {"body", body_}}); } -template -void CompileImpl(const LabelledStatement *self, CodeGen *cg) -{ - compiler::LabelContext label_ctx(cg, self); - self->Body()->Compile(cg); -} - const ir::AstNode *LabelledStatement::GetReferencedStatement() const { const auto *iter = body_; @@ -67,24 +58,23 @@ const ir::AstNode *LabelledStatement::GetReferencedStatement() const } } -void LabelledStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void LabelledStatement::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } -void LabelledStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void LabelledStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *LabelledStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *LabelledStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *LabelledStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *LabelledStatement::Check(checker::ETSChecker *checker) { - body_->Check(checker); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/labelledStatement.h b/ets2panda/ir/statements/labelledStatement.h index 7a5779bd3febc3c7c20a37847e7b76a2f3191d3b..1daa79ce46f6f97127a54bf2c43e727a0bd50ab4 100644 --- a/ets2panda/ir/statements/labelledStatement.h +++ b/ets2panda/ir/statements/labelledStatement.h @@ -19,6 +19,10 @@ #include "ir/statement.h" #include "util/ustring.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Identifier; @@ -29,6 +33,9 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + const Statement *Body() const { return body_; @@ -51,10 +58,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *ident_; diff --git a/ets2panda/ir/statements/returnStatement.h b/ets2panda/ir/statements/returnStatement.h index cacaf713a77d7b33281721073dea6680f01c6cff..2e2efaf8da232a47c16cb0ef0863994fb0032546 100644 --- a/ets2panda/ir/statements/returnStatement.h +++ b/ets2panda/ir/statements/returnStatement.h @@ -61,10 +61,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *argument_ {}; diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index d3b4ab31eaa9d4bfcabffbf0afb8081c0d07ad80..3830c777c6445b27e21d45b8b7069cbdda0e9a73 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -15,8 +15,9 @@ #include "switchCaseStatement.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb) @@ -46,15 +47,23 @@ void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); } -void SwitchCaseStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *SwitchCaseStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *SwitchCaseStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *SwitchCaseStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/switchCaseStatement.h b/ets2panda/ir/statements/switchCaseStatement.h index 0ed32b85facd23ca10301372f9e6c2616dd9e74e..886520a6f719792a1a9835481d2750439f97e1ee 100644 --- a/ets2panda/ir/statements/switchCaseStatement.h +++ b/ets2panda/ir/statements/switchCaseStatement.h @@ -55,9 +55,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *test_; diff --git a/ets2panda/ir/statements/switchStatement.cpp b/ets2panda/ir/statements/switchStatement.cpp index 4bc685e3b2ba20fc3c0f25c67c3d0a36e1eb8300..c7d908bd2d4ec163e47ee390b1a21ce49cb6b864 100644 --- a/ets2panda/ir/statements/switchStatement.cpp +++ b/ets2panda/ir/statements/switchStatement.cpp @@ -21,12 +21,6 @@ #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ets/typeRelationContext.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" -#include "ir/statements/switchCaseStatement.h" namespace panda::es2panda::ir { void SwitchStatement::TransformChildren(const NodeTransformer &cb) @@ -52,132 +46,24 @@ void SwitchStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "SwitchStatement"}, {"discriminant", discriminant_}, {"cases", cases_}}); } -template -void CompileImpl(const SwitchStatement *self, CodeGen *cg) +void SwitchStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope lrs(cg, self->Scope()); - compiler::SwitchBuilder builder(cg, self); - compiler::VReg tag = cg->AllocReg(); - - builder.CompileTagOfSwitch(tag); - uint32_t default_index = 0; - - for (size_t i = 0; i < self->Cases().size(); i++) { - const auto *clause = self->Cases()[i]; - - if (clause->Test() == nullptr) { - default_index = i; - continue; - } - - builder.JumpIfCase(tag, i); - } - - if (default_index > 0) { - builder.JumpToDefault(default_index); - } else { - builder.Break(); - } - - for (size_t i = 0; i < self->Cases().size(); i++) { - builder.SetCaseTarget(i); - builder.CompileCaseStatements(i); - } + pg->GetAstCompiler()->Compile(this); } -void SwitchStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void SwitchStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, pg); + etsg->GetAstCompiler()->Compile(this); } -void SwitchStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +checker::Type *SwitchStatement::Check(checker::TSChecker *checker) { - CompileImpl(this, etsg); -} - -checker::Type *SwitchStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - checker::ScopeContext scope_ctx(checker, scope_); - - checker::Type *expr_type = discriminant_->Check(checker); - bool expr_is_literal = checker::TSChecker::IsLiteralType(expr_type); - - for (auto *it : cases_) { - if (it->Test() != nullptr) { - checker::Type *case_type = it->Test()->Check(checker); - bool case_is_literal = checker::TSChecker::IsLiteralType(case_type); - checker::Type *compared_expr_type = expr_type; - - if (!case_is_literal || !expr_is_literal) { - case_type = case_is_literal ? checker->GetBaseTypeOfLiteralType(case_type) : case_type; - compared_expr_type = checker->GetBaseTypeOfLiteralType(expr_type); - } - - if (!checker->IsTypeEqualityComparableTo(compared_expr_type, case_type) && - !checker->IsTypeComparableTo(case_type, compared_expr_type)) { - checker->ThrowTypeError({"Type ", case_type, " is not comparable to type ", compared_expr_type}, - it->Test()->Start()); - } - } - - for (auto *case_stmt : it->Consequent()) { - case_stmt->Check(checker); - } - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *SwitchStatement::Check(checker::ETSChecker *const checker) { - checker::ScopeContext scope_ctx(checker, scope_); - discriminant_->Check(checker); - checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(checker->Relation(), - checker::TypeRelationFlag::NONE); - // NOTE: check exhaustive Switch - checker->CheckSwitchDiscriminant(discriminant_); - auto *compared_expr_type = discriminant_->TsType(); - auto unboxed_disc_type = (Discriminant()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U - ? checker->ETSBuiltinTypeAsPrimitiveType(compared_expr_type) - : compared_expr_type; - - bool valid_case_type; - - for (auto *it : cases_) { - if (it->Test() != nullptr) { - auto *case_type = it->Test()->Check(checker); - valid_case_type = true; - if (case_type->HasTypeFlag(checker::TypeFlag::CHAR)) { - valid_case_type = compared_expr_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); - } else if (case_type->IsETSEnumType() && discriminant_->TsType()->IsETSEnumType()) { - valid_case_type = discriminant_->TsType()->AsETSEnumType()->IsSameEnumType(case_type->AsETSEnumType()); - } else if (case_type->IsETSStringEnumType() && discriminant_->TsType()->IsETSStringEnumType()) { - valid_case_type = - discriminant_->TsType()->AsETSStringEnumType()->IsSameEnumType(case_type->AsETSStringEnumType()); - } else { - checker::AssignmentContext( - checker->Relation(), discriminant_, case_type, unboxed_disc_type, it->Test()->Start(), - {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, - (compared_expr_type->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING - : checker::TypeRelationFlag::NO_UNBOXING) | - checker::TypeRelationFlag::NO_BOXING); - } - - if (!valid_case_type) { - checker->ThrowTypeError( - {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, - it->Test()->Start()); - } - } - - for (auto *case_stmt : it->Consequent()) { - case_stmt->Check(checker); - } - } - - checker->CheckForSameSwitchCases(&cases_); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } void SwitchStatement::SetReturnType(checker::ETSChecker *checker, checker::Type *type) diff --git a/ets2panda/ir/statements/switchStatement.h b/ets2panda/ir/statements/switchStatement.h index 70a0fab7466e5818c6861ecb5897de991b770dc2..a18b646ac3dd6d5c2197ec6512bc606e943b9f98 100644 --- a/ets2panda/ir/statements/switchStatement.h +++ b/ets2panda/ir/statements/switchStatement.h @@ -19,6 +19,11 @@ #include "varbinder/scope.h" #include "ir/statement.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Expression; class SwitchCaseStatement; @@ -31,6 +36,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class checker::TSAnalyzer; + const Expression *Discriminant() const { return discriminant_; @@ -56,10 +65,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - 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 *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::LocalScope *scope_; diff --git a/ets2panda/ir/ts/tsAnyKeyword.cpp b/ets2panda/ir/ts/tsAnyKeyword.cpp index 170d086c834e06131469232c55c42778705bb7a6..c82f0274154bba1664f4055ba3082a96504a8266 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.cpp +++ b/ets2panda/ir/ts/tsAnyKeyword.cpp @@ -15,8 +15,9 @@ #include "tsAnyKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSAnyKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSAnyKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSAnyKeyword"}}); } -void TSAnyKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSAnyKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checke return checker->GlobalAnyType(); } -checker::Type *TSAnyKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSAnyKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsAnyKeyword.h b/ets2panda/ir/ts/tsAnyKeyword.h index 5719a54c0a73cc95b06679d6190b869ba21910f6..e6f2d21e62f1ad86135cddb12d10f5ad84a36c92 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.h +++ b/ets2panda/ir/ts/tsAnyKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsBooleanKeyword.cpp b/ets2panda/ir/ts/tsBooleanKeyword.cpp index f5759ccf7f82246b477557cff9dcbc2e04714c1b..7cc031e8a91543cfcef2b0a1a680ad182a2c90bc 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.cpp +++ b/ets2panda/ir/ts/tsBooleanKeyword.cpp @@ -15,8 +15,9 @@ #include "tsBooleanKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSBooleanKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSBooleanKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSBooleanKeyword"}}); } -void TSBooleanKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSBooleanKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *ch return checker->GlobalBooleanType(); } -checker::Type *TSBooleanKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSBooleanKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsBooleanKeyword.h b/ets2panda/ir/ts/tsBooleanKeyword.h index a4936f1cecadf7e928448c41e891ebc3dcfd8eeb..c796b0e41c04d70a67e045d3b3fb3fd359fe1832 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.h +++ b/ets2panda/ir/ts/tsBooleanKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index c1bb84f23b05aace5810caed65fa8ba22a0ed144..b0f73788e5517e4142ff969721f057e92825a6e0 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -15,22 +15,11 @@ #include "tsEnumDeclaration.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "varbinder/scope.h" #include "util/helpers.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" -#include "ir/base/methodDefinition.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/templateLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/ts/tsEnumMember.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" namespace panda::es2panda::ir { void TSEnumDeclaration::TransformChildren(const NodeTransformer &cb) @@ -68,89 +57,7 @@ void TSEnumDeclaration::Dump(ir::AstDumper *dumper) const {"const", is_const_}}); } -void TSEnumDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -int32_t ToInt(double num) -{ - if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { - return static_cast(num); - } - - // NOTE: aszilagyi. Perform ECMA defined toInt conversion - - return 0; -} - -uint32_t ToUInt(double num) -{ - if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { - return static_cast(num); - } - - // NOTE: aszilagyi. Perform ECMA defined toInt conversion - - return 0; -} - -varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::Identifier *expr) -{ - if (expr->Name() == "NaN") { - return std::nan(""); - } - if (expr->Name() == "Infinity") { - return std::numeric_limits::infinity(); - } - - varbinder::Variable *enum_member = expr->AsIdentifier()->Variable(); - - if (enum_member == nullptr) { - checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, - enum_var->Declaration()->Node()->Start()); - } - - if (enum_member->IsEnumVariable()) { - varbinder::EnumVariable *expr_enum_var = enum_member->AsEnumVariable(); - if (std::holds_alternative(expr_enum_var->Value())) { - checker->ThrowTypeError( - "A member initializer in a enum declaration cannot reference members declared after it, " - "including " - "members defined in other enums.", - enum_var->Declaration()->Node()->Start()); - } - - return expr_enum_var->Value(); - } - - return false; -} - -varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::UnaryExpression *expr) -{ - varbinder::EnumMemberResult value = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->Argument()); - if (!std::holds_alternative(value)) { - return false; - } - - switch (expr->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_PLUS: { - return std::get(value); - } - case lexer::TokenType::PUNCTUATOR_MINUS: { - return -std::get(value); - } - case lexer::TokenType::PUNCTUATOR_TILDE: { - return static_cast(~ToInt(std::get(value))); // NOLINT(hicpp-signed-bitwise) - } - default: { - break; - } - } - - return false; -} - +// 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 *enum_var, ir::MemberExpression *expr) @@ -172,280 +79,23 @@ varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker return false; } -varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::BinaryExpression *expr) +void TSEnumDeclaration::Compile(compiler::PandaGen *pg) const { - varbinder::EnumMemberResult left = - TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Left()); - varbinder::EnumMemberResult right = - TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Right()); - if (std::holds_alternative(left) && std::holds_alternative(right)) { - switch (expr->AsBinaryExpression()->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { - return static_cast(ToUInt(std::get(left)) | ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_BITWISE_AND: { - return static_cast(ToUInt(std::get(left)) & ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: { - return static_cast(ToUInt(std::get(left)) ^ ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) - return static_cast(ToInt(std::get(left)) << ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) - return static_cast(ToInt(std::get(left)) >> ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: { - return static_cast(ToUInt(std::get(left)) >> ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_PLUS: { - return std::get(left) + std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MINUS: { - return std::get(left) - std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MULTIPLY: { - return std::get(left) * std::get(right); - } - case lexer::TokenType::PUNCTUATOR_DIVIDE: { - return std::get(left) / std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MOD: { - return std::fmod(std::get(left), std::get(right)); - } - case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: { - return std::pow(std::get(left), std::get(right)); - } - default: { - break; - } - } - - return false; - } - - if (std::holds_alternative(left) && std::holds_alternative(right) && - expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { - std::stringstream ss; - ss << std::get(left) << std::get(right); - - util::UString res(ss.str(), checker->Allocator()); - return res.View(); - } - - return false; + pg->GetAstCompiler()->Compile(this); } -varbinder::EnumMemberResult TSEnumDeclaration::EvaluateEnumMember(checker::TSChecker *checker, - varbinder::EnumVariable *enum_var, - const ir::AstNode *expr) +void TSEnumDeclaration::Compile(compiler::ETSGen *etsg) const { - switch (expr->Type()) { - case ir::AstNodeType::UNARY_EXPRESSION: { - return EvaluateUnaryExpression(checker, enum_var, expr->AsUnaryExpression()); - } - case ir::AstNodeType::BINARY_EXPRESSION: { - return EvaluateBinaryExpression(checker, enum_var, expr->AsBinaryExpression()); - } - case ir::AstNodeType::NUMBER_LITERAL: { - return expr->AsNumberLiteral()->Number().GetDouble(); - } - case ir::AstNodeType::STRING_LITERAL: { - return expr->AsStringLiteral()->Str(); - } - case ir::AstNodeType::IDENTIFIER: { - return EvaluateIdentifier(checker, enum_var, expr->AsIdentifier()); - } - case ir::AstNodeType::MEMBER_EXPRESSION: { - return EvaluateEnumMember(checker, enum_var, expr->AsMemberExpression()); - } - default: - break; - } - - return false; -} - -bool IsComputedEnumMember(const ir::Expression *init) -{ - if (init->IsLiteral()) { - return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); - } - - if (init->IsTemplateLiteral()) { - return !init->AsTemplateLiteral()->Quasis().empty(); - } - - return true; -} - -void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVariable *variable) -{ - variable->SetTsType(checker->GlobalNumberType()); - - util::StringView member_str = util::Helpers::ToStringView(checker->Allocator(), number); - - varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); - varbinder::Variable *res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); - varbinder::EnumVariable *enum_var = nullptr; - - if (res == nullptr) { - auto *decl = checker->Allocator()->New(member_str); - decl->BindNode(variable->Declaration()->Node()); - enum_scope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); - res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); - ASSERT(res && res->IsEnumVariable()); - enum_var = res->AsEnumVariable(); - enum_var->AsEnumVariable()->SetBackReference(); - enum_var->SetTsType(checker->GlobalStringType()); - } else { - ASSERT(res->IsEnumVariable()); - enum_var = res->AsEnumVariable(); - auto *decl = checker->Allocator()->New(member_str); - decl->BindNode(variable->Declaration()->Node()); - enum_var->ResetDecl(decl); - } - - enum_var->SetValue(variable->Declaration()->Name()); -} - -void InferEnumVariableType(checker::TSChecker *checker, varbinder::EnumVariable *variable, double *value, - bool *init_next, bool *is_literal_enum, bool is_const_enum, - const ir::Expression *computed_expr) -{ - const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); - - if (init == nullptr && *init_next) { - checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Start()); - } - - if (init == nullptr && !*init_next) { - variable->SetValue(++(*value)); - AddEnumValueDeclaration(checker, *value, variable); - return; - } - - ASSERT(init); - - if (IsComputedEnumMember(init)) { - if (*is_literal_enum) { - checker->ThrowTypeError("Computed values are not permitted in an enum with string valued members.", - init->Start()); - } - - computed_expr = init; - } - - varbinder::EnumMemberResult res = TSEnumDeclaration::EvaluateEnumMember(checker, variable, init); - if (std::holds_alternative(res)) { - if (computed_expr != nullptr) { - checker->ThrowTypeError("Computed values are not permitted in an enum with string valued members.", - computed_expr->Start()); - } - - *is_literal_enum = true; - variable->SetTsType(checker->GlobalStringType()); - *init_next = true; - return; - } - - if (std::holds_alternative(res)) { - if (is_const_enum) { - checker->ThrowTypeError( - "const enum member initializers can only contain literal values and other computed enum " - "values.", - init->Start()); - } - - *init_next = true; - return; - } - - ASSERT(std::holds_alternative(res)); - variable->SetValue(res); - - *value = std::get(res); - if (is_const_enum) { - if (std::isnan(*value)) { - checker->ThrowTypeError("'const' enum member initializer was evaluated to disallowed value 'NaN'.", - init->Start()); - } - - if (std::isinf(*value)) { - checker->ThrowTypeError("'const' enum member initializer was evaluated to a non-finite value.", - init->Start()); - } - } - - *init_next = false; - AddEnumValueDeclaration(checker, *value, variable); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *TSEnumDeclaration::InferType(checker::TSChecker *checker, bool is_const) const +checker::Type *TSEnumDeclaration::Check(checker::TSChecker *checker) { - double value = -1.0; - - varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); - - bool init_next = false; - bool is_literal_enum = false; - const ir::Expression *computed_expr = nullptr; - size_t locals_size = enum_scope->Decls().size(); - - for (size_t i = 0; i < locals_size; i++) { - const util::StringView ¤t_name = enum_scope->Decls()[i]->Name(); - varbinder::Variable *current_var = - enum_scope->FindLocal(current_name, varbinder::ResolveBindingOptions::BINDINGS); - ASSERT(current_var && current_var->IsEnumVariable()); - InferEnumVariableType(checker, current_var->AsEnumVariable(), &value, &init_next, &is_literal_enum, is_const, - computed_expr); - } - - checker::Type *enum_type = checker->Allocator()->New( - key_->Name(), checker->Scope(), - is_literal_enum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL - : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); - - return enum_type; -} - -checker::Type *TSEnumDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - varbinder::Variable *enum_var = key_->Variable(); - ASSERT(enum_var); - - if (enum_var->TsType() == nullptr) { - checker::ScopeContext scope_ctx(checker, scope_); - checker::Type *enum_type = InferType(checker, is_const_); - enum_type->SetVariable(enum_var); - enum_var->SetTsType(enum_type); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSEnumDeclaration::Check(checker::ETSChecker *const checker) { - varbinder::Variable *enum_var = key_->Variable(); - ASSERT(enum_var != nullptr); - - if (enum_var->TsType() == nullptr) { - checker::Type *ets_enum_type; - if (auto *const item_init = members_.front()->AsTSEnumMember()->Init(); item_init->IsNumberLiteral()) { - ets_enum_type = checker->CreateETSEnumType(this); - } else if (item_init->IsStringLiteral()) { - ets_enum_type = checker->CreateETSStringEnumType(this); - } else { - checker->ThrowTypeError("Invalid enumeration value type.", Start()); - } - SetTsType(ets_enum_type); - ets_enum_type->SetVariable(enum_var); - enum_var->SetTsType(ets_enum_type); - } else if (TsType() == nullptr) { - SetTsType(enum_var->TsType()); - } - - return TsType(); + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumDeclaration.h b/ets2panda/ir/ts/tsEnumDeclaration.h index 72a6d0870e70927c208743b2179173baf897b3e6..d6d318a62bd846c8181de21aeb724de6def6f45c 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.h +++ b/ets2panda/ir/ts/tsEnumDeclaration.h @@ -101,14 +101,13 @@ public: static varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, const ir::AstNode *expr); - checker::Type *InferType(checker::TSChecker *checker, bool is_const) const; - void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::LocalScope *scope_; diff --git a/ets2panda/ir/ts/tsEnumMember.cpp b/ets2panda/ir/ts/tsEnumMember.cpp index d0cb459a00ee3e5d787bc70aacf7b6c7f14c48cc..adb6873dd8b5ffb09e1c3451e10afe28b93c95ba 100644 --- a/ets2panda/ir/ts/tsEnumMember.cpp +++ b/ets2panda/ir/ts/tsEnumMember.cpp @@ -15,9 +15,9 @@ #include "tsEnumMember.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSEnumMember::TransformChildren(const NodeTransformer &cb) @@ -49,15 +49,23 @@ util::StringView TSEnumMember::Name() const return key_->AsIdentifier()->Name(); } -void TSEnumMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSEnumMember::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSEnumMember::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSEnumMember::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumMember.h b/ets2panda/ir/ts/tsEnumMember.h index 52918aee6035283dfd9502090324f2035ba06f66..c169a782db2bbe14f6bcd09d903471fd837df8a1 100644 --- a/ets2panda/ir/ts/tsEnumMember.h +++ b/ets2panda/ir/ts/tsEnumMember.h @@ -43,9 +43,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *key_; diff --git a/ets2panda/ir/ts/tsExternalModuleReference.cpp b/ets2panda/ir/ts/tsExternalModuleReference.cpp index 5e9aa155d8e9903772b48181c504ae15de8bb758..601c235a021631515e75a58bcc15a6f566762db8 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.cpp +++ b/ets2panda/ir/ts/tsExternalModuleReference.cpp @@ -15,7 +15,9 @@ #include "tsExternalModuleReference.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSExternalModuleReference::TransformChildren(const NodeTransformer &cb) @@ -33,15 +35,23 @@ void TSExternalModuleReference::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSExternalModuleReference"}, {"expression", expr_}}); } -void TSExternalModuleReference::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSExternalModuleReference::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSExternalModuleReference::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSExternalModuleReference::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsExternalModuleReference.h b/ets2panda/ir/ts/tsExternalModuleReference.h index 2ab4685a25524fa460de66ddb231c6ffd88a94bd..00ec35da541200445121e4b99bbaf29834a6ec67 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.h +++ b/ets2panda/ir/ts/tsExternalModuleReference.h @@ -34,9 +34,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expr_; diff --git a/ets2panda/ir/ts/tsNumberKeyword.cpp b/ets2panda/ir/ts/tsNumberKeyword.cpp index 294e15b549f5c62458c1e8322542441823f881ad..13aca3172f286fb496bf7b9cbaecaacd2f6cdb43 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.cpp +++ b/ets2panda/ir/ts/tsNumberKeyword.cpp @@ -15,8 +15,9 @@ #include "tsNumberKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSNumberKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSNumberKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSNumberKeyword"}}); } -void TSNumberKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSNumberKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *che return checker->GlobalNumberType(); } -checker::Type *TSNumberKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSNumberKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsNumberKeyword.h b/ets2panda/ir/ts/tsNumberKeyword.h index f9012741687d4613e41392c7af9b026847ad9e0a..5debdb8a4a114c28859cc24b147b06321b57eeb1 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.h +++ b/ets2panda/ir/ts/tsNumberKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsObjectKeyword.cpp b/ets2panda/ir/ts/tsObjectKeyword.cpp index eb471e9d7b1502b6ba6895968a7fc19c2d77e7c8..da0fea006153b8aca88c0a39aecb43b9f7db034f 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.cpp +++ b/ets2panda/ir/ts/tsObjectKeyword.cpp @@ -15,8 +15,9 @@ #include "tsObjectKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSObjectKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSObjectKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSObjectKeyword"}}); } -void TSObjectKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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 nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -41,6 +50,6 @@ checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *che checker::Type *TSObjectKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsObjectKeyword.h b/ets2panda/ir/ts/tsObjectKeyword.h index d06a36dde29392f550497276e762ee1a3272e4aa..ecbb83c4518d66c430daa21e2884b04c653c30f8 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.h +++ b/ets2panda/ir/ts/tsObjectKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsStringKeyword.cpp b/ets2panda/ir/ts/tsStringKeyword.cpp index 3374b8bb51d9eccd2a48ca08990eab939e65a420..11caf9ca5a439ab380ae10e48c43135243033167 100644 --- a/ets2panda/ir/ts/tsStringKeyword.cpp +++ b/ets2panda/ir/ts/tsStringKeyword.cpp @@ -15,8 +15,9 @@ #include "tsStringKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSStringKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSStringKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSStringKeyword"}}); } -void TSStringKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSStringKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *che return checker->GlobalStringType(); } -checker::Type *TSStringKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSStringKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsStringKeyword.h b/ets2panda/ir/ts/tsStringKeyword.h index 14b8cf390d545b080368bce3979fa6622077265e..611c2a70f90643775d63d26876d10b9c4cb40998 100644 --- a/ets2panda/ir/ts/tsStringKeyword.h +++ b/ets2panda/ir/ts/tsStringKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index 614e9798df1fab0d259a248af6eb144a817379d9..f9906355134f706cc9f02bc68efa1eebce3c9ef6 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -27,12 +27,13 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag : Expression(static_cast(other)), params_(allocator->Adapter()) { for (auto *param : other.params_) { - params_.emplace_back(param->Clone(allocator, this)->AsTypeNode()); + params_.emplace_back(param->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index 727e08911e51a4b2b7e2b7195e298efe543c6f08..09db9a4b1df80ee993004e47adeab28c5347e851 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -43,7 +43,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.cpp b/ets2panda/ir/ts/tsUndefinedKeyword.cpp index 6d889996c82dab60fced9a83fd9230db62ce8c4d..ba59f6f222104216981d9d0947bfec593be26db7 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/ets2panda/ir/ts/tsUndefinedKeyword.cpp @@ -15,8 +15,9 @@ #include "tsUndefinedKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSUndefinedKeyword"}}); } -void TSUndefinedKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSUndefinedKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker * return checker->GlobalUndefinedType(); } -checker::Type *TSUndefinedKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSUndefinedKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.h b/ets2panda/ir/ts/tsUndefinedKeyword.h index 1dcc42d743a2803f468a43a8c3b008a09752eca3..1bbf96fcfdea6d51a220218457fc74afa8ab5703 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.h +++ b/ets2panda/ir/ts/tsUndefinedKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnknownKeyword.cpp b/ets2panda/ir/ts/tsUnknownKeyword.cpp index 3799e4b62b1b288094101bfeda5d8b18558db5b7..d8e35bf46a3b69854a8209cb66f10adb66a48b21 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.cpp +++ b/ets2panda/ir/ts/tsUnknownKeyword.cpp @@ -15,8 +15,9 @@ #include "tsUnknownKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSUnknownKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSUnknownKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSUnknownKeyword"}}); } -void TSUnknownKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSUnknownKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *ch return checker->GlobalUnknownType(); } -checker::Type *TSUnknownKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSUnknownKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnknownKeyword.h b/ets2panda/ir/ts/tsUnknownKeyword.h index 0e912ca124800fd68f94ae4bf3a615cfadfdaec2..642f239a53d7f929e544c44b1b2e63a0c4cd5299 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.h +++ b/ets2panda/ir/ts/tsUnknownKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsVoidKeyword.cpp b/ets2panda/ir/ts/tsVoidKeyword.cpp index 43417ff96ac18a52f86f0ea68ce7fded722ac217..47502deb375b1b5088bd99d2837c606d2f93b6d4 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.cpp +++ b/ets2panda/ir/ts/tsVoidKeyword.cpp @@ -15,8 +15,9 @@ #include "tsVoidKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSVoidKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSVoidKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSVoidKeyword"}}); } -void TSVoidKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +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([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSVoidKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *check return checker->GlobalVoidType(); } -checker::Type *TSVoidKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSVoidKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsVoidKeyword.h b/ets2panda/ir/ts/tsVoidKeyword.h index 6a1d20d35d712a7631f8c1e483d6ae377c68048d..d1869ab617e16b767aaf296e818456b3d6d91067 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.h +++ b/ets2panda/ir/ts/tsVoidKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + 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::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index 991f0a7d9549324e03af7194c032c78265f17765..be22e10ee704a4131e7b904c37bcbe46245b34a3 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -14,13 +14,14 @@ */ #include "typeNode.h" +#include "astNode.h" #include "opaqueTypeNode.h" #include "es2panda.h" namespace panda::es2panda::ir { // NOLINTNEXTLINE(google-default-arguments) -Expression *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { if (auto *const clone = allocator->New(type); clone != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index c92340a3a1fb3512ce77ef4a6f345f4a901154e4..7933f9b5e407daaa0898bc2b39b20c5107b542c4 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {} diff --git a/ets2panda/lexer/lexer.cpp b/ets2panda/lexer/lexer.cpp index 0b26a83a572ab5f91fd822575265418f1b88cc2b..dba2f94d63d0f02821d977264f6a2c63c89ba75a 100644 --- a/ets2panda/lexer/lexer.cpp +++ b/ets2panda/lexer/lexer.cpp @@ -779,6 +779,16 @@ void Lexer::ScanAmpersandPunctuator() } } +void Lexer::ScanAtPunctuator() +{ + GetToken().type_ = TokenType::PUNCTUATOR_AT; + + if (Iterator().Peek() == LEX_CHAR_AT) { + GetToken().type_ = TokenType::PUNCTUATOR_FORMAT; + Iterator().Forward(1U); + } +} + void Lexer::ScanVLinePunctuator() { GetToken().type_ = TokenType::PUNCTUATOR_BITWISE_OR; @@ -1360,7 +1370,7 @@ void Lexer::NextToken(Keywords *kws) break; } case LEX_CHAR_AT: { - GetToken().type_ = TokenType::PUNCTUATOR_AT; + ScanAtPunctuator(); break; } case LEX_CHAR_DOLLAR_SIGN: { diff --git a/ets2panda/lexer/lexer.h b/ets2panda/lexer/lexer.h index 2a36059a2b794a8adc91a9e1157818af3cdaa925..4f8cd73a1c419a0fb8f80c11bb5d906afc8a9bbb 100644 --- a/ets2panda/lexer/lexer.h +++ b/ets2panda/lexer/lexer.h @@ -230,6 +230,7 @@ protected: void ScanDotPunctuator(); void ScanColonPunctuator(); virtual bool ScanDollarPunctuator(); + void ScanAtPunctuator(); virtual void SkipMultiLineComment(); virtual void ScanHashMark(); diff --git a/ets2panda/lexer/token/token.cpp b/ets2panda/lexer/token/token.cpp index a6bb09dfb07aecbb655dc95c9f7f5ed36c03021f..885adaa546e630541797b437148728de124496b7 100644 --- a/ets2panda/lexer/token/token.cpp +++ b/ets2panda/lexer/token/token.cpp @@ -226,6 +226,8 @@ const char *TokenToString(TokenType type) // NOLINT(readability-function-size) return "?."; case TokenType::PUNCTUATOR_AT: return "@"; + case TokenType::PUNCTUATOR_FORMAT: + return "@@"; case TokenType::PUNCTUATOR_RIGHT_PARENTHESIS: return ")"; case TokenType::PUNCTUATOR_LEFT_PARENTHESIS: diff --git a/ets2panda/lexer/token/tokenType.h b/ets2panda/lexer/token/tokenType.h index 7872cd90d76aa93d05d2378891c5308c25306e53..5f6b4df393764e869320bfe0d29b3622c13ee530 100644 --- a/ets2panda/lexer/token/tokenType.h +++ b/ets2panda/lexer/token/tokenType.h @@ -94,6 +94,7 @@ enum class TokenType { PUNCTUATOR_BACK_TICK, PUNCTUATOR_HASH_MARK, PUNCTUATOR_AT, + PUNCTUATOR_FORMAT, PUNCTUATOR_DOLLAR_DOLLAR, /* contextual keywords */ diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e86b81930b53cae8faaf2f62b2477e5529ca52c7..1100af3be59744c72fa13015407b4cf5ab5d647c 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -14,6 +14,7 @@ */ #include "ETSparser.h" +#include #include "parser/parserFlags.h" #include "util/arktsconfig.h" @@ -46,6 +47,7 @@ #include "ir/expressions/assignmentExpression.h" #include "ir/expressions/sequenceExpression.h" #include "ir/expressions/callExpression.h" +#include "ir/expressions/blockExpression.h" #include "ir/expressions/thisExpression.h" #include "ir/expressions/superExpression.h" #include "ir/expressions/newExpression.h" @@ -669,7 +671,7 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector::Enter( VarBinder(), GetProgram()->GlobalClassScope()); - ParseClassFieldDefiniton(member_name, member_modifiers, &global_properties, init_function); + ParseClassFieldDefiniton(member_name, member_modifiers, &global_properties, init_function, &start_loc); break; } case lexer::TokenType::KEYW_ASYNC: @@ -1253,8 +1255,11 @@ ir::ModifierFlags ETSParser::ParseClassMethodModifiers(bool seen_static) // NOLINTNEXTLINE(google-default-arguments) void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *init_function) + ArenaVector *declarations, ir::ScriptFunction *init_function, + lexer::SourcePosition *let_loc) { + lexer::SourcePosition start_loc = let_loc != nullptr ? *let_loc : Lexer()->GetToken().Start(); + lexer::SourcePosition end_loc = start_loc; ir::TypeNode *type_annotation = nullptr; TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1283,9 +1288,16 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie auto *assignment_expression = AllocNode(ident, initializer, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + end_loc = initializer->End(); + assignment_expression->SetRange({field_name->Start(), end_loc}); assignment_expression->SetParent(func_body); - func_body->AsBlockStatement()->Statements().emplace_back( - AllocNode(assignment_expression)); + + auto expression_statement = AllocNode(assignment_expression); + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + end_loc = Lexer()->GetToken().End(); + } + expression_statement->SetRange({start_loc, end_loc}); + func_body->AsBlockStatement()->Statements().emplace_back(expression_statement); if (type_annotation != nullptr && !type_annotation->IsETSFunctionType()) { initializer = nullptr; @@ -1300,6 +1312,13 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie } auto *field = AllocNode(field_name, initializer, type_annotation, modifiers, Allocator(), false); + start_loc = field_name->Start(); + if (initializer != nullptr) { + end_loc = initializer->End(); + } else { + end_loc = type_annotation != nullptr ? type_annotation->End() : field_name->End(); + } + field->SetRange({start_loc, end_loc}); if ((modifiers & ir::ModifierFlags::CONST) != 0) { ASSERT(VarBinder()->GetScope()->Parent() != nullptr); @@ -2236,7 +2255,7 @@ std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const fun void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node) { if (method->IsConstructor()) { - return; // TODO(szd): Fix constructors not working with default params + return; // NOTE(szd): Fix constructors not working with default params } const auto *const function = method->Function(); @@ -2616,10 +2635,10 @@ ir::TypeNode *ETSParser::ParseFunctionType() return func_type; } -ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *options) +// Just to reduce the size of ParseTypeAnnotation(...) method +std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options) { ir::TypeNode *type_annotation = nullptr; - bool throw_error = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; switch (Lexer()->GetToken().Type()) { case lexer::TokenType::LITERAL_IDENT: { @@ -2632,7 +2651,7 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio if (((*options) & TypeAnnotationParsingOptions::POTENTIAL_CLASS_LITERAL) != 0 && (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword())) { - return type_annotation; + return std::make_pair(type_annotation, false); } break; } @@ -2678,14 +2697,14 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio Lexer()->Lookahead() == lexer::LEX_CHAR_COLON)) { type_annotation = ParseFunctionType(); type_annotation->SetStart(start_loc); - return type_annotation; + return std::make_pair(type_annotation, false); } type_annotation = ParseTypeAnnotation(options); type_annotation->SetStart(start_loc); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { - if (throw_error) { + if (((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); } @@ -2697,25 +2716,44 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio break; } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + type_annotation = ParseTypeFormatPlaceholder(); + break; + } default: { break; } } + return std::make_pair(type_annotation, true); +} + +ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *options) +{ + bool const throw_error = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; + + auto [type_annotation, need_further_processing] = GetTypeAnnotationFromToken(options); + if (type_annotation == nullptr) { if (throw_error) { ThrowSyntaxError("Invalid Type"); } - return nullptr; } + if (!need_further_processing) { + return type_annotation; + } + const lexer::SourcePosition &start_pos = Lexer()->GetToken().Start(); if (((*options) & TypeAnnotationParsingOptions::ALLOW_INTERSECTION) != 0 && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_AND) { if (type_annotation->IsETSPrimitiveType()) { - ThrowSyntaxError("Invalid intersection type."); + if (throw_error) { + ThrowSyntaxError("Invalid intersection type."); + } + return nullptr; } return ParseIntersectionType(type_annotation); @@ -2728,7 +2766,6 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio if (throw_error) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET); } - return nullptr; } @@ -3653,6 +3690,9 @@ ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) case lexer::TokenType::KEYW_TYPE: { ThrowSyntaxError("Type alias is allowed only as top-level declaration"); } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + return ParseExpressionFormatPlaceholder(); + } default: { return ParseDefaultPrimaryExpression(flags); } @@ -3847,6 +3887,9 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primary_ex continue; } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + ThrowUnexpectedToken(lexer::TokenType::PUNCTUATOR_FORMAT); + } default: { break; } @@ -3861,11 +3904,12 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primary_ex ir::Expression *ETSParser::ParsePotentialAsExpression(ir::Expression *primary_expr) { ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::KEYW_AS); + Lexer()->NextToken(); TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::ALLOW_INTERSECTION; - Lexer()->NextToken(); ir::TypeNode *type = ParseTypeAnnotation(&options); + auto *as_expression = AllocNode(primary_expr, type, false); as_expression->SetRange(primary_expr->Range()); return as_expression; @@ -4119,23 +4163,16 @@ ir::TSEnumDeclaration *ETSParser::ParseEnumMembers(ir::Identifier *const key, co void ETSParser::ParseNumberEnum(ArenaVector &members) { - std::unordered_set enum_values {}; checker::ETSEnumType::ValueType current_value {}; // Lambda to parse enum member (maybe with initializer) - auto const parse_member = [this, &members, &enum_values, ¤t_value]() { + auto const parse_member = [this, &members, ¤t_value]() { auto *const ident = ExpectIdentifier(); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); var->SetScope(VarBinder()->GetScope()); var->AddFlag(varbinder::VariableFlags::STATIC); ident->SetVariable(var); - auto const add_value = [this, &enum_values](checker::ETSEnumType::ValueType const new_value) { - if (auto const rc = enum_values.emplace(new_value); !rc.second) { - ThrowSyntaxError(DUPLICATE_ENUM_VALUE + std::to_string(new_value)); - } - }; - ir::NumberLiteral *ordinal; lexer::SourcePosition end_loc; @@ -4164,14 +4201,12 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) } current_value = ordinal->Number().GetValue(); - add_value(current_value); end_loc = ordinal->End(); } else { // Default enumeration constant value. Equal to 0 for the first item and = previous_value + 1 for all the // others. - add_value(current_value); ordinal = AllocNode(lexer::Number(current_value)); end_loc = ident->End(); @@ -4204,10 +4239,8 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) void ETSParser::ParseStringEnum(ArenaVector &members) { - std::unordered_set enum_values {}; - // Lambda to parse enum member (maybe with initializer) - auto const parse_member = [this, &members, &enum_values]() { + auto const parse_member = [this, &members]() { auto *const ident = ExpectIdentifier(); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); var->SetScope(VarBinder()->GetScope()); @@ -4225,9 +4258,6 @@ void ETSParser::ParseStringEnum(ArenaVector &members) } item_value = ParseStringLiteral(); - if (auto const rc = enum_values.emplace(item_value->Str()); !rc.second) { - ThrowSyntaxError(DUPLICATE_ENUM_VALUE + '\'' + std::string {item_value->Str()} + '\''); - } } else { // Default item value is not allowed for string type enumerations! ThrowSyntaxError("All items of string-type enumeration should be explicitly initialized."); @@ -4468,6 +4498,148 @@ void ETSParser::CheckDeclare() // Methods to create AST node(s) from the specified string (part of valid ETS-code!) //================================================================================================// +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_NUMBER_NODE[] = "Invalid node number in format expression."; +static constexpr char const INVALID_FORMAT_NODE[] = "Invalid node type in format expression."; +static constexpr char const INSERT_NODE_ABSENT[] = "There is no any node to insert at the placeholder position."; +static constexpr char const INVALID_INSERT_NODE[] = + "Inserting node type differs from that required by format specification."; +// NOLINTEND(modernize-avoid-c-arrays) + +ParserImpl::NodeFormatType ETSParser::GetFormatPlaceholderIdent() const +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT); + Lexer()->NextToken(); + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT); + + char const *const ident_data = Lexer()->GetToken().Ident().Bytes(); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic, cert-err34-c) + auto ident_number = std::atoi(ident_data + 1U); + if (ident_number <= 0) { + ThrowSyntaxError(INVALID_NUMBER_NODE, Lexer()->GetToken().Start()); + } + + return {*ident_data, static_cast().second)>(ident_number - 1)}; +} + +ir::AstNode *ETSParser::ParseFormatPlaceholder() +{ + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (auto node_format = GetFormatPlaceholderIdent(); node_format.first == EXPRESSION_FORMAT_NODE) { + return ParseExpressionFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == IDENTIFIER_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseIdentifierFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == TYPE_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseTypeFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == STATEMENT_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseStatementFormatPlaceholder(std::make_optional(node_format)); + } + + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); +} + +ir::Expression *ETSParser::ParseExpressionFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first == TYPE_FORMAT_NODE) { + return ParseTypeFormatPlaceholder(std::move(node_format)); + } else if (node_format->first == IDENTIFIER_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseIdentifierFormatPlaceholder(std::move(node_format)); + } else if (node_format->first != EXPRESSION_FORMAT_NODE) { // NOLINT(readability-else-after-return) + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_expression = inserting_node->AsExpression(); + Lexer()->NextToken(); + return insert_expression; +} + +ir::TypeNode *ETSParser::ParseTypeFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != TYPE_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression() || !inserting_node->AsExpression()->IsTypeNode()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_type = inserting_node->AsExpression()->AsTypeNode(); + Lexer()->NextToken(); + return insert_type; +} + +// NOLINTNEXTLINE(google-default-arguments) +ir::Identifier *ETSParser::ParseIdentifierFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != IDENTIFIER_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression() || + !inserting_node->AsExpression()->IsIdentifier()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_identifier = inserting_node->AsExpression()->AsIdentifier(); + Lexer()->NextToken(); + return insert_identifier; +} + +ir::Statement *ETSParser::ParseStatementFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != STATEMENT_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsStatement()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_statement = inserting_node->AsStatement(); + Lexer()->NextToken(); + return insert_statement; +} + ir::Statement *ETSParser::CreateStatement(std::string_view const source_code, std::string_view const file_name) { util::UString source {source_code, Allocator()}; @@ -4498,6 +4670,16 @@ ir::Statement *ETSParser::CreateStatement(std::string_view const source_code, st return block_stmt; } +ir::Statement *ETSParser::CreateFormattedStatement(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + inserting_nodes_.swap(inserting_nodes); + auto const statement = CreateStatement(source_code, file_name); + inserting_nodes_.swap(inserting_nodes); + return statement; +} + ArenaVector ETSParser::CreateStatements(std::string_view const source_code, std::string_view const file_name) { @@ -4509,6 +4691,16 @@ ArenaVector ETSParser::CreateStatements(std::string_view const return ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); } +ArenaVector ETSParser::CreateFormattedStatements(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + inserting_nodes_.swap(inserting_nodes); + auto statements = CreateStatements(source_code, file_name); + inserting_nodes_.swap(inserting_nodes); + return statements; +} + ir::MethodDefinition *ETSParser::CreateMethodDefinition(ir::ModifierFlags modifiers, std::string_view const source_code, std::string_view const file_name) { @@ -4535,15 +4727,38 @@ ir::MethodDefinition *ETSParser::CreateMethodDefinition(ir::ModifierFlags modifi return method_definition; } -ir::Expression *ETSParser::CreateExpression(ExpressionParseFlags const flags, std::string_view const source_code, +ir::Expression *ETSParser::CreateExpression(std::string_view const source_code, ExpressionParseFlags const flags, std::string_view const file_name) { util::UString source {source_code, Allocator()}; auto const isp = InnerSourceParser(this); auto const lexer = InitLexer({file_name, source.View().Utf8()}); + lexer::SourcePosition const start_loc = lexer->GetToken().Start(); lexer->NextToken(); - return ParseExpression(flags); + + ir::Expression *return_expression = ParseExpression(flags); + return_expression->SetRange({start_loc, lexer->GetToken().End()}); + + return return_expression; +} + +ir::Expression *ETSParser::CreateFormattedExpression(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + ir::Expression *return_expression; + inserting_nodes_.swap(inserting_nodes); + + if (auto statements = CreateStatements(source_code, file_name); + statements.size() == 1U && statements.back()->IsExpressionStatement()) { + return_expression = statements.back()->AsExpressionStatement()->GetExpression(); + } else { + return_expression = AllocNode(std::move(statements)); + } + + inserting_nodes_.swap(inserting_nodes); + return return_expression; } ir::TypeNode *ETSParser::CreateTypeAnnotation(TypeAnnotationParsingOptions *options, std::string_view const source_code, diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index ba8e78e3598ff4a5968eafceb990cbf6237273d0..d1eb419aa82dbb2f77527a06167cf6a8af77ef07 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_PARSER_CORE_ETS_PARSER_H #define ES2PANDA_PARSER_CORE_ETS_PARSER_H +#include #include "util/arktsconfig.h" #include "TypedParser.h" #include "ir/ets/etsParameterExpression.h" @@ -27,6 +28,16 @@ enum class PrimitiveType; } // namespace panda::es2panda::ir namespace panda::es2panda::parser { + +// NOLINTBEGIN(modernize-avoid-c-arrays) +inline constexpr char const FORMAT_SIGNATURE = '@'; +inline constexpr char const TYPE_FORMAT_NODE = 'T'; +inline constexpr char const STATEMENT_FORMAT_NODE = 'S'; +inline constexpr char const EXPRESSION_FORMAT_NODE = 'E'; +inline constexpr char const IDENTIFIER_FORMAT_NODE = 'I'; +inline constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; +// NOLINTEND(modernize-avoid-c-arrays) + class ETSParser final : public TypedParser { public: ETSParser(Program *program, const CompilerOptions &options, ParserStatus status = ParserStatus::NO_OPTS) @@ -34,14 +45,53 @@ public: { } + ETSParser() = delete; NO_COPY_SEMANTIC(ETSParser); NO_MOVE_SEMANTIC(ETSParser); - ~ETSParser() = default; - ir::Expression *CreateExpression(ExpressionParseFlags flags, std::string_view source_code, + [[nodiscard]] bool IsETSParser() const noexcept override + { + return true; + } + + // Methods to create AST node(s) from the specified string (part of valid ETS-code!) + // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, + // and correct parent and, probably, variable set to the node(s) after obtaining + + ir::Expression *CreateExpression(std::string_view source_code, + ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS, std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::Expression *CreateFormattedExpression(std::string_view source_code, std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ir::Expression *CreateFormattedExpression(std::string_view const source_code, std::string_view const file_name, + Args &&...args) + { + std::vector inserting_nodes {}; + inserting_nodes.reserve(sizeof...(Args)); + (inserting_nodes.emplace_back(std::forward(args)), ...); + return CreateFormattedExpression(source_code, inserting_nodes, file_name); + } + + ArenaVector CreateStatements(std::string_view source_code, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + ArenaVector CreateFormattedStatements(std::string_view source_code, + std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ArenaVector CreateFormattedStatements(std::string_view const source_code, + std::string_view const file_name, Args &&...args) + { + std::vector inserting_nodes {}; + (inserting_nodes.emplace(std::forward(args)), ...); + return CreateFormattedStatements(source_code, inserting_nodes, file_name); + } + private: struct ImportData { Language lang; @@ -103,8 +153,8 @@ private: // NOLINTNEXTLINE(google-default-arguments) void ParseClassFieldDefiniton(ir::Identifier *field_name, ir::ModifierFlags modifiers, - ArenaVector *declarations, - ir::ScriptFunction *init_function = nullptr); + ArenaVector *declarations, ir::ScriptFunction *init_function = nullptr, + lexer::SourcePosition *let_loc = nullptr); std::tuple ParseTypeReferencePart( TypeAnnotationParsingOptions *options); ir::TypeNode *ParseTypeReference(TypeAnnotationParsingOptions *options); @@ -126,6 +176,7 @@ private: ir::ArrowFunctionExpression *ParseArrowFunctionExpression(); void ThrowIfVarDeclaration(VariableParsingFlags flags) override; + std::pair GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseTypeAnnotation(TypeAnnotationParsingOptions *options) override; ir::TSTypeAliasDeclaration *ParseTypeAliasDeclaration() override; @@ -179,6 +230,14 @@ private: ir::Expression *ParseAwaitExpression(); ir::TSTypeParameter *ParseTypeParameter(TypeAnnotationParsingOptions *options) override; + NodeFormatType GetFormatPlaceholderIdent() const; + ir::AstNode *ParseFormatPlaceholder(); + ir::Statement *ParseStatementFormatPlaceholder(std::optional node_format = std::nullopt); + ir::Expression *ParseExpressionFormatPlaceholder(std::optional node_format = std::nullopt); + // NOLINTNEXTLINE(google-default-arguments) + ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional node_format = std::nullopt) override; + ir::TypeNode *ParseTypeFormatPlaceholder(std::optional node_format = std::nullopt); + ir::TSEnumDeclaration *ParseEnumMembers(ir::Identifier *key, const lexer::SourcePosition &enum_start, bool is_const, bool is_static) override; void ParseNumberEnum(ArenaVector &members); @@ -246,17 +305,25 @@ private: // Methods to create AST node(s) from the specified string (part of valid ETS-code!) // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, // and correct parent and, probably, variable set to the node(s) after obtaining - // NOLINTNEXTLINE(modernize-avoid-c-arrays) - inline static constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; - // NOLINTBEGIN(google-default-arguments) + ir::Statement *CreateStatement(std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); - ArenaVector CreateStatements(std::string_view source_code, - std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::Statement *CreateFormattedStatement(std::string_view source_code, std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ir::Statement *CreateFormattedStatement(std::string_view const source_code, std::string_view const file_name, + Args &&...args) + { + std::vector inserting_nodes {}; + (inserting_nodes.emplace(std::forward(args)), ...); + return CreateFormattedStatement(source_code, inserting_nodes, file_name); + } + ir::MethodDefinition *CreateMethodDefinition(ir::ModifierFlags modifiers, std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::TypeNode *CreateTypeAnnotation(TypeAnnotationParsingOptions *options, std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); - // NOLINTEND(google-default-arguments) friend class ExternalSourceParser; friend class InnerSourceParser; @@ -264,6 +331,7 @@ private: private: parser::Program *global_program_; std::vector parsed_sources_; + std::vector inserting_nodes_ {}; }; class ExternalSourceParser { diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index b2955aec9cc1fcf896d25686c5f5ed74a7658eed..9167b18adebe2b1516b23e9d88eab812501c3d46 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -1274,6 +1274,8 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *type_name, Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { Lexer()->NextToken(); // eat '*' prop_name = AllocNode(varbinder::VarBinder::STAR_IMPORT, Allocator()); + } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT) { + prop_name = ParseIdentifierFormatPlaceholder(); } else if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { if ((flags & ExpressionParseFlags::POTENTIAL_CLASS_LITERAL) != 0) { if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS) { diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 13ef8c672976b2ef8786568abdee101277b7b224..4a19f8842780e4436933f767f7238451e440ca40 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1137,6 +1137,10 @@ void ParserImpl::ThrowParameterModifierError(ir::ModifierFlags status) const ir::Identifier *ParserImpl::ExpectIdentifier(bool is_reference) { + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT) { + return ParseIdentifierFormatPlaceholder(); + } + if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("Identifier expected."); } diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 21c674b2e6d56b19aeb6cc03885a5bde0e9b866a..5d0c578d0e6b6e2c01f014a04978ac79f10af070 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -101,6 +101,8 @@ enum class CatchClauseType; namespace panda::es2panda::parser { +class ETSParser; + using FunctionSignature = std::tuple, ir::TypeNode *, varbinder::FunctionParamScope *, panda::es2panda::ir::ScriptFunctionFlags>; @@ -181,6 +183,23 @@ public: ScriptExtension Extension() const; + [[nodiscard]] virtual bool IsETSParser() const noexcept + { + return false; + } + + ETSParser *AsETSParser() + { + ASSERT(IsETSParser()); + return reinterpret_cast(this); + } + + const ETSParser *AsETSParser() const + { + ASSERT(IsETSParser()); + return reinterpret_cast(this); + } + protected: virtual void ParseProgram(ScriptKind kind); static ExpressionParseFlags CarryExpressionParserFlag(ExpressionParseFlags origin, ExpressionParseFlags carry); @@ -502,6 +521,14 @@ protected: return ir::ScriptFunctionFlags::NONE; } + using NodeFormatType = std::pair; + // NOLINTNEXTLINE(google-default-arguments) + virtual ir::Identifier *ParseIdentifierFormatPlaceholder( + [[maybe_unused]] std::optional node_format = std::nullopt) + { + ThrowSyntaxError("Identifier expected"); + } + virtual std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, varbinder::FunctionScope *func_scope); diff --git a/ets2panda/parser/program/program.cpp b/ets2panda/parser/program/program.cpp index 1ab75d6854366725f90a248146a897c3e21f23bc..f0adf76b96dd02d554e45edfc50615c30af740a7 100644 --- a/ets2panda/parser/program/program.cpp +++ b/ets2panda/parser/program/program.cpp @@ -29,6 +29,12 @@ std::string Program::Dump() const return dumper.Str(); } +void Program::DumpSilent() const +{ + [[maybe_unused]] ir::AstDumper dumper {ast_, SourceCode()}; + ASSERT(!dumper.Str().empty()); +} + util::StringView Program::PackageClassName(util::StringView class_name) { if (package_name_.Empty()) { diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index c1331188946169e250b2d3e2192406ca41d8324a..88b3db982c0195f8e9ca327e4f5c57ab23c7dd96 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -217,6 +217,8 @@ public: std::string Dump() const; + void DumpSilent() const; + private: ArenaAllocator *allocator_ {}; varbinder::VarBinder *varbinder_ {}; diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 6b6c6e5cf449bf91a56ad8835176fa9a9796107e..6a19d981662c2b6e002fb51f2b7ae665bd0fee1c 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -132,6 +132,7 @@ static es2panda_Context *CreateContext(es2panda_Config *config, std::string cons varbinder->SetCompilerContext(res->compiler_context.get()); res->emitter = std::make_unique(res->compiler_context.get()); res->compiler_context->SetEmitter(res->emitter.get()); + res->compiler_context->SetParser(res->parser.get()); res->program = nullptr; res->state = ES2PANDA_STATE_NEW; } catch (Error &e) { diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index ff14df7c4ae66ff22c3618052179032ef05d69e4..a602e480e52b0af635d8bcf31cb82414f9adcf08 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -78,7 +78,7 @@ if(PANDA_WITH_ETS) panda_add_gtest( NAME es2panda_public_tests SOURCES - public/es2panda_public_test.cpp + unit/public/es2panda_public_test.cpp LIBRARIES es2panda-public es2panda-lib arkassembler arkbytecodeopt INCLUDE_DIRS @@ -95,7 +95,7 @@ if(PANDA_WITH_ETS) panda_add_gtest( NAME es2panda_astverifier_tests SOURCES - public/ast_verifier_test.cpp + unit/public/ast_verifier_test.cpp LIBRARIES es2panda-lib INCLUDE_DIRS @@ -104,5 +104,17 @@ if(PANDA_WITH_ETS) ${PANDA_SANITIZERS_LIST} ) + panda_add_gtest( + NAME es2panda_astdumper_tests + SOURCES + unit/ast_dumper_test.cpp + LIBRARIES + es2panda-public es2panda-lib arkassembler arkbytecodeopt + INCLUDE_DIRS + ${ES2PANDA_PATH} + SANITIZERS + ${PANDA_SANITIZERS_LIST} + ) + add_subdirectory(tsconfig) endif() diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index 8a077af2aa1c71fa7e8cbec4bf39c1a4edcfc0f6..067f0174687c1432a88946ef6160ecd645cca7f2 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -594,12 +594,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 35 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType2-expected.txt b/ets2panda/test/compiler/ets/FunctionType2-expected.txt index 071e519658d1b4ba336c9c2028e3f5eb16df4101..1dcaa7ce18cad300834afa778966c9f4f1368547 100644 --- a/ets2panda/test/compiler/ets/FunctionType2-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType2-expected.txt @@ -253,12 +253,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index ca35e1e27ca278512efc531856f662671c7d2acc..9f4f79c8571bd80cc8786da052cf4cd025e27c3d 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -281,12 +281,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 36 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType4-expected.txt b/ets2panda/test/compiler/ets/FunctionType4-expected.txt index c2aedd46bf6c9423523616e25365b365f5e02e45..8927a880696633a15427e3a077bcfc4fde64e7e0 100644 --- a/ets2panda/test/compiler/ets/FunctionType4-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType4-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 24 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index 20c6f2c6fc116e7aa3f1d881e6525bb7f4755aeb..c6c23c17deefe05dd99af1785a27875cdb188c55 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } } @@ -434,12 +434,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } } diff --git a/ets2panda/test/compiler/ets/FunctionType6-expected.txt b/ets2panda/test/compiler/ets/FunctionType6-expected.txt index f0652030543c41e44a49166a1606092dd9ac3aca..909ce83c37a295537bee3d4ca6896fb2f6b23d13 100644 --- a/ets2panda/test/compiler/ets/FunctionType6-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType6-expected.txt @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 17 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType8-expected.txt b/ets2panda/test/compiler/ets/FunctionType8-expected.txt index 98c579e069b0722d245a7204faaad75689f82f68..246720088183d754f5cd838c8689bdd222ac527a 100644 --- a/ets2panda/test/compiler/ets/FunctionType8-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType8-expected.txt @@ -448,12 +448,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 42 } } }, @@ -978,12 +978,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 34 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType9-expected.txt b/ets2panda/test/compiler/ets/FunctionType9-expected.txt index b0d532dda3f1bbc611e296d7984d3398daf13429..e6dafbd1aedc0b5c985c1960af18a070f203de10 100644 --- a/ets2panda/test/compiler/ets/FunctionType9-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType9-expected.txt @@ -338,12 +338,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 37 } } }, diff --git a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt index e136477e1f712db4ee485f8cf6108052094ec704..d2a660f61fd80d3a31797928ad2fc5a706b667fd 100644 --- a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt +++ b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt @@ -746,12 +746,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 9 } } }, @@ -948,12 +948,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt b/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt index bc25d70c78f102d30b18e19902252789f137459c..e2347bad084c1a78e4c09c379c4d19a1109714dd 100644 --- a/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt +++ b/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 17 } } }, diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt b/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt index 7e25b44fe194e548df02e16ab173e5742b6a788f..3bbcd11e33ef65d1560400dab4ba7a68d1dc9f59 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt +++ b/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt @@ -119,12 +119,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, diff --git a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt index e902bdbdba6b18c5653e8f9385f15b4f1f1e1952..4769cb130a3e19312293236b350d5ee01f41fd1c 100644 --- a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt +++ b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt @@ -20928,12 +20928,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 238, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 238, + "column": 23 } } }, @@ -20977,12 +20977,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 239, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 239, + "column": 25 } } } diff --git a/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt b/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt index f74eaa8b74e437a34c849d6ddd5300ce4519f4c1..42dbbefc7b1b9fc2284ff47ae8905ac98c15f221 100644 --- a/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt +++ b/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt @@ -466,12 +466,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } } diff --git a/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt b/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt index bd5f6fdaac1d5fdeadccfd1b5a36c7c8988948c6..8c18f48d2d53e1b85e1adde629d867cf5b4b6376 100644 --- a/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt @@ -355,12 +355,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -432,12 +432,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -509,12 +509,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -558,12 +558,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -732,12 +732,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } }, @@ -5376,12 +5376,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 55, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 55, + "column": 13 } } }, @@ -5855,12 +5855,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 20 } } }, @@ -6029,12 +6029,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 60, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 60, + "column": 20 } } }, diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt b/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e86df9a9df27ce7dfa07bdf50c60a3924720059 --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt @@ -0,0 +1,2178 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "second", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 54 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 59 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 33 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "second", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 16 + }, + "end": { + "line": 25, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 58 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 18 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 18 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 29 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "second", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 46 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 38 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 38 + }, + "end": { + "line": 28, + "column": 57 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 62 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 31 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 33 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "second", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 17 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 16 + }, + "end": { + "line": 31, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 61 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 2 + }, + "end": { + "line": 33, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 29 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 36, + "column": 32 + }, + "end": { + "line": 36, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 25 + }, + "end": { + "line": 36, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 23 + }, + "end": { + "line": 36, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 39 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 41 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 16 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 42, + "loc": { + "start": { + "line": 38, + "column": 29 + }, + "end": { + "line": 38, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 38, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 20 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 33 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 40, + "column": 6 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 41, + "column": 28 + }, + "end": { + "line": 41, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 41, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 35, + "column": 17 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } +} diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets b/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a3a18e2c85509dce4d64d1738e8c3b3b8513b1a --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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. + */ + +function foo(first: () => T): T { + const instance = first() + return instance +} + +class X { + static foo(first: () => T, second: () => void): T { + const instance = first() + second() + return instance + } + + static invoke(first: () => T, second: () => void): T { + const instance = first() + second() + return instance + } +} + +function main() { + foo((): String => { return "XXX" }); + + foo((): int => { return 42 }); + + X( + (): String => { return "XXX" }, + ) { + } +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt b/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..642f8dc36d5fffe6d8748b7e9a1c46839a84700c --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt @@ -0,0 +1,1085 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 45 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 51 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 56 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 16, + "column": 55 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 19, + "column": 60 + }, + "end": { + "line": 19, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 53 + }, + "end": { + "line": 19, + "column": 65 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 51 + }, + "end": { + "line": 19, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 67 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 68 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} +TypeError: Type parameter already instantiated with another type [generics_implicit_lambda2.ets:16:17] diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets b/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets new file mode 100644 index 0000000000000000000000000000000000000000..df06746de6c860dbe8bdd698b8de020a053527e2 --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + +function foo(first: (a: U, b: T, c: U) => T): T {} + +function main() { + foo((a: int, b: String, c: String): String => { return "XXX" }); +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt index a39528d5a38ab36748bc8bc21b3cbea200b7b823..826c0e80a2a5d3a8bdbdc04ccce1745a3cf8cedc 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt @@ -174,12 +174,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt index 9378ef0aa26c2df1f48d9148668533fa64f723af..2e60845699d3825ea362f56d7c1df654d0fdef7b 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt @@ -395,12 +395,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt index 4304cd5d687d10c9e40f63cd3235c7113c7298ed..7aee3903115cb2f559b552a5dc20f616270cdc33 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt @@ -498,12 +498,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt index 4d568d9bcf9474a674492185989acb10183bb7d9..58ac0be4cfac4fecd88f525982db39725aebebcf 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt @@ -1952,12 +1952,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 41, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 41, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt b/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt index bcf0a134c96a95adf9a519c133d2610130162040..618aaf0ee73a60ef27168d8fd50d945a3e917aa8 100644 --- a/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt @@ -509,12 +509,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt index d17aa49e9fbfecdd6c5077b0f5e12bfa6b85ef79..beeda0916cc791e793dba090353c106ce47b51ef 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, @@ -196,12 +196,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt index 0217b74e03617b6fa40af2736435e5e4cc702626..981fbdf9d51da28140bb7735680829375e60846c 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt index 64dcbdf3312e415af616aedcba2608594f09cfb9..cb01550c5cf92886f01e6485b96d5516e3b1b69c 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference10-expected.txt b/ets2panda/test/compiler/ets/identifierReference10-expected.txt index 3eb9089b8257dc353155625959fde77cc80781f5..c956b389498268a4a617309cf07097e15c35e852 100644 --- a/ets2panda/test/compiler/ets/identifierReference10-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference10-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -345,12 +345,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference11-expected.txt b/ets2panda/test/compiler/ets/identifierReference11-expected.txt index 0d57a8c2bcad8794cd44fc911adc825909b6ff0d..f0d601241052dc6a836894ef9b0cd87f1863b571 100644 --- a/ets2panda/test/compiler/ets/identifierReference11-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference11-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference12-expected.txt b/ets2panda/test/compiler/ets/identifierReference12-expected.txt index efc3f35fc8f1630c140845997675ebec15a25652..c41ed2bceb102471cca4d21074d66d858b42c362 100644 --- a/ets2panda/test/compiler/ets/identifierReference12-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference12-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, @@ -345,12 +345,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference13-expected.txt b/ets2panda/test/compiler/ets/identifierReference13-expected.txt index f11520714b1f94145ed7f201a62f27580d7d664b..b9a14ad2ffcf30aecc632e992570e00be7fabb65 100644 --- a/ets2panda/test/compiler/ets/identifierReference13-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference13-expected.txt @@ -417,12 +417,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index 07248d61cc74133a3e39b310f113ced2d96a5c2d..4f28a2426c9af4f5c3ec56e6aa866368b4e95e0d 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 38 } } } @@ -354,12 +354,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 6495cedbd507534806dc7aa04c65d78638513a60..6e49f3f6047d4d305eb455b2495bc0e3260c1f38 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -435,23 +435,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -542,12 +542,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index bed72d5ed11b89f0c4e5a6bdd14300794738428f..beb0f9de571c0db777b146fd15c7af262a494110 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -689,23 +689,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } } @@ -796,12 +796,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference5-expected.txt b/ets2panda/test/compiler/ets/identifierReference5-expected.txt index e0cef05812a4d38732a01afb6743d0801ffbe325..ebaa3df0392c0733bb049e85472606fe1e15c774 100644 --- a/ets2panda/test/compiler/ets/identifierReference5-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference5-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -209,12 +209,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index 835924e26a17c4e648145487aadfba3402cfb59b..ed3c6dd87d5fd3763b62d4bcef09dfb9a232888a 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -233,23 +233,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -332,23 +332,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -501,23 +501,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, @@ -557,23 +557,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -671,23 +671,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, @@ -949,12 +949,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -999,12 +999,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -1064,12 +1064,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -1157,12 +1157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -1320,12 +1320,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, @@ -1370,12 +1370,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -1478,12 +1478,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 88c70a3f2dd27e73d03dcb6a8d6589eb6a39a01d..8f6bb0ae1d0975589b7f81984e15d40d629ba372 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } @@ -300,12 +300,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index 8a219b90aaeaeb70f5101732898f1bfc95b46cc7..be6fbf6957dc573b9d43b407d70f4a2a4be7deca 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -420,23 +420,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } } @@ -528,12 +528,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -666,12 +666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index aca5d358ee60330e2d0ffb7355d4224539765564..6b9887c2443957e1e61566b49f2c8077b5b809e5 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, @@ -385,12 +385,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } } diff --git a/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt b/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt index 15762d56248fd9d3714a8e176cddbba1c326798c..0e8ee965c51ef83140341a2831267caee8114ed2 100644 --- a/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt +++ b/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt @@ -198,12 +198,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 41 } } }, @@ -289,12 +289,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 39 } } }, @@ -380,12 +380,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt index c352a2bbf8d8919eeaa6bbc20989e755c08b8c61..035dd5dd21c1153e965fd16b527ba91e0703095a 100644 --- a/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt index b51e8ebc28d9b4a9e7dfda61e70054c0e946f267..bb1005989a0af56b8f0cdd76857e7d4a8184ac95 100644 --- a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt @@ -187,12 +187,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -427,12 +427,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt index 050eafacd6e78562b37a13570083d4b2c800ed71..f902846d03329cbaf2f6f287b0d0a254703358b1 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt index 363fb01a7035caaf6ce91eb80df139c7611b0439..37596af9b0411671162bed3285e0892dfc1935ef 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } } diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt index 2d7478d6bbb74531046405fff69057d2ebc6ff1c..7a5181e8f833dcd0efe9e484c626a4c8b470c3a3 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt index e32a0fe8b363c29033f82de27e2524ebcfc9828a..661b94b89bb836625aa5045129f81acd6c1a15c1 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt index 5614525b4dd15844890c659c258b6e5ad78d0da4..013fcfafc4406c822305c7b524edcaa704178a9e 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 16 } } }, diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt index e0a657b55a3c1182d8c7e98a0f75da005ef5f5c2..e7356eb49ac88663605c00760fdfa126b2da8113 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } } diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt index a3ba983dd75bc6a2498dfdae3e64ad4d1d57ee4f..fa41a9e7db8e6ea6dfb79ef3d996be4a197c9388 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt index 22a3b73a7aeabb59eb9a14bbf64c3778db3c2b05..132a58cca84c259f538604a00d25b0fbf40fcfb9 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt @@ -553,12 +553,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 6 } } }, @@ -783,23 +783,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -890,12 +890,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -1083,12 +1083,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt index 1dc4a6da9a133b7a9ffcb444516db13c20737e51..581964183a2641672a9bbc8fde3b4fe0532fe59b 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt @@ -104,12 +104,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -353,12 +353,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 2cae57f050c12f9206ee759d2fff9109c6cac46a..131a90f02e35ec70e1ef761fb09451a38ed0d508 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -437,12 +437,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 } } }, diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index 943aa3142140f683aabf5d6270246626eb436d73..ef4e77e94292a46fcb1550c006cc52d5d3b59384 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -245,23 +245,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, @@ -328,23 +328,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 31 } } } @@ -436,12 +436,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, @@ -486,12 +486,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -548,12 +548,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, @@ -610,12 +610,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt index 9c9103dccf00b6d76e65386ee61d42021ea14ca0..520b7c45cc2609b062daec9d91f721d5e9c14959 100644 --- a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt +++ b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt @@ -1390,12 +1390,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt b/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt index 0420e8c4b96b71d6e36ac2179941af5bdd885130..9c8d5790d23a90e3ee6a20cb67a84306d46f7edd 100644 --- a/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt +++ b/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt @@ -10697,12 +10697,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 280, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 280, + "column": 18 } } }, @@ -14373,12 +14373,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 281, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 538, + "column": 7 } } }, diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index 69b8a1f75481b700c511885771312e5b850412c8..e4799e206c3975afe37d67236466909ca6fbeff2 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -243,23 +243,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } } @@ -378,12 +378,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 69dabbbb8f507ece4fa449766a3bac54b2f53dd4..37364fa25b8d25f5d7a19254dfe384a02a91aee4 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -289,23 +289,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 } } } @@ -424,12 +424,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 3d5876a288aea2b930633f3cdd5079405613bc24..7d776f219ab4f37e9980605c8736ed316acc3b00 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 2fca7389c448f7bcba61df2a0c56c44087316526..368098ad83f6eb7b5f35661510a5781ab22f2714 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } } @@ -284,12 +284,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index 58b54f8ad1ed0153e11c6f54b1a8169e74561474..ef22164be00fe61f84da4df0bdc7c4adc381728e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 8c92271a75f399b9b7089e85aedc90d9054cc2d7..365d537e22b794e553d61b68cf3d0407320c40f5 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -286,23 +286,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } } @@ -421,12 +421,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index 3a47a2cb86681feb3c7fd71b08a0399ba4820788..d7eb3607ecdda660cc4a5d74dd402f5e03f19c6d 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -290,23 +290,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 } } } @@ -425,12 +425,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 67be00033869b6b07c182be1b7272d5bdf81ce6e..15dc9ad6b1f1d483d7ac083b9f8a22f8341d1e22 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } } @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 270254e5ab5f47498bbfd189e99e126943f37d16..65af224bc883906b76a4648d61499d8d66007624 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -244,23 +244,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } } @@ -379,12 +379,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index f98ed82a485635ee8ca5508daad2bd618b0d136c..277e55a111bd4dcedf02ac2061caecd338b5fc33 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index cba33cf83f95878978207ba234016f9e56128c85..b391dd776152656baf1fa61458c423c4940fd5ce 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/setArrayLength1-expected.txt b/ets2panda/test/compiler/ets/setArrayLength1-expected.txt index a494136da14d4df2024aea6e9c83c5d5eb0b48d5..df6abda8adaa59f33375167c80fd2c1300d8de28 100644 --- a/ets2panda/test/compiler/ets/setArrayLength1-expected.txt +++ b/ets2panda/test/compiler/ets/setArrayLength1-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, diff --git a/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt b/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt index 2d6182f988e66d750e26381fee3cc349495e7957..0fe5d6df8dda8edc812d63a41138d508cbd0428e 100644 --- a/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt +++ b/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt b/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt index 19f43b83628682f7616844eaa4604b51a56bfd86..28b0b12faeb806eaed28de7f60d7958426bbf331 100644 --- a/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt +++ b/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt @@ -233,12 +233,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 76f6ac6fcda6ef5d615c5ba6043773fa4224bfbc..14b1a16a4052ff3326d0faf4d09ed45a02c3c214 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -122,23 +122,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 28 } } } @@ -382,12 +382,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index afd663e75c8cf939ac914e00ab8557a5902f9318..4f17d69d03438581f00eefe50e28732e1d2d4227 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -167,23 +167,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } } @@ -336,12 +336,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } } diff --git a/ets2panda/test/compiler/ets/union_types_1-expected.txt b/ets2panda/test/compiler/ets/union_types_1-expected.txt index 124c26c7ed81d78a771058243ca42cbbb295f32c..c6343a07d2af189303ee52626d73928658599864 100644 --- a/ets2panda/test/compiler/ets/union_types_1-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -276,12 +276,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, @@ -476,12 +476,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_2-expected.txt b/ets2panda/test/compiler/ets/union_types_2-expected.txt index 868389447b183772a6d3affbcd902e8bfbcc5715..02bad5efa30c8e9a195fca186ff7cda9332d71c0 100644 --- a/ets2panda/test/compiler/ets/union_types_2-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_2-expected.txt @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -413,12 +413,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index f69abcff990d30f21f336bdbc510840c89d79cb4..3ae46f4f245c157c7e296e237c49a9f52d4ef420 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_5-expected.txt b/ets2panda/test/compiler/ets/union_types_5-expected.txt index 1ca5dd87b41c5782c6c35e20978a00677fa6680f..3a041975ac79846e59708c3e456c28967f60f1c1 100644 --- a/ets2panda/test/compiler/ets/union_types_5-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_5-expected.txt @@ -174,12 +174,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 18 } } }, @@ -574,12 +574,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 18 } } }, diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt index df130879674f709131f58e8118451cf1885bee5f..d5501d37a78b4b9f0ffdf8acd77fb4c6087cdaf2 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt +++ b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 28 } } }, @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -1348,12 +1348,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 36, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 33 } } }, @@ -1398,12 +1398,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 31 } } }, @@ -1463,12 +1463,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 32 } } }, diff --git a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt index ae08c0e2bc89e3161066f26273a90a2abac937a2..bf878c72fa03e37a869114189c2edde404646afe 100644 --- a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt +++ b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -304,12 +304,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/AccessNBody-expected.txt b/ets2panda/test/parser/ets/AccessNBody-expected.txt index 71bf383517453d950e44559734f7abe60cc0a7a3..068b84444be6b15f224b93399867d68cccc4efd4 100644 --- a/ets2panda/test/parser/ets/AccessNBody-expected.txt +++ b/ets2panda/test/parser/ets/AccessNBody-expected.txt @@ -206,12 +206,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 16 } } }, @@ -304,12 +304,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 16 } } }, @@ -353,12 +353,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 16 } } }, @@ -402,12 +402,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 17 } } }, @@ -451,12 +451,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, @@ -500,12 +500,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 17 } } }, @@ -549,12 +549,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 19 } } }, @@ -2418,12 +2418,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 47, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 47, + "column": 23 } } }, @@ -10644,12 +10644,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 119, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 119, + "column": 54 } } }, @@ -10707,12 +10707,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 120, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 120, + "column": 52 } } }, @@ -10770,12 +10770,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 121, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 121, + "column": 17 } } }, @@ -10833,12 +10833,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 122, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 122, + "column": 18 } } }, @@ -13551,12 +13551,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 139, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 139, + "column": 53 } } }, diff --git a/ets2panda/test/parser/ets/AccessNSieve-expected.txt b/ets2panda/test/parser/ets/AccessNSieve-expected.txt index c51455e4dd544f0e1444e2169f38211620f221ea..e9379ad0e68b659f0e6efe5606a982a1314bc11a 100644 --- a/ets2panda/test/parser/ets/AccessNSieve-expected.txt +++ b/ets2panda/test/parser/ets/AccessNSieve-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 34 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 40 } } }, @@ -264,12 +264,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt b/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt index 1eccd3fe82a3342280f4f27fe92748eee1cca953..a298f24c52b74b3278008473dccf4b51f0f2f877 100644 --- a/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt +++ b/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt @@ -893,12 +893,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, @@ -956,12 +956,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -1019,12 +1019,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 49 } } }, diff --git a/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt b/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt index 9f7a9bfd2fbf598bb3d9bc99e2489e3de2186e25..dd67845c62470f0b84d2c2dcf4779e29c60d5636 100644 --- a/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt +++ b/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt @@ -667,12 +667,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 24 } } }, @@ -730,12 +730,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 24 } } }, @@ -793,12 +793,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 49 } } }, diff --git a/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt b/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt index b7f077ed40726f59e9e5d73ebdef996d6a64967c..d9d3f5b4cc96b7c69151f5322ff837966c350543 100644 --- a/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt +++ b/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } }, diff --git a/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt b/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt index a9f4084f952173fceea4fab0ae77bbbce48d02fe..6e174ce74bed36e52d83d3388896a99a5954eadf 100644 --- a/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt +++ b/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt @@ -2192,12 +2192,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 14 } } }, @@ -2255,12 +2255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 18 } } }, @@ -2333,12 +2333,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 50 } } }, diff --git a/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt b/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt index d3f54dd3e82aa4f0c91c453e5ca33e53cd1cb6b1..5a053da53e353202d757f71054ec7a9d8c74bf2a 100644 --- a/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt +++ b/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 40 } } }, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index d15e91cc98bfe094ee321a6a12461a4dac52fe31..b50e9e486748a14f8ad68761bfe6093b6b1ee9e0 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -121,23 +121,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt index acae80b8e2e9cdc1cfe19d213215e491496b78a0..43188a188ab441342e467771d57b657272a91d01 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 23 } } }, @@ -230,12 +230,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 36 } } }, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index b0087ada5fdff4b2fad21b31af6acac4765737c7..f981e5c3544c73106fa0e317c75001073cc238bc 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -284,23 +284,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, @@ -356,23 +356,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } } @@ -505,12 +505,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, @@ -571,12 +571,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index ca830b055948632c62e206b61655010901def400..f38a7fdcfff8746312205053549a22f3cd26c14e 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/FunctionType-expected.txt b/ets2panda/test/parser/ets/FunctionType-expected.txt index e7dd67b60f462ab48b7a3449156cf6fc7b1ee24a..051ecf2aa9ba66bce0629e4cfa1a0f047d63f03c 100644 --- a/ets2panda/test/parser/ets/FunctionType-expected.txt +++ b/ets2panda/test/parser/ets/FunctionType-expected.txt @@ -187,12 +187,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 32 } } }, @@ -564,12 +564,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 32 } } }, @@ -669,12 +669,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/MathCordic-expected.txt b/ets2panda/test/parser/ets/MathCordic-expected.txt index dd28c3583b68da9afc6a45575b1a8540a3064f04..56e1b883227409c26f070ad2413545b234710af2 100644 --- a/ets2panda/test/parser/ets/MathCordic-expected.txt +++ b/ets2panda/test/parser/ets/MathCordic-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 53 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 51 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 59 } } }, @@ -1179,12 +1179,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 391 } } }, @@ -4633,12 +4633,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/MathPartialSums-expected.txt b/ets2panda/test/parser/ets/MathPartialSums-expected.txt index efb9d801cafd6b1dd0b5da554a83b48f3557e936..23eb4fa4753baadc7c0603ec692e79ba95aacab8 100644 --- a/ets2panda/test/parser/ets/MathPartialSums-expected.txt +++ b/ets2panda/test/parser/ets/MathPartialSums-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 34 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } }, @@ -265,12 +265,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt b/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt index 5a90ca960749ceae2867464814f7717b5827b9ab..2c9560bd208fa1b6efacdbb852355181094ec775 100644 --- a/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt +++ b/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt @@ -4998,12 +4998,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 14 } } }, @@ -5061,12 +5061,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 15 } } }, @@ -5124,12 +5124,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 78, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 78, + "column": 63 } } }, diff --git a/ets2panda/test/parser/ets/Morph3d-expected.txt b/ets2panda/test/parser/ets/Morph3d-expected.txt index 9d8cc669825ef4b65f85256fda25a6d6e7afccec..e5929d51a22301e09c8b302a1d222082630f165a 100644 --- a/ets2panda/test/parser/ets/Morph3d-expected.txt +++ b/ets2panda/test/parser/ets/Morph3d-expected.txt @@ -148,12 +148,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 43 } } }, @@ -211,12 +211,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } }, @@ -273,12 +273,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/StringBase64-expected.txt b/ets2panda/test/parser/ets/StringBase64-expected.txt index 8957ad62c158195c72c9b01a6a3dacb15219a6b3..8ea38a24270626dc74d6c58efc5f568b80e96644 100644 --- a/ets2panda/test/parser/ets/StringBase64-expected.txt +++ b/ets2panda/test/parser/ets/StringBase64-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 119 } } }, @@ -195,12 +195,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 44 } } }, @@ -3009,12 +3009,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 548 } } }, @@ -9357,12 +9357,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 20 } } }, @@ -9420,12 +9420,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 71, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 71, + "column": 21 } } }, diff --git a/ets2panda/test/parser/ets/access_modifier_3-expected.txt b/ets2panda/test/parser/ets/access_modifier_3-expected.txt index a4b4adad2ca3510f091eb4e29cce685bd5631716..6e1441dd51416b58b74ffe14ab1af4e942c94038 100644 --- a/ets2panda/test/parser/ets/access_modifier_3-expected.txt +++ b/ets2panda/test/parser/ets/access_modifier_3-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/anonymous_class-expected.txt b/ets2panda/test/parser/ets/anonymous_class-expected.txt index 44d1aafb1a57c1994c14fafc673e6148e55c5e8f..efcfb803c883d651bd6c892aa919b7f136df6cfa 100644 --- a/ets2panda/test/parser/ets/anonymous_class-expected.txt +++ b/ets2panda/test/parser/ets/anonymous_class-expected.txt @@ -196,12 +196,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 38 } } }, @@ -414,12 +414,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 } } }, diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index b41cb428aa336649bb62adcb20ad8594249697ae..94a5bd22f3afa1dc49d04edd32d2342628ce3c27 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 24 } } }, @@ -248,23 +248,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 35 } } } @@ -368,12 +368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -458,12 +458,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index dabdff4623bcbe79ae17ebc00332ac88bf5b23b4..d9ff0c65bccdf4ff3e8f29a7deff02413dc370e6 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 28 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 31 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } } @@ -338,12 +338,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -400,12 +400,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -490,12 +490,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, diff --git a/ets2panda/test/parser/ets/array_type-expected.txt b/ets2panda/test/parser/ets/array_type-expected.txt index 58aa59e69cd4a99c9897683ef53036bab75393b3..d86b75cade346005dd3d2f529055dca1674a0e0b 100644 --- a/ets2panda/test/parser/ets/array_type-expected.txt +++ b/ets2panda/test/parser/ets/array_type-expected.txt @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 24 } } }, @@ -303,12 +303,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 32 } } }, diff --git a/ets2panda/test/parser/ets/assign-expected.txt b/ets2panda/test/parser/ets/assign-expected.txt index de7bfd7e216b62820733bfca1b4b51248a6e86de..89ce3dbfcaa36a1abdb33489da5ff8c2b95fcd1b 100644 --- a/ets2panda/test/parser/ets/assign-expected.txt +++ b/ets2panda/test/parser/ets/assign-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -264,12 +264,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/assign-func-expected.txt b/ets2panda/test/parser/ets/assign-func-expected.txt index a391d586b28b76439b85bbdf61ac2ae21cb0bf06..9acaaa71d7e17739606f0832fb279a402f803b44 100644 --- a/ets2panda/test/parser/ets/assign-func-expected.txt +++ b/ets2panda/test/parser/ets/assign-func-expected.txt @@ -368,12 +368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 34 } } } diff --git a/ets2panda/test/parser/ets/assignments-expected.txt b/ets2panda/test/parser/ets/assignments-expected.txt index d5dbf6fbb6d7e7398860de6d5cd44a95ad36aea5..a23e936e229dd27f1da9aa2ba4bb7df8679d7bef 100644 --- a/ets2panda/test/parser/ets/assignments-expected.txt +++ b/ets2panda/test/parser/ets/assignments-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -251,12 +251,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/async_function-expected.txt b/ets2panda/test/parser/ets/async_function-expected.txt index f9b41ad62976230f90159731e78beb366c4d2b08..5ad52c7a2102a52b95198532b56e5b1029e9a5ba 100644 --- a/ets2panda/test/parser/ets/async_function-expected.txt +++ b/ets2panda/test/parser/ets/async_function-expected.txt @@ -999,12 +999,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 96 } } } diff --git a/ets2panda/test/parser/ets/async_lambda_bad-expected.txt b/ets2panda/test/parser/ets/async_lambda_bad-expected.txt index 6928920e681cd9cff7853c4026ae65af7b547fdd..348a522a40c5f421097da5e12cfbec6c86be5e96 100644 --- a/ets2panda/test/parser/ets/async_lambda_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_lambda_bad-expected.txt @@ -256,12 +256,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 2007b8a7be58dbdd60a7102bfe8470e58ad5a622..657afa171455554c64b5d2a5cf2dd6abbcda280e 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -156,12 +156,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 9adc24bf5003ce6ca65d8a6dcb9b75b06f74f263..2159d4df660a84e8b58988960fd248006cbbf539 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 43 } } }, "loc": { "start": { - "line": 1, + "line": 38, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 44 } } }, @@ -176,23 +176,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 39, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 33 } } } @@ -1308,12 +1308,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 2 } } }, @@ -2158,12 +2158,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 2 } } }, @@ -2291,12 +2291,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 31 } } }, @@ -2368,12 +2368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index 4be4d2ea48517d38274b99172e9921e0e2c1134b..f491c8074d578921dbadc41b6583978df7d70555 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -274,23 +274,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -371,23 +371,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, @@ -513,23 +513,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 25, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 19 } } }, @@ -628,23 +628,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 25 } } }, @@ -714,23 +714,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 29, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 20 } } }, @@ -800,23 +800,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 30, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 20 } } }, @@ -944,23 +944,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 31, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 34 } } }, @@ -1088,23 +1088,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 32, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 34 } } }, @@ -1232,23 +1232,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 33, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 34 } } }, @@ -1376,23 +1376,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 34, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 34 } } }, @@ -1462,23 +1462,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 37, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 17 } } }, @@ -1548,23 +1548,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 38, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 17 } } }, @@ -1634,23 +1634,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 39, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 17 } } }, @@ -1836,23 +1836,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 40, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 33 } } }, @@ -1922,23 +1922,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 43, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 18 } } }, @@ -2008,23 +2008,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 44, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 18 } } }, @@ -2094,23 +2094,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 45, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 21 } } }, @@ -2180,23 +2180,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 46, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 46, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 21 } } }, @@ -2266,23 +2266,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 49, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 49, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 17 } } }, @@ -2352,23 +2352,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 50, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 50, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 17 } } }, @@ -2438,23 +2438,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 51, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 51, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 18 } } }, @@ -2524,23 +2524,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 52, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 52, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 18 } } }, @@ -2610,23 +2610,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 53, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 31 } } }, "loc": { "start": { - "line": 1, + "line": 53, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 32 } } }, @@ -2696,23 +2696,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 56, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 56, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 18 } } }, @@ -2782,23 +2782,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 57, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 57, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 18 } } }, @@ -2868,23 +2868,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 58, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 58, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 19 } } }, @@ -3012,23 +3012,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 59, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 29 } } }, @@ -3098,23 +3098,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 62, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 62, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 17 } } }, @@ -3184,23 +3184,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 63, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 63, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 17 } } }, @@ -3328,23 +3328,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 64, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 64, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 25 } } }, @@ -3414,23 +3414,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 67, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 67, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 17 } } }, @@ -3500,23 +3500,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 68, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 17 } } }, @@ -3586,23 +3586,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 69, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 69, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 17 } } }, @@ -3788,23 +3788,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 70, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 33 } } }, @@ -3932,23 +3932,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 73, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 73, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 27 } } }, @@ -4076,23 +4076,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 74, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 74, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 29 } } }, @@ -4423,23 +4423,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 75, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 62 } } }, "loc": { "start": { - "line": 1, + "line": 75, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 63 } } }, @@ -4770,23 +4770,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 63 } } }, "loc": { "start": { - "line": 1, + "line": 76, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 64 } } }, @@ -4943,23 +4943,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 77, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 35 } } } @@ -5051,12 +5051,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -5101,12 +5101,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 10 } } }, @@ -5151,12 +5151,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -5201,12 +5201,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -5292,12 +5292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -5369,12 +5369,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 17 } } }, @@ -5449,12 +5449,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, @@ -5558,12 +5558,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, @@ -5638,12 +5638,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 19 } } }, @@ -5718,12 +5718,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, @@ -5856,12 +5856,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, @@ -5994,12 +5994,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 33 } } }, @@ -6132,12 +6132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 33 } } }, @@ -6270,12 +6270,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 33 } } }, @@ -6350,12 +6350,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 16 } } }, @@ -6430,12 +6430,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 16 } } }, @@ -6510,12 +6510,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 16 } } }, @@ -6706,12 +6706,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 32 } } }, @@ -6786,12 +6786,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 17 } } }, @@ -6866,12 +6866,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 17 } } }, @@ -6946,12 +6946,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 20 } } }, @@ -7026,12 +7026,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 46, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 20 } } }, @@ -7106,12 +7106,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 49, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 16 } } }, @@ -7186,12 +7186,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 50, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 16 } } }, @@ -7266,12 +7266,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 51, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 17 } } }, @@ -7346,12 +7346,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 52, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 17 } } }, @@ -7426,12 +7426,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 53, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 31 } } }, @@ -7506,12 +7506,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 56, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 17 } } }, @@ -7586,12 +7586,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 57, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 17 } } }, @@ -7666,12 +7666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 58, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 18 } } }, @@ -7804,12 +7804,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 28 } } }, @@ -7884,12 +7884,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 62, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 16 } } }, @@ -7964,12 +7964,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 63, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 16 } } }, @@ -8102,12 +8102,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 64, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 24 } } }, @@ -8182,12 +8182,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 67, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 16 } } }, @@ -8262,12 +8262,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 16 } } }, @@ -8342,12 +8342,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 69, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 16 } } }, @@ -8538,12 +8538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 32 } } }, @@ -8676,12 +8676,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 73, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 26 } } }, @@ -8814,12 +8814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 74, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 28 } } }, @@ -9155,12 +9155,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 75, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 62 } } }, @@ -9496,12 +9496,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 63 } } }, @@ -9663,12 +9663,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 34 } } } diff --git a/ets2panda/test/parser/ets/binary_operations-expected.txt b/ets2panda/test/parser/ets/binary_operations-expected.txt index 2b38694179b7aba9963c400a90cb5aec4081599d..7503903f1d4b105f07a41b3ea71fca47c0b8e0cb 100644 --- a/ets2panda/test/parser/ets/binary_operations-expected.txt +++ b/ets2panda/test/parser/ets/binary_operations-expected.txt @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 31 } } }, @@ -391,12 +391,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 39 } } }, @@ -482,12 +482,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 31 } } }, @@ -601,12 +601,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 35 } } }, @@ -692,12 +692,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 31 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 39 } } }, @@ -930,12 +930,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 39 } } }, @@ -1077,12 +1077,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 54 } } }, @@ -1168,12 +1168,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 37 } } }, @@ -1343,12 +1343,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 60 } } }, @@ -1434,12 +1434,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 31 } } }, @@ -1525,12 +1525,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 32 } } }, @@ -1616,12 +1616,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, @@ -1707,12 +1707,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 31 } } }, @@ -1798,12 +1798,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 31 } } }, @@ -1889,12 +1889,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 31 } } }, @@ -1980,12 +1980,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 35, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 35, + "column": 33 } } }, @@ -2071,12 +2071,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 36, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 34 } } }, @@ -2162,12 +2162,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 34 } } }, @@ -2253,12 +2253,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 } } }, @@ -2344,12 +2344,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 34 } } }, @@ -2435,12 +2435,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 34 } } }, @@ -2582,12 +2582,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 41, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 41, + "column": 46 } } }, @@ -2729,12 +2729,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 46 } } }, diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index ef4e2d8e363389611b650ec6382d36d83b554c8d..ddbbcc7ffe442204fe38b00816e034e1440fa5c6 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -263,12 +263,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/break-expected.txt b/ets2panda/test/parser/ets/break-expected.txt index 6f3b8210bd49cfc6bbb0e59c8d254cee4ff8b322..c165861131c3dca33733e7b1a729bb99e726b1c6 100644 --- a/ets2panda/test/parser/ets/break-expected.txt +++ b/ets2panda/test/parser/ets/break-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index d791b13df928e116652ece4c009b538d4462c392..d8a3a2b217d8f3854979e80bd5d1110a4dd80f79 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 17 } } }, @@ -705,23 +705,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -812,12 +812,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 21 } } }, diff --git a/ets2panda/test/parser/ets/class_init-expected.txt b/ets2panda/test/parser/ets/class_init-expected.txt index 985153831a02029cbcd5675e03ff5c08eced33db..ddee21102b0dd0ba05782339fc70cefafd44bfcf 100644 --- a/ets2panda/test/parser/ets/class_init-expected.txt +++ b/ets2panda/test/parser/ets/class_init-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index a6bdefd2f1df70c3c4fb72e391964ef91e012ec5..a4e953fd73edf315b9fb8640d579eb82ca42af9e 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -244,23 +244,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 } } }, @@ -344,23 +344,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -488,23 +488,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } } @@ -596,12 +596,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -722,12 +722,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -816,12 +816,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, @@ -954,12 +954,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/class_instance_creation-expected.txt b/ets2panda/test/parser/ets/class_instance_creation-expected.txt index b9cfb97c79990632e342474c80a00858871b54f4..5b17fb7414cddee4d27b172030303bf9817c700e 100644 --- a/ets2panda/test/parser/ets/class_instance_creation-expected.txt +++ b/ets2panda/test/parser/ets/class_instance_creation-expected.txt @@ -721,12 +721,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 76 } } }, @@ -868,12 +868,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 77 } } }, @@ -1029,12 +1029,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 85 } } } diff --git a/ets2panda/test/parser/ets/class_instance_initializer-expected.txt b/ets2panda/test/parser/ets/class_instance_initializer-expected.txt index 4e1f9163543a795969ead5a52efeb9060873cd6c..f43d49e1c488306b3e7675a201dbe2f34e1cc96f 100644 --- a/ets2panda/test/parser/ets/class_instance_initializer-expected.txt +++ b/ets2panda/test/parser/ets/class_instance_initializer-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -279,12 +279,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -1705,12 +1705,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 16 } } }, @@ -1768,12 +1768,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/class_static_initializer-expected.txt b/ets2panda/test/parser/ets/class_static_initializer-expected.txt index 48f5bda364a58ff9fdaafe7739c644d25c130ca7..7a091612afe48d9247b68b4af9175904e01ddfce 100644 --- a/ets2panda/test/parser/ets/class_static_initializer-expected.txt +++ b/ets2panda/test/parser/ets/class_static_initializer-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } }, @@ -696,12 +696,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/const-expected.txt b/ets2panda/test/parser/ets/const-expected.txt index 15ceee614718d599536797de13e0a3f30f06aa1d..1747669044fc29618c620316a97b5d2989dc97a4 100644 --- a/ets2panda/test/parser/ets/const-expected.txt +++ b/ets2panda/test/parser/ets/const-expected.txt @@ -157,12 +157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -248,12 +248,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } } diff --git a/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt b/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt index a8d99f387378ac1cf09f2f8e96d22c633561c261..09cc3fe47d3a9ba508b87908e9378bfb79c9cd15 100644 --- a/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt +++ b/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt b/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt index c12b546800e52d6f095b88dc9fc76f24fbad6a9b..39d854bcec258aa9336e357b7cb580f4613d8e39 100644 --- a/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt +++ b/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/constructors-expected.txt b/ets2panda/test/parser/ets/constructors-expected.txt index 762124e0a30691c56f463095e4166e5b8face1b8..3bbc3e2cd13139bb48d0059a568b70dd98077b33 100644 --- a/ets2panda/test/parser/ets/constructors-expected.txt +++ b/ets2panda/test/parser/ets/constructors-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, @@ -799,12 +799,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/continue-expected.txt b/ets2panda/test/parser/ets/continue-expected.txt index 278cbe5e954a88df3aa0ef780ff90a3ea92c636b..cd8cfe6fabf65c4e7e0b788ab216c52b559ed281 100644 --- a/ets2panda/test/parser/ets/continue-expected.txt +++ b/ets2panda/test/parser/ets/continue-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index 6cf890abe7d7568f8768b3639687257d3c3a0188..0455f4f8b2e9110156d6a2d656885ede6c5def4d 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, @@ -274,23 +274,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -330,23 +330,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } @@ -438,12 +438,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -488,12 +488,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -538,12 +538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -588,12 +588,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -638,12 +638,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -688,12 +688,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -738,12 +738,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 } } }, @@ -788,12 +788,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 16 } } }, @@ -838,12 +838,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 16 } } }, @@ -888,12 +888,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/declare_class-expected.txt b/ets2panda/test/parser/ets/declare_class-expected.txt index 373bf55cae62e02efecbe743687a1c915e608d92..4e26b0f34509b4b43ddfcbd42916bb3d78572795 100644 --- a/ets2panda/test/parser/ets/declare_class-expected.txt +++ b/ets2panda/test/parser/ets/declare_class-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt b/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt index cdaf88a64574c4fd3fc9400d6848c420f763cb3a..8fc27406b67b17ec075baded8262001d885f9cda 100644 --- a/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 } } }, diff --git a/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt b/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt index 752e4a97cdf2482ba45ea5ca5df3b5f02ed4c940..beb867b7c5edc03ddd55dd39c38464986da7c261 100644 --- a/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt +++ b/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt index 89bafa7dc78e11846fd1089dc1620841e5665318..63103e5c36e00436f54f6fe15496bc78c7c39ce4 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 16 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/empty_statement-expected.txt b/ets2panda/test/parser/ets/empty_statement-expected.txt index df7d09a3cd5d122eae7645c6e1315ec3e5d0a984..2e225881a50cdbead8412272e1fcb37864c37007 100644 --- a/ets2panda/test/parser/ets/empty_statement-expected.txt +++ b/ets2panda/test/parser/ets/empty_statement-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/enum-expected.txt b/ets2panda/test/parser/ets/enum-expected.txt index 33faf5b2498f1fdc6c1fca6a04ba0484d27174d2..edcd158548ed00f63dd34d455018a1c3ffbcb6d7 100644 --- a/ets2panda/test/parser/ets/enum-expected.txt +++ b/ets2panda/test/parser/ets/enum-expected.txt @@ -247,12 +247,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/enum19-expected.txt b/ets2panda/test/parser/ets/enum19-expected.txt index 7cc03bf96332f508a420c7a127e9b6d9848e182b..df747461ca68928a9989a06b7e889fb6ceddcba1 100644 --- a/ets2panda/test/parser/ets/enum19-expected.txt +++ b/ets2panda/test/parser/ets/enum19-expected.txt @@ -1 +1,310 @@ -SyntaxError: Duplicate enum initialization value -1 [enum19.ets:20:1] +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/enum20-expected.txt b/ets2panda/test/parser/ets/enum20-expected.txt index 65d031f2b2887eb78f9de05b777525622354aab9..ddbf6ffb3da603c6a29106d0ab63c8a47d0cbc13 100644 --- a/ets2panda/test/parser/ets/enum20-expected.txt +++ b/ets2panda/test/parser/ets/enum20-expected.txt @@ -1 +1,1025 @@ -SyntaxError: Duplicate enum initialization value 0 [enum20.ets:16:52] +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -100, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -99, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "White", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 39 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 16, + "column": 47 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 39 + }, + "end": { + "line": 16, + "column": 51 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 53 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "red", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "green", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "blue", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 11 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "white", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "White", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} +TypeError: No enum item method called 'ordinal' [enum20.ets:19:23] diff --git a/ets2panda/test/parser/ets/enum21-expected.txt b/ets2panda/test/parser/ets/enum21-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cdccfed003d73dbb2108d33616e0ed7c91d4fb7a --- /dev/null +++ b/ets2panda/test/parser/ets/enum21-expected.txt @@ -0,0 +1,268 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Gray", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Grey", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 21 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/enum21.ets b/ets2panda/test/parser/ets/enum21.ets new file mode 100644 index 0000000000000000000000000000000000000000..54dfe00e9fe265a1222713fa53e6fa86ef4b0879 --- /dev/null +++ b/ets2panda/test/parser/ets/enum21.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + +enum ArkColor { + Gray = "#ff808080", + Grey = "#ff808080" +} diff --git a/ets2panda/test/parser/ets/enum22-expected.txt b/ets2panda/test/parser/ets/enum22-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c19b3b0f34b7abbaf250f0bec86fc5101f9d1bd --- /dev/null +++ b/ets2panda/test/parser/ets/enum22-expected.txt @@ -0,0 +1 @@ +SyntaxError: Variable 'Gray' has already been declared. [enum22.ets:18:5] diff --git a/ets2panda/test/parser/ets/enum22.ets b/ets2panda/test/parser/ets/enum22.ets new file mode 100644 index 0000000000000000000000000000000000000000..27f85fd0a413229006b668c08cbf5ed4578c6286 --- /dev/null +++ b/ets2panda/test/parser/ets/enum22.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + +enum duplicateKeysStringCase { + Gray = "#ff808080", + Gray = "#ff808080" +} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/enum23-expected.txt b/ets2panda/test/parser/ets/enum23-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..11869929521aa134465fb7df635e8d0d8eecc0a0 --- /dev/null +++ b/ets2panda/test/parser/ets/enum23-expected.txt @@ -0,0 +1 @@ +SyntaxError: Variable 'Red' has already been declared. [enum23.ets:18:5] diff --git a/ets2panda/test/parser/ets/enum23.ets b/ets2panda/test/parser/ets/enum23.ets new file mode 100644 index 0000000000000000000000000000000000000000..de2a396d37f6a2cb860b8392411501c05583a2dc --- /dev/null +++ b/ets2panda/test/parser/ets/enum23.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + +enum duplicateKeysNumCase { + Red = 1, + Red = 1 +} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index f0f84b4b21fd14ee348758a2c3d296b7725a2398..aab03ca6223b18134f4b881ca75b3b54274a573f 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -327,23 +327,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } } @@ -435,12 +435,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, @@ -485,12 +485,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, diff --git a/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt b/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt index 9d29b2e8db9cb4bbdf0049eb8b5fa6ae35022fc7..81d573a8a844b6d159166b8c43b53155759fdf7a 100644 --- a/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt +++ b/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/field_decl-expected.txt b/ets2panda/test/parser/ets/field_decl-expected.txt index 13d0f0143d25fd65fe785bd4ddd82697f0ac54e3..25bfd9129a170d6fae7fa85d26d9c532dc07f18c 100644 --- a/ets2panda/test/parser/ets/field_decl-expected.txt +++ b/ets2panda/test/parser/ets/field_decl-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -251,12 +251,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -314,12 +314,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, @@ -377,12 +377,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, @@ -426,12 +426,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 14 } } }, @@ -475,12 +475,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 20 } } }, @@ -538,12 +538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 38 } } }, @@ -601,12 +601,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 28 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 48 } } }, @@ -664,12 +664,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 34 } } }, diff --git a/ets2panda/test/parser/ets/for_of-expected.txt b/ets2panda/test/parser/ets/for_of-expected.txt index 481464b7259e994d486816a998733452133af19c..d3446be05acb4a707042ce62be9e66b71e03153c 100644 --- a/ets2panda/test/parser/ets/for_of-expected.txt +++ b/ets2panda/test/parser/ets/for_of-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/for_of_02-expected.txt b/ets2panda/test/parser/ets/for_of_02-expected.txt index 7a44ae114a3c8ff1e0a1ddf081d9d10e615731de..f7ae611379b140d2abf221271420444eec740cd0 100644 --- a/ets2panda/test/parser/ets/for_of_02-expected.txt +++ b/ets2panda/test/parser/ets/for_of_02-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/function-expected.txt b/ets2panda/test/parser/ets/function-expected.txt index a5f03e6e932f58902a2622205dd5e2eda1c36623..f1b6103f28447ef581b227b2b2e7eb24c5667e1a 100644 --- a/ets2panda/test/parser/ets/function-expected.txt +++ b/ets2panda/test/parser/ets/function-expected.txt @@ -1467,12 +1467,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 2 } } } diff --git a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt index 9f504266b843b1daeaff8568c320056754be55b6..2c3510eb6070b6e709fbb43b7891a215c1cc35ee 100644 --- a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt +++ b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt @@ -254,12 +254,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index e765b5e9e3e22a4c40d8e7145ad6bfd46973fb87..86dadbaca552b0b22c7f1cd3bcc89d9bc24254e7 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -272,12 +272,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 44 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 86c0bf3a67b14a00dad67ec7b52878c2d2541808..41e4545d599f50668ebfd4a924992a225a4b2899 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 33 } } } @@ -421,12 +421,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/generics_1-expected.txt b/ets2panda/test/parser/ets/generics_1-expected.txt index ef863b3f6522e330abc880b86838697f2ceadfb1..d8e381e5d79357471ad7d40e3f3153c46c732594 100644 --- a/ets2panda/test/parser/ets/generics_1-expected.txt +++ b/ets2panda/test/parser/ets/generics_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e080ae9620bc835af391bfd5ede1f7c4679bd2a --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt @@ -0,0 +1,524 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8417c9a359fe85b148aa07392d0169087672456 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +class X > {} +function main() {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d2baa5275ba064b0dff77cbe23ed32d5a5de3df --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt @@ -0,0 +1,777 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 44 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 48 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "456", + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 22 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets new file mode 100644 index 0000000000000000000000000000000000000000..17b5c5a98b3e028f0606db6ca3dcef9b668e0f2e --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function bar>(x: T): T { + return x; +} + +function main(): void { + bar("456"); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..326439e5f9989bc22daf4762ec84a1504d7cbfab --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt @@ -0,0 +1,336 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 41 + } + } + }, + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..d06d34b560ab879ff7a8d50dc555b6be010509ea --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b525585b96fa00ef977c4c828c982d39924a93c --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt @@ -0,0 +1,527 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 47 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 53 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 52 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f22a296448f8662e92d5f9da27d96825a9b1d8f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +function X >(value: K) : K { + return value; +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c01abfe35c951526eb766700c0f41f25a34061eb --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt @@ -0,0 +1,709 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 29 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets new file mode 100644 index 0000000000000000000000000000000000000000..369ca4643a150b496775136670484f83d02c5564 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface func { + ifunc(x: T): void; +} +class X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd54bd69e73bc35d596b15baeb8d66b7b262de96 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt @@ -0,0 +1,998 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 12 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 26 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 35 + }, + "end": { + "line": 21, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 33 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3f94be24d3d245c70035c757a4ba5f3ee209e3f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface func { + ifunc1(x: T): void; + ifunc2(x: K): void; +} +class X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e843f6940ae2947cfc2b0f1c16ab9439228c8bc8 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt @@ -0,0 +1,552 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets new file mode 100644 index 0000000000000000000000000000000000000000..34cdb626a4fd7781a27a6f02023bac2e5481163f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +class X ,T> {} +function main() {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e4e9ef1deb0939a69252b0f46d32b1237bdc2d7 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt @@ -0,0 +1,680 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myCharClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets new file mode 100644 index 0000000000000000000000000000000000000000..5144fef006c5a3aeb8a63f5c026f496d87120dce --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +class X > {} +function main(){ + const myCharClass = new X(); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cedf6ac5edb651aad900d73b1e46f789874a6e0e --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt @@ -0,0 +1,750 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myCharClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 44 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 46 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 46 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Type 'Char' is not assignable to constraint type 'Comparable'. [generics_type_param_constraint_8.ets:19:31] diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets new file mode 100644 index 0000000000000000000000000000000000000000..75d51601cc589f6793877cbefaf8ec887d70a4c8 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +class X ,T> {} +function main(){ + const myCharClass = new X(); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..51f8058c292d76263a4fe008edbf2bc4fdbae3f5 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt @@ -0,0 +1,1080 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 40 + }, + "end": { + "line": 18, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets new file mode 100644 index 0000000000000000000000000000000000000000..b210876fe1ae353ef7dbea4f0958f55c973437a2 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Base { } +class Derived extends Base { } +class G> { } +function main(){ + let y: G +} diff --git a/ets2panda/test/parser/ets/getter_native-expected.txt b/ets2panda/test/parser/ets/getter_native-expected.txt index 51137c86a61adabd0385189fa1bcc65993b3e95c..707c2e0c1e51639dbff40384c94e9d624469bdc8 100644 --- a/ets2panda/test/parser/ets/getter_native-expected.txt +++ b/ets2panda/test/parser/ets/getter_native-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt b/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt index 2ee593916541e3b04478b472877c837761d8d1ad..3412eacfea5a68acaf1a45299365245c543af3f4 100644 --- a/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt +++ b/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, @@ -769,12 +769,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 22 } } }, @@ -818,12 +818,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt b/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt index f4338c189264a1da8aab028e2b93d0e9fb727c55..ed873fe6929caabb985252186532009293bcd939 100644 --- a/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt +++ b/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, @@ -765,12 +765,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, @@ -814,12 +814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/global_const_vars3-expected.txt b/ets2panda/test/parser/ets/global_const_vars3-expected.txt index e04656ffbcb0632b906f3c1e08779d294f3ff7e0..e2c12eaa49798fdd8480024812da446e5f294a71 100644 --- a/ets2panda/test/parser/ets/global_const_vars3-expected.txt +++ b/ets2panda/test/parser/ets/global_const_vars3-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 32 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } }, @@ -778,12 +778,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } } diff --git a/ets2panda/test/parser/ets/global_const_vars4-expected.txt b/ets2panda/test/parser/ets/global_const_vars4-expected.txt index 256ab597dba491525248d5785704f8f19a9478d5..8d67d403e87a8e200ea9088362ca8a568d1e9889 100644 --- a/ets2panda/test/parser/ets/global_const_vars4-expected.txt +++ b/ets2panda/test/parser/ets/global_const_vars4-expected.txt @@ -145,12 +145,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 45 } } }, @@ -889,4 +889,4 @@ } } } -TypeError: Cannot assign to a constant variable date [global_const_vars4.ets:1:1] +TypeError: Cannot assign to a constant variable date [global_const_vars4.ets:17:21] diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index ffe91080804c1082ba423295668914b2efd6a291..79101bcf96800d89de1a50e9199225cedaac2967 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 28 } } } @@ -325,12 +325,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, @@ -423,12 +423,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt index beebde9f92c0b04f55b1d6501e1b1b159a9530f5..020e5e183aa1dbcfcab384d8c6d778ab10b19a39 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -179,23 +179,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } } @@ -288,12 +288,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt index 64d88326d9155dcd267df70c0dd0c750b559273d..41d64f40ed99bea9ccd0c10a920cb18aa1ab0606 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -179,23 +179,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } } @@ -288,12 +288,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt index 953043cdc28dc0c38dc0313fc693867501509c1f..49fc3015d82ec7acb23970b392f82ebe012f81e4 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt index 7b824f2ff048cb9d101d5e9e35c121531704cc74..6f65df047697c0e17df741ac22d048b7e86750ad 100644 --- a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt @@ -568,23 +568,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 28, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 15 } } }, @@ -624,23 +624,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 22 } } } @@ -1002,12 +1002,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 14 } } }, @@ -1052,12 +1052,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt index c8d0f42b5e41cd6e56583df841617ad486a60803..a05f2eaec9c5335ddc4a9a6d7c354587f81b8448 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -252,23 +252,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -340,23 +340,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 48 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 49 } } } @@ -567,12 +567,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -649,12 +649,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, @@ -730,12 +730,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 48 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt index aa4820bf60d0775cc2d8c378fd129d5f1f140729..e105d8c13c3fde8e3d43cebdb57dc782431d5609 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt @@ -255,23 +255,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 56 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 57 } } }, @@ -403,23 +403,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 56 } } } @@ -603,12 +603,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 56 } } }, @@ -745,12 +745,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt index 996057b92504c02391e37b37e25c0d7abe60ca4c..18b018cd704c49b55d3b2850048acc8fb99099d5 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt @@ -195,23 +195,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } } @@ -335,12 +335,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt index eb9dd09cbc92d5d265f6fd02ab8564ab9d122067..77c11005f850e46bb01176d0824fede31f297e9c 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt @@ -296,23 +296,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -384,23 +384,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } @@ -524,12 +524,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -606,12 +606,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt index 32d4a693e6a9bf9f3661d40355e607305f69b4d4..4ce97a3c9bc8f6c6ea014f36e35c67458b7b276e 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt @@ -253,23 +253,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt index e2ec55d6b007e5439c8eed0298118ea3cda05fc5..8192941368ea24f6f7720624dde7df81d27bece2 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt @@ -296,23 +296,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -384,23 +384,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } } @@ -524,12 +524,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -606,12 +606,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt index 55cc9b92604e9d3ae8135c786f80dc1078b33be1..6c17455873bca42a862bb6654b85a19a7df8d4dc 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt @@ -253,23 +253,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt index 8d440877dc15a8db81d0ba3b32511450728b6e4c..c99810cb09868251e1b25b32ac77b981cfe998d0 100755 --- a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt @@ -195,23 +195,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -283,23 +283,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } } @@ -423,12 +423,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -505,12 +505,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt index 8214b5801d6d26b4eb8db16df8f561db06ca4a34..7ceeda97255e793639dafa3e9ea26440a915fc1a 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt @@ -354,23 +354,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -442,23 +442,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 46 } } } @@ -582,12 +582,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -664,12 +664,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt index 359cefafad21243794d99dc7c48165b343dcaa8b..a1118839c3ec9252ace25799812f2ba32ca32d5e 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt @@ -252,23 +252,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 } } } @@ -391,12 +391,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt index d3ab1b4c34ed9851d9438ab8e2ae3f111832bef5..bb89ff35a9cc410bace3f4991833478b5450fbf3 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt @@ -267,23 +267,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -355,23 +355,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } @@ -495,12 +495,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -577,12 +577,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt index 89ec61fe08d5433199b5a25bafeb05ba2565ccd3..614c31accbe1145a796a297de4be41908887f17d 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt @@ -297,23 +297,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 52 } } }, @@ -445,23 +445,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 56 } } } @@ -615,12 +615,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, @@ -757,12 +757,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt index 95e2b9ca99e899d603e9c8bb410372d23921b9e6..3d619efbbe134e3b0c9ea4606b046b17bddc6a98 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt @@ -267,23 +267,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -355,23 +355,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } @@ -495,12 +495,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -577,12 +577,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt index 6502defab4343385e930f0a5417495e20aa01f75..08763cfb560d323b79d9c3dced590c61c5054767 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt @@ -297,23 +297,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 52 } } }, @@ -445,23 +445,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 56 } } } @@ -615,12 +615,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, @@ -757,12 +757,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt index a092b0c023ce35de044ad529cf2cfa8816d0cf06..a522257b8f57f2d4b3ac7d8ad4e250a471f6dde5 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 46 } } } @@ -567,12 +567,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -649,12 +649,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt index 2afbc6d7abbcb9fc2e9cce7dc85ae0d92fd1305f..8e84f0f521ad0a24ddda14fe4fa34ab86a8b4a08 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt index 888bdee534c5fc99a46cacf3ecfab842c1093c88..1401356c1015f9bb7a7ded17a7013cb066157bff 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt index 044b63affb8e6505e69a4a438392ae7ed5fb6998..85f26116667833d6e3b93976544a522ecad636d2 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt index 3b6b6fbb30311934bfb0841b4759cccc7128d033..925e41d76aaf4ba07a500af1f679f963d288e3df 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt index 4706c5778946b15742e6e6265449d1d10d2d368a..e22b6128f4292dfc54edbf937aa6c598a3f78184 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 38 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt index 11c8c5ed4a5c89d416f201d5b5dabdc3cbf9f5cb..e11f163db86c2353dc6efe6bef5022613ebac601 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 33 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt index 068e9cc8aafeea67998740f6741201c923ac741f..6db77e6e7f0a7f582a5b7b2a500d876badb9c8da 100644 --- a/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt @@ -147,12 +147,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt index 1c44fc097c9600200e81cb3d45ccca5bef5984a5..fd7dc9f6ab8cf66f6e59e5db3eef3a87c8896c8f 100644 --- a/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt @@ -147,12 +147,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt index ab9f2deb442f8b6e9a4559d662de8e6234c269f1..889698997e73fb93fdd0aed624c83923c26bd76b 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt index ab9f2deb442f8b6e9a4559d662de8e6234c269f1..889698997e73fb93fdd0aed624c83923c26bd76b 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt index 54408f63cd3436bf11c146f687f7761f6fd2e93c..e4fbb33d05932a8e7ff8ebe0a6d6dcdc89c496c4 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt @@ -162,12 +162,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -239,12 +239,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt index 522f0a8f0b79d01871a1b23072aa79c8e04e6856..db8f03c2be7f5600f3ca8df48f3a191819b8a5af 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt index 76e0d220b2c9091b2cd70a248f427665e7eedd47..78b1a6b2bbd6691406f23800e20c09cbf2293a27 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt @@ -337,23 +337,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } } @@ -445,12 +445,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index 5eafc0fe04534fc684551488be77f8af5f9c1936..da4f14491678ca06393920994b7ddf1ca0802ee6 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -132,23 +132,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -305,23 +305,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -422,23 +422,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 17 } } } @@ -556,12 +556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -636,12 +636,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -717,12 +717,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -828,12 +828,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/internalParsing-expected.txt b/ets2panda/test/parser/ets/internalParsing-expected.txt index 63c475014317bf699b92bc5785f00b06f2be0fa4..a2fe1faccdd55da48ffec893504596803c38dc1f 100644 --- a/ets2panda/test/parser/ets/internalParsing-expected.txt +++ b/ets2panda/test/parser/ets/internalParsing-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt b/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt index e225935409c974d2a3a9497bb55de6c9daa33956..9c8de543ac0094195f72e82a9368f8251bfb76a4 100644 --- a/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt +++ b/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt b/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt index cccfa91bfb237216be2a0a65e0c2d123f87459d7..bc9900bde930e18dea026ae0db5bf707db5b03da 100644 --- a/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt +++ b/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt @@ -286,12 +286,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 54 } } }, @@ -745,12 +745,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 133 } } } diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index 2eb0ed8184ae5ddd698b42934f76de172a83b26e..d5c78505507622de816eb29934b2c123c3b49b33 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -396,23 +396,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } } @@ -563,12 +563,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } } diff --git a/ets2panda/test/parser/ets/literals-expected.txt b/ets2panda/test/parser/ets/literals-expected.txt index 102b4b5cf5793da386c5ffa5eb222a2a180740af..019093d519550c2c3fce3b09662c62afae81ba86 100644 --- a/ets2panda/test/parser/ets/literals-expected.txt +++ b/ets2panda/test/parser/ets/literals-expected.txt @@ -157,12 +157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -207,12 +207,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -257,12 +257,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -307,12 +307,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 } } }, @@ -357,12 +357,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 24 } } }, @@ -407,12 +407,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 21 } } }, @@ -457,12 +457,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 21 } } }, @@ -522,12 +522,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 22 } } }, @@ -572,12 +572,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 19 } } }, @@ -622,12 +622,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -672,12 +672,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 19 } } }, @@ -722,12 +722,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 20 } } }, @@ -772,12 +772,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, @@ -822,12 +822,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 17 } } }, @@ -915,12 +915,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 22 } } }, @@ -1008,12 +1008,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 28 } } }, @@ -1101,12 +1101,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 28 } } } diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index fe48855d5646fa0642363eda4a33acae5fac7f6d..f069f5a6a679ab99caee7be78a77b7c0c31c644c 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -243,23 +243,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, @@ -340,23 +340,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } } @@ -475,12 +475,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -552,12 +552,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 63b294b65cabc536d959139b79a669dbbacbc9b5..1c9ab91eeeac7352aace79b9b760748ca182065d 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -292,12 +292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 78a7b9c1a8d0f1bae13a38b1bc0e8bd8dd1f5f82..1891cfc564194d2f8b9d7038adff79c3ca03b7e2 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } } @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -292,12 +292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/nullableType-expected.txt b/ets2panda/test/parser/ets/nullableType-expected.txt index 4ffaa76dd684359644472e7adf7c6e4ac0783152..ed0d54068514e413f44c031d2e948014ed8deeff 100644 --- a/ets2panda/test/parser/ets/nullableType-expected.txt +++ b/ets2panda/test/parser/ets/nullableType-expected.txt @@ -958,12 +958,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 132, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 132, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/object-expected.txt b/ets2panda/test/parser/ets/object-expected.txt index d44e5d101d1718d1c02c7d60091edbff13e49162..9f1511caa9e1a0346b5142108441c96124fe7ba3 100644 --- a/ets2panda/test/parser/ets/object-expected.txt +++ b/ets2panda/test/parser/ets/object-expected.txt @@ -184,12 +184,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt index 756f1572dc51df08b3c8d4ddef31e8ceea094106..bf7e6b46de5daf47cc82e78ab51fb9b83eaf8580 100644 --- a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt +++ b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 28 } } }, @@ -263,23 +263,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, @@ -377,23 +377,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 39 } } } @@ -525,12 +525,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } }, @@ -633,12 +633,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -723,12 +723,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -831,12 +831,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt index 597585d0b1eefecbc5a5bba5ee268a9e46484900..2c046490ecfedd22b633e419f3eb37b98677be33 100644 --- a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -444,23 +444,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, @@ -531,23 +531,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 30 } } } @@ -666,12 +666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 } } }, @@ -747,12 +747,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt index 8aa877a567ea517f331b9f5f14301cb0d055753e..47d2b4e1241a24507e64380127f6f1c2680bc3de 100644 --- a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -521,23 +521,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 23, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, @@ -653,23 +653,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 43 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 44 } } } @@ -788,12 +788,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 } } }, @@ -914,12 +914,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 43 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt index 3bba741952961de68772d69182e696fb700ab0f7..3e7ff288e94a231fe72888e0eb4ed591a370d76e 100644 --- a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -444,23 +444,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, @@ -559,23 +559,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 33 } } }, @@ -674,23 +674,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 35 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 36 } } } @@ -809,12 +809,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 } } }, @@ -918,12 +918,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 32 } } }, @@ -967,12 +967,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt index dd1396ae0e6b1529feb4b40fe86c5c4073141b20..32bc14b3a4b55db92bda2c320d9de403f2147a19 100644 --- a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt +++ b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -275,23 +275,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } } @@ -383,12 +383,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -433,12 +433,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -483,12 +483,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -534,12 +534,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/predefined_types-expected.txt b/ets2panda/test/parser/ets/predefined_types-expected.txt index d2ef41f276e8c6c7af60cd0ddf4c208c3b04c0c2..1917db3b8842b16629c2f9391abcdb0ffb8e33ac 100644 --- a/ets2panda/test/parser/ets/predefined_types-expected.txt +++ b/ets2panda/test/parser/ets/predefined_types-expected.txt @@ -156,12 +156,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -205,12 +205,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -254,12 +254,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -303,12 +303,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, @@ -352,12 +352,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -401,12 +401,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 14 } } }, @@ -450,12 +450,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/property-access-field-1-expected.txt b/ets2panda/test/parser/ets/property-access-field-1-expected.txt index cd63a35ca3f673f3561a065d21271b4aa0349e17..786506feadd070852cd1dcb1c89045986fd7b231 100644 --- a/ets2panda/test/parser/ets/property-access-field-1-expected.txt +++ b/ets2panda/test/parser/ets/property-access-field-1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/property-access-field-2-expected.txt b/ets2panda/test/parser/ets/property-access-field-2-expected.txt index daabca2798b09bf2243f3a8d466c3482b31dfaeb..c9cce528be18588d97328e5f21b5156a794771c2 100644 --- a/ets2panda/test/parser/ets/property-access-field-2-expected.txt +++ b/ets2panda/test/parser/ets/property-access-field-2-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/return-expected.txt b/ets2panda/test/parser/ets/return-expected.txt index 75e777bf826819d99683549fe677322b2d42d548..ee83fa8590954398b414c31cfa2e74c94becba16 100644 --- a/ets2panda/test/parser/ets/return-expected.txt +++ b/ets2panda/test/parser/ets/return-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/setter_native-expected.txt b/ets2panda/test/parser/ets/setter_native-expected.txt index ba515f59a5bd535ed5985860ccdc8ed4332e32d9..a36ac4231486e9f480afa0f14d6552268db17c58 100644 --- a/ets2panda/test/parser/ets/setter_native-expected.txt +++ b/ets2panda/test/parser/ets/setter_native-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/setter_with_non_void-expected.txt b/ets2panda/test/parser/ets/setter_with_non_void-expected.txt index e0dd8b95dfebfd005adbd9b4f422ca66e25d4849..d346044787d7970a6dd03d7d99a5a386758f3fea 100644 --- a/ets2panda/test/parser/ets/setter_with_non_void-expected.txt +++ b/ets2panda/test/parser/ets/setter_with_non_void-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index 1f81b8c3616d84239c091cbf2251a74dc5758995..b75839eeb2747a4359414db7de8f4f03e8be5477 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, @@ -177,23 +177,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -233,23 +233,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 25 } } }, @@ -304,23 +304,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 35 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 36 } } }, @@ -360,23 +360,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -416,23 +416,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 20 } } }, @@ -472,23 +472,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 23 } } }, @@ -528,23 +528,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -585,23 +585,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 29, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 17 } } } @@ -692,12 +692,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -741,12 +741,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -790,12 +790,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 } } }, @@ -888,12 +888,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 } } }, @@ -937,12 +937,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 } } }, @@ -1014,12 +1014,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 } } }, @@ -1063,12 +1063,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 } } }, @@ -1112,12 +1112,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 14 } } }, @@ -1161,12 +1161,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 03becdb639ee516e35bdc4e2a833e1a27651e45a..657641c2443d16f5e35b06a8d4469fe9ac19ce13 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } } @@ -297,12 +297,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/struct_identifier-expected.txt b/ets2panda/test/parser/ets/struct_identifier-expected.txt index 3ea6f12b26f0e14b697ef21f26e5a313c595ecee..cfd8673216d5c3d28983eaf5b900a406a53159ba 100644 --- a/ets2panda/test/parser/ets/struct_identifier-expected.txt +++ b/ets2panda/test/parser/ets/struct_identifier-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } }, diff --git a/ets2panda/test/parser/ets/struct_init-expected.txt b/ets2panda/test/parser/ets/struct_init-expected.txt index ce12d14a1578e7edcf07c2f64b9e14ce4f19a3bb..68015c8f2f8b1ecdc26451d0caaf4268969ea4d6 100644 --- a/ets2panda/test/parser/ets/struct_init-expected.txt +++ b/ets2panda/test/parser/ets/struct_init-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, diff --git a/ets2panda/test/parser/ets/struct_static_initializer-expected.txt b/ets2panda/test/parser/ets/struct_static_initializer-expected.txt index 86b94856915fd61b4942aa15260c4ac61297dc54..1d09901886df78a5787cb5965ab0e3bbaaa96121 100644 --- a/ets2panda/test/parser/ets/struct_static_initializer-expected.txt +++ b/ets2panda/test/parser/ets/struct_static_initializer-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -556,12 +556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/struct_templete-expected.txt b/ets2panda/test/parser/ets/struct_templete-expected.txt index 5223d017d73c2e73079646d51e675860ff86ae73..5060c2b73b24c7c1345fe7a4e9af9b9775e6b4f7 100644 --- a/ets2panda/test/parser/ets/struct_templete-expected.txt +++ b/ets2panda/test/parser/ets/struct_templete-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt index a1f6f441709f98012c7b76d278741ba479e6ace9..a0429f6a7db7e3a089173aa136253133094a590e 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt index cffaacb12ff6d7553bb062aff8fd2cc1842620d3..04b54186be83e3fcdd5aeaf816dea2c58e7b2b34 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt index b4210967be804120b0e50db5e9eae783d581c525..0f99422e115d451281e74d7b5b26e20b74623338 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index 0d057e60f5737bd7675c77aa38ce115571497256..f34d7e3f9246eb67d65876ae8c128e8bd56ab57c 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index da9f79eae86b676bd051435fc935ed71952c2c34..3ef004f3ec9a6b0181d78255d6c875c3b60de6b3 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt index 9b68e099f815767b04466ea7a364597fa89ba5ac..cc9db9fc4a73b6404a9f3e753ccfc0c0c81514cb 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt index 4515834d1ca3ac63a4b520308a60725a192113e3..c37cacffebdfd380c90cdc1ad55f41fe2d790157 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt index 72fb18d07217ae10845664831d6e015c9bd02a1c..2ce1ff962ac981cf80603be3f45e0c24c4a9b352 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index a870370edbf4d77582dec8627cc1b56832d9946b..b80d1cd97c9239f52f71459d19eda0c19fd35b4e 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -291,23 +291,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } } @@ -399,12 +399,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -449,12 +449,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -572,12 +572,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue-expected.txt b/ets2panda/test/parser/ets/test_jsvalue-expected.txt index 9f9d588fe8353e2a9fe54d6c4cb3b400bb3895cd..f172336108f9f1c27fa523ff53efe64d4124ef69 100644 --- a/ets2panda/test/parser/ets/test_jsvalue-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue-expected.txt @@ -184,12 +184,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt index 435dd5eb18b46f600ac005bab5dd87f043ed49aa..59de21d316643ba4412ad6bb533b38326006b41f 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } } @@ -242,12 +242,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -291,12 +291,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt index b046e7b05299218614ef4fb73a88031287ede417..dfd10c05a70cb678eac98f913ed6c2dde59eb601 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt @@ -137,23 +137,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } } @@ -272,12 +272,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -349,12 +349,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt index fc03e2ef4a53b0e8fe9cc63697cac8b210ebc259..b19aae63841f98e1262b375be17e6061f97d1eb2 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt @@ -167,23 +167,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 47 } } } @@ -302,12 +302,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -379,12 +379,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index 5c564550d19d44a0774bc63c5045f33b63eb2009..20df64b662c0a1a355500af56dffb173b65c20bf 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -214,23 +214,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, @@ -385,23 +385,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 52 } } } @@ -520,12 +520,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -597,12 +597,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index 58e965b05166f8b1e019b1bc05d24a37052ebdae..203a0147ad78122484ca1943d0a1535679d7cac4 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } } @@ -270,12 +270,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -320,12 +320,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt index 8520e0bd7d5ae0e815a0c66772d6f8a36063336a..fba13eb71c47ee15f33656c8ef2708ad9bd50150 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, diff --git a/ets2panda/test/parser/ets/type_cast-expected.txt b/ets2panda/test/parser/ets/type_cast-expected.txt index f8965d9172a6034c67f5d6c0ef7d00f076bfad4b..cde9ff443ea1cbeafa4ca9a3593142d8d0c4df84 100644 --- a/ets2panda/test/parser/ets/type_cast-expected.txt +++ b/ets2panda/test/parser/ets/type_cast-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } }, @@ -279,12 +279,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 28 } } }, @@ -397,12 +397,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } }, @@ -460,12 +460,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 29 } } }, @@ -578,12 +578,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 31 } } }, @@ -696,12 +696,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/type_variance1-expected.txt b/ets2panda/test/parser/ets/type_variance1-expected.txt index 7006bc04a7b9cdc5fa1155d72fb7a50009e0a24a..526d6a2a596d5a2f79c9d894f7dd105a53196202 100644 --- a/ets2panda/test/parser/ets/type_variance1-expected.txt +++ b/ets2panda/test/parser/ets/type_variance1-expected.txt @@ -3245,12 +3245,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 52 } } }, diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index cd8baaf5044840ba2b685491b90ccb156169ad0e..9a9d965671f43a0614d6fbf981349d914768d60c 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -178,23 +178,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -250,23 +250,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -321,23 +321,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 } } }, @@ -393,23 +393,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, @@ -465,23 +465,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 } } }, @@ -521,23 +521,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 14 } } }, @@ -593,23 +593,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 23, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 12 } } }, @@ -665,23 +665,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 25, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 } } } @@ -773,12 +773,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -905,12 +905,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -970,12 +970,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -1036,12 +1036,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, @@ -1102,12 +1102,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -1152,12 +1152,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -1218,12 +1218,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 } } }, @@ -1268,12 +1268,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 15 } } }, @@ -1334,12 +1334,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 11 } } } diff --git a/ets2panda/test/parser/ets/unary_operations-expected.txt b/ets2panda/test/parser/ets/unary_operations-expected.txt index 685a1b84e0bcc96305addc11dc566510c0a54ada..4dcbbcdf600992a032c1eb9ecee891a2932e7571 100644 --- a/ets2panda/test/parser/ets/unary_operations-expected.txt +++ b/ets2panda/test/parser/ets/unary_operations-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } }, @@ -323,12 +323,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 33 } } }, @@ -430,12 +430,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 33 } } }, @@ -537,12 +537,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 34 } } }, @@ -644,12 +644,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 34 } } }, @@ -751,12 +751,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 33 } } }, @@ -814,12 +814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 31 } } }, @@ -921,12 +921,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 37 } } }, @@ -1028,12 +1028,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 34 } } }, @@ -1135,12 +1135,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 34 } } }, diff --git a/ets2panda/test/runtime/ets/assignment_lowering.ets b/ets2panda/test/runtime/ets/assignment_lowering.ets new file mode 100644 index 0000000000000000000000000000000000000000..75bbd8afd99dc0d06404023e421b1a5d68fbd492 --- /dev/null +++ b/ets2panda/test/runtime/ets/assignment_lowering.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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. + */ + +class B { + c: int = 11; + d: int = 33; + public constructor() { + this.c += 22; + this.d -= 44; + } +} + +function main(): void { + + let b = new B(); + assert (b.c == 33); + assert (b.d == -11); + + let x: int[] = [1, 2, 3]; + + for (let i: int = 0; i < 3; ++i) { + i <<= 2; + + x[i >> 2] *= 2; + i >>= 2; + } + + for (let i: int = 0; i < 3; ++i) { + assert (x[i] == (i + 1) * 2); + } +} diff --git a/ets2panda/test/unit/ast_dumper_test.cpp b/ets2panda/test/unit/ast_dumper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d38b78fe12935540b47fd79bef2131b805105ce --- /dev/null +++ b/ets2panda/test/unit/ast_dumper_test.cpp @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2021-2023 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. + */ + +#include +#include +#include "macros.h" + +#include "assembler/assembly-program.h" +#include "compiler/core/ASTVerifier.h" +#include "ir/astDump.h" +#include "ir/expressions/literals/stringLiteral.h" + +#include "bytecode_optimizer/bytecodeopt_options.h" +#include "compiler/compiler_logger.h" +#include "mem/arena_allocator.h" +#include "mem/pool_manager.h" +#include "es2panda.h" +#include "util/arktsconfig.h" +#include "util/generateBin.h" +#include "util/options.h" +#include "libpandabase/mem/mem.h" + +class ASTDumperTest : public testing::Test { +public: + ASTDumperTest() + { + constexpr auto COMPILER_SIZE = 268435456; + + panda::mem::MemConfig::Initialize(0, 0, COMPILER_SIZE, 0, 0, 0); + panda::PoolManager::Initialize(panda::PoolType::MMAP); + } + ~ASTDumperTest() override + { + panda::PoolManager::Finalize(); + panda::mem::MemConfig::Finalize(); + }; + + static panda::pandasm::Program *GetProgram(int argc, const char **argv, std::string_view file_name, + std::string_view src) + { + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return nullptr; + } + + panda::Logger::ComponentMask mask {}; + mask.set(panda::Logger::Component::ES2PANDA); + panda::Logger::InitializeStdLogging(panda::Logger::LevelFromString(options->LogLevel()), mask); + + panda::es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); + panda::es2panda::SourceFile input(file_name, src, options->ParseModule()); + + return compiler.Compile(input, options->CompilerOptions()); + } + + NO_COPY_SEMANTIC(ASTDumperTest); + NO_MOVE_SEMANTIC(ASTDumperTest); + +private: +}; + +TEST_F(ASTDumperTest, DumpJsonSimple) +{ + static constexpr std::string_view FILE_NAME = "dummy.ets"; + static constexpr std::string_view SRC = + "\ + function main(args: String[]): int {\ + let a: int = 2;\ + let b: int = 3;\ + return a + b;\ + }"; + + int argc = 0; + const char *argv = ""; + + auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; + + ASSERT_NE(program, nullptr); + + auto dump_str = program->JsonDump(); + + ASSERT_FALSE(dump_str.empty()); +} + +TEST_F(ASTDumperTest, DumpJsonUTF16Char) +{ + static constexpr std::string_view FILE_NAME = "dummy.ets"; + static constexpr std::string_view SRC = + "\ + function main(args: String[]): int {\ + let a: char = c'\\uDBFF';\ + let b: char = c'\\uDC00';\ + console.log(a);\ + console.log(b);\ + return 0;\ + }"; + + int argc = 0; + const char *argv = ""; + + auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; + + ASSERT_NE(program, nullptr); + + auto dump_str = program->JsonDump(); + + ASSERT_FALSE(dump_str.empty()); +} diff --git a/ets2panda/test/public/ast_verifier_test.cpp b/ets2panda/test/unit/public/ast_verifier_test.cpp similarity index 100% rename from ets2panda/test/public/ast_verifier_test.cpp rename to ets2panda/test/unit/public/ast_verifier_test.cpp diff --git a/ets2panda/test/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp similarity index 100% rename from ets2panda/test/public/es2panda_public_test.cpp rename to ets2panda/test/unit/public/es2panda_public_test.cpp diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index f0195c7dbcb05b58f1937f04574b15dbaa7a6c0a..aafd8d43e718abdef49471b48b332b09d574e6cc 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -42,8 +42,7 @@ #include "ir/ets/etsParameterExpression.h" #include "ir/module/importDeclaration.h" #include "lexer/token/letters.h" -#include -#include +#include "libpandabase/utils/utf.h" namespace panda::es2panda::util { // Helpers @@ -654,8 +653,8 @@ std::string Helpers::CreateEscapedString(const std::string &str) std::string Helpers::UTF16toUTF8(const char16_t c) { - std::wstring_convert, char16_t> convert {}; - return convert.to_bytes(c); + const utf::Utf8Char utf8_ch = utf::ConvertUtf16ToUtf8(c, 0, false); + return std::string(reinterpret_cast(utf8_ch.ch.data()), utf8_ch.n); } std::pair Helpers::SplitSignature(std::string_view signature) diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index f5d6b87d989a9251c759e0300d71a9ce9f92c19a..c7f2350ca873daa63d904e6b08960356591d56f9 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -66,6 +66,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg op_module("module", false, "Parse the input as module (JS only option)"); panda::PandArg op_parse_only("parse-only", false, "Parse the input only"); panda::PandArg op_dump_ast("dump-ast", false, "Dump the parsed AST"); + panda::PandArg op_dump_ast_only_silent( + "dump-ast-only-silent", false, "Dump parsed AST with all dumpers available but don't print to stdout"); panda::PandArg op_dump_checked_ast("dump-dynamic-ast", false, "Dump AST with synthetic nodes for dynamic languages"); panda::PandArg op_list_files("list-files", false, "Print names of files that are part of compilation"); @@ -98,6 +100,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&op_help); argparser_->Add(&op_module); argparser_->Add(&op_dump_ast); + argparser_->Add(&op_dump_ast_only_silent); argparser_->Add(&op_dump_checked_ast); argparser_->Add(&op_parse_only); argparser_->Add(&op_dump_assembly); @@ -290,6 +293,7 @@ bool Options::Parse(int argc, const char **argv) compiler_options_.ts_decl_out = op_ts_decl_out.GetValue(); compiler_options_.dump_asm = op_dump_assembly.GetValue(); compiler_options_.dump_ast = op_dump_ast.GetValue(); + compiler_options_.op_dump_ast_only_silent = op_dump_ast_only_silent.GetValue(); compiler_options_.dump_checked_ast = op_dump_checked_ast.GetValue(); compiler_options_.dump_debug_info = op_dump_debug_info.GetValue(); compiler_options_.is_debug = op_debug_info.GetValue(); diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index cd271713f1002ce6f728df4394d835ba25d759b4..d12f33d16ebc46442351abaf4cbce8080d666b16 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -133,6 +133,40 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allow_dynamic_na ThrowUnresolvableType(ident->Start(), name); } +void ETSBinder::ResolveReferencesForScope(ir::AstNode const *const parent, Scope *const scope) +{ + parent->Iterate([this, scope](auto *node) { ResolveReferenceForScope(node, scope); }); +} + +void ETSBinder::ResolveReferenceForScope(ir::AstNode *const node, Scope *const scope) +{ + switch (node->Type()) { + case ir::AstNodeType::IDENTIFIER: { + auto *ident = node->AsIdentifier(); + if (auto const res = scope->Find(ident->Name(), ResolveBindingOptions::ALL); res.variable != nullptr) { + ident->SetVariable(res.variable); + } + break; + } + case ir::AstNodeType::VARIABLE_DECLARATOR: { + auto scope_ctx = LexicalScope::Enter(this, scope); + BuildVarDeclarator(node->AsVariableDeclarator()); + break; + } + /* Maybe will be used + case ir::AstNodeType::BLOCK_STATEMENT: { + auto scope_ctx = LexicalScope::Enter(this, node->AsBlockStatement()->Scope()); + ResolveReferences(node); + break; + } + */ + default: { + ResolveReferencesForScope(node, scope); + break; + } + } +} + void ETSBinder::LookupIdentReference(ir::Identifier *ident) { const auto &name = ident->Name(); diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index 32b7feae10e0d0f8ee9cc872b07369f5db05bc42..82f49cd9ae5f2af13edfb44d2e5ef50da9a4109b 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2023 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 @@ -198,6 +198,9 @@ import * from "std/interop/js"; import * from "escompat"; )"; + void ResolveReferenceForScope(ir::AstNode *node, Scope *scope); + void ResolveReferencesForScope(ir::AstNode const *parent, Scope *scope); + private: void BuildClassDefinitionImpl(ir::ClassDefinition *class_def); void InitImplicitThisParam();