diff --git a/ets2panda/.clang-format b/ets2panda/.clang-format deleted file mode 100644 index 6a0a41e79546a5bafeb89fa50ae442f02ac2291d..0000000000000000000000000000000000000000 --- a/ets2panda/.clang-format +++ /dev/null @@ -1,114 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: Google -AccessModifierOffset: -4 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Left -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom -BreakBeforeInheritanceComma: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^' - Priority: 2 - - Regex: '^<.*\.h>' - Priority: 1 - - Regex: '^<.*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IncludeIsMainRegex: '([-_](test|unittest))?$' -IndentCaseLabels: true -IndentPPDirectives: None -IndentWidth: 4 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Right -ReflowComments: true -SortIncludes: false -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 4 -UseTab: Never -... - diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 9b136af98d206d34f057bbc599aabbcb7ff689e5..6f1bf9f6bd2dd3f2b542442d1c3bb6121e54ee3f 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -25,6 +25,16 @@ config("libes2panda_public_config") { } libes2panda_sources = [ + "binder/ASBinder.cpp", + "binder/ETSBinder.cpp", + "binder/JSBinder.cpp", + "binder/TSBinder.cpp", + "binder/TypedBinder.cpp", + "binder/binder.cpp", + "binder/declaration.cpp", + "binder/recordTable.cpp", + "binder/scope.cpp", + "binder/variable.cpp", "checker/ASchecker.cpp", "checker/ETSAnalyzer.cpp", "checker/ETSchecker.cpp", @@ -73,7 +83,6 @@ libes2panda_sources = [ "checker/types/ets/etsObjectType.cpp", "checker/types/ets/etsStringType.cpp", "checker/types/ets/etsTypeParameter.cpp", - "checker/types/ets/etsUnionType.cpp", "checker/types/ets/etsVoidType.cpp", "checker/types/ets/floatType.cpp", "checker/types/ets/intType.cpp", @@ -122,7 +131,6 @@ libes2panda_sources = [ "compiler/base/literals.cpp", "compiler/base/lreference.cpp", "compiler/base/optionalChain.cpp", - "compiler/core/ASTVerifier.cpp", "compiler/core/ETSCompiler.cpp", "compiler/core/ETSGen.cpp", "compiler/core/ETSemitter.cpp", @@ -156,7 +164,6 @@ libes2panda_sources = [ "compiler/lowering/checkerPhase.cpp", "compiler/lowering/ets/generateDeclarations.cpp", "compiler/lowering/ets/opAssignment.cpp", - "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", "compiler/lowering/util.cpp", "es2panda.cpp", @@ -194,7 +201,6 @@ libes2panda_sources = [ "ir/ets/etsStructDeclaration.cpp", "ir/ets/etsTypeReference.cpp", "ir/ets/etsTypeReferencePart.cpp", - "ir/ets/etsUnionType.cpp", "ir/ets/etsWildcardType.cpp", "ir/expression.cpp", "ir/expressions/arrayExpression.cpp", @@ -342,16 +348,6 @@ libes2panda_sources = [ "util/declgenEts2Ts.cpp", "util/helpers.cpp", "util/ustring.cpp", - "varbinder/ASBinder.cpp", - "varbinder/ETSBinder.cpp", - "varbinder/JSBinder.cpp", - "varbinder/TSBinder.cpp", - "varbinder/TypedBinder.cpp", - "varbinder/declaration.cpp", - "varbinder/recordTable.cpp", - "varbinder/scope.cpp", - "varbinder/varbinder.cpp", - "varbinder/variable.cpp", ] # libes2panda does not include bytecode optimizer, because it is used in diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 10bf1f40a62128dd0ec2bdf8f46a44782beb4946..e49880048b39a7862c1959de208a79d92c2719a7 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -83,16 +83,16 @@ panda_gen( set(ES2PANDA_LIB_SRC es2panda.cpp - varbinder/ASBinder.cpp - varbinder/TSBinder.cpp - varbinder/TypedBinder.cpp - varbinder/ETSBinder.cpp - varbinder/JSBinder.cpp - varbinder/varbinder.cpp - varbinder/declaration.cpp - varbinder/recordTable.cpp - varbinder/scope.cpp - varbinder/variable.cpp + binder/ASBinder.cpp + binder/TSBinder.cpp + binder/TypedBinder.cpp + binder/ETSBinder.cpp + binder/JSBinder.cpp + binder/binder.cpp + binder/declaration.cpp + binder/recordTable.cpp + binder/scope.cpp + binder/variable.cpp compiler/base/catchTable.cpp compiler/base/condition.cpp compiler/base/destructuring.cpp @@ -102,7 +102,6 @@ set(ES2PANDA_LIB_SRC compiler/base/literals.cpp compiler/base/lreference.cpp compiler/base/optionalChain.cpp - compiler/core/ASTVerifier.cpp compiler/core/codeGen.cpp compiler/core/compileJob.cpp compiler/core/compileQueue.cpp @@ -138,7 +137,6 @@ set(ES2PANDA_LIB_SRC compiler/lowering/util.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/opAssignment.cpp - compiler/lowering/ets/unionLowering.cpp ir/astDump.cpp ir/astNode.cpp ir/irnode.cpp @@ -242,7 +240,6 @@ set(ES2PANDA_LIB_SRC ir/ets/etsScript.cpp ir/ets/etsTypeReference.cpp ir/ets/etsTypeReferencePart.cpp - ir/ets/etsUnionType.cpp ir/ets/etsWildcardType.cpp ir/ets/etsImportSource.cpp ir/ts/tsAnyKeyword.cpp @@ -371,7 +368,6 @@ set(ES2PANDA_LIB_SRC checker/types/ets/etsObjectType.cpp checker/types/ets/etsStringType.cpp checker/types/ets/etsTypeParameter.cpp - checker/types/ets/etsUnionType.cpp checker/types/ets/etsVoidType.cpp checker/types/ets/wildcardType.cpp checker/types/ets/etsAsyncFuncReturnType.cpp diff --git a/ets2panda/varbinder/ASBinder.cpp b/ets2panda/binder/ASBinder.cpp similarity index 88% rename from ets2panda/varbinder/ASBinder.cpp rename to ets2panda/binder/ASBinder.cpp index 9d5171a950b657a968bc18d40bb040ac3ce57108..8a58d1c3e7dbad3a0c7c0240500a98935482e3ad 100644 --- a/ets2panda/varbinder/ASBinder.cpp +++ b/ets2panda/binder/ASBinder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,5 +15,5 @@ #include "ASBinder.h" -namespace panda::es2panda::varbinder { -} // namespace panda::es2panda::varbinder +namespace panda::es2panda::binder { +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/ASBinder.h b/ets2panda/binder/ASBinder.h similarity index 75% rename from ets2panda/varbinder/ASBinder.h rename to ets2panda/binder/ASBinder.h index b23e59db4cb00ac798c9f7be51695f13c7799892..edb51793c8b80ebcde5479772bb77d49082007b7 100644 --- a/ets2panda/varbinder/ASBinder.h +++ b/ets2panda/binder/ASBinder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_AS_VARBINDER_H -#define ES2PANDA_VARBINDER_AS_VARBINDER_H +#ifndef ES2PANDA_BINDER_AS_BINDER_H +#define ES2PANDA_BINDER_AS_BINDER_H -#include "varbinder/varbinder.h" +#include "binder/binder.h" -namespace panda::es2panda::varbinder { -class ASBinder : public VarBinder { +namespace panda::es2panda::binder { +class ASBinder : public Binder { public: - explicit ASBinder(ArenaAllocator *allocator) : VarBinder(allocator) {} + explicit ASBinder(ArenaAllocator *allocator) : Binder(allocator) {} NO_COPY_SEMANTIC(ASBinder); NO_MOVE_SEMANTIC(ASBinder); @@ -41,6 +41,6 @@ public: private: }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/binder/ETSBinder.cpp similarity index 74% rename from ets2panda/varbinder/ETSBinder.cpp rename to ets2panda/binder/ETSBinder.cpp index cd271713f1002ce6f728df4394d835ba25d759b4..7b1590d40085e503e98afcba5a2b3130d4c905b2 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/binder/ETSBinder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -59,7 +59,7 @@ #include "checker/types/type.h" #include "checker/types/ets/types.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { void ETSBinder::IdentifierAnalysis() { @@ -98,6 +98,7 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allow_dynamic_na while (iter != nullptr) { auto res = iter->Find(name, ResolveBindingOptions::DECLARATION | ResolveBindingOptions::TYPE_ALIASES); + if (res.variable == nullptr) { break; } @@ -198,9 +199,8 @@ void ETSBinder::ResolveInterfaceDeclaration(ir::TSInterfaceDeclaration *decl) ResolveReference(stmt); - auto field_var = - ResolvePropertyReference(stmt->AsClassProperty(), decl->Scope()->AsClassScope()) - ->FindLocal(stmt->AsClassProperty()->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); + auto field_var = ResolvePropertyReference(stmt->AsClassProperty(), decl->Scope()->AsClassScope()) + ->FindLocal(stmt->AsClassProperty()->Id()->Name()); field_var->AddFlag(VariableFlags::INITIALIZED); } @@ -307,9 +307,8 @@ void ETSBinder::BuildClassDefinitionImpl(ir::ClassDefinition *class_def) continue; } - auto field_var = - ResolvePropertyReference(stmt->AsClassProperty(), class_def->Scope()->AsClassScope()) - ->FindLocal(stmt->AsClassProperty()->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); + auto field_var = ResolvePropertyReference(stmt->AsClassProperty(), class_def->Scope()->AsClassScope()) + ->FindLocal(stmt->AsClassProperty()->Id()->Name()); field_var->AddFlag(VariableFlags::INITIALIZED); if (field_var->Declaration()->IsConstDecl() && stmt->AsClassProperty()->Value() == nullptr) { field_var->AddFlag(VariableFlags::EXPLICIT_INIT_REQUIRED); @@ -364,7 +363,7 @@ void ETSBinder::BuildLambdaObject(ir::AstNode *ref_node, ir::ClassDefinition *la auto bound_ctx = BoundContext(GetGlobalRecordTable(), lambda_object); const auto &lambda_body = lambda_object->Body(); - AddLambdaFunctionThisParam(lambda_body[lambda_body.size() - 2U]->AsMethodDefinition()->Function()); + AddLambdaFunctionThisParam(lambda_body[lambda_body.size() - 2]->AsMethodDefinition()->Function()); AddLambdaFunctionThisParam(lambda_body[lambda_body.size() - 1]->AsMethodDefinition()->Function()); LambdaObjects().insert({ref_node, {lambda_object, signature}}); @@ -393,8 +392,8 @@ void ETSBinder::AddDynamicSpecifiersToTopBindings(ir::AstNode *const specifier, return specifier->AsImportSpecifier()->Local()->Name(); }(); - auto *const decl = Allocator()->New(name, specifier); - auto *const var = Allocator()->New(decl, varbinder::VariableFlags::STATIC); + auto *const decl = Allocator()->New(name, specifier); + auto *const var = Allocator()->New(decl, binder::VariableFlags::STATIC); var->AddFlag(VariableFlags::INITIALIZED); dynamic_import_vars_.emplace(var, DynamicImportData {import, specifier, var}); @@ -402,152 +401,6 @@ void ETSBinder::AddDynamicSpecifiersToTopBindings(ir::AstNode *const specifier, TopScope()->InsertDynamicBinding(name, var); } -bool ETSBinder::AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *const specifier, - const varbinder::Scope::VariableMap &global_bindings, - const parser::Program *const import_program, - const varbinder::GlobalScope *const import_global_scope, - const ir::ETSImportDeclaration *const import) -{ - if (!specifier->IsImportNamespaceSpecifier()) { - return false; - } - const auto *const namespace_specifier = specifier->AsImportNamespaceSpecifier(); - auto insert_foreign_binding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamic_import_vars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; - - if (namespace_specifier->Local()->Name().Empty()) { - for (const auto [bindingName, var] : global_bindings) { - if (bindingName.Is(compiler::Signatures::ETS_GLOBAL)) { - const auto *const class_def = var->Declaration()->Node()->AsClassDeclaration()->Definition(); - ImportGlobalProperties(class_def); - continue; - } - - if (!import_global_scope->IsForeignBinding(bindingName) && - !var->Declaration()->Node()->IsDefaultExported()) { - insert_foreign_binding(bindingName, var); - } - } - - for (const auto [bindingName, var] : import_program->GlobalClassScope()->StaticMethodScope()->Bindings()) { - if (!var->Declaration()->Node()->IsDefaultExported()) { - insert_foreign_binding(bindingName, var); - } - } - - for (const auto [bindingName, var] : import_program->GlobalClassScope()->StaticFieldScope()->Bindings()) { - if (!var->Declaration()->Node()->IsDefaultExported()) { - insert_foreign_binding(bindingName, var); - } - } - } - - return true; -} - -Variable *ETSBinder::FindImportSpecifiersVariable(const util::StringView &imported, - const varbinder::Scope::VariableMap &global_bindings, - const ArenaVector &record_res, - const ir::StringLiteral *const import_path) -{ - auto found_var = global_bindings.find(imported); - if (found_var == global_bindings.end()) { - const auto &static_method_bindings = record_res.front()->GlobalClassScope()->StaticMethodScope()->Bindings(); - found_var = static_method_bindings.find(imported); - if (found_var != static_method_bindings.end()) { - return found_var->second; - } - bool found = false; - for (auto res : record_res) { - const auto &static_field_bindings = res->GlobalClassScope()->StaticFieldScope()->Bindings(); - found_var = static_field_bindings.find(imported); - if (found_var != static_field_bindings.end()) { - found = true; - found_var->second->AsLocalVariable()->AddFlag(VariableFlags::INITIALIZED); - break; - } - } - if (!found) { - ThrowError(import_path->Start(), "Cannot find imported element " + imported.Mutf8()); - } - } - - return found_var->second; -} - -bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, - const varbinder::Scope::VariableMap &global_bindings, - const ir::ETSImportDeclaration *const import, - const ArenaVector &record_res) -{ - if (!specifier->IsImportSpecifier()) { - return false; - } - const ir::StringLiteral *const import_path = import->Source(); - auto insert_foreign_binding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamic_import_vars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; - - const auto *const import_specifier = specifier->AsImportSpecifier(); - - if (!import_specifier->Imported()->IsIdentifier()) { - return true; - } - - const auto &imported = import_specifier->Imported()->AsIdentifier()->Name(); - - auto *const var = FindImportSpecifiersVariable(imported, global_bindings, record_res, import_path); - - const auto &local_name = [this, import_specifier, &imported, &import_path]() { - if (import_specifier->Local() != nullptr) { - auto fnc = [&import_path, &imported](const auto &saved_specifier) { - return import_path->Str() != saved_specifier.first && imported == saved_specifier.second; - }; - if (!std::any_of(import_specifiers_.begin(), import_specifiers_.end(), fnc)) { - TopScope()->EraseBinding(imported); - } - - import_specifiers_.push_back(std::make_pair(import_path->Str(), imported)); - - return import_specifier->Local()->Name(); - } - - return imported; - }(); - - if (var->Declaration()->Node()->IsDefaultExported()) { - ThrowError(import_path->Start(), "Use the default import syntax to import a default exported element"); - } - - insert_foreign_binding(local_name, var); - return true; -} - -varbinder::Variable *ETSBinder::FindStaticBinding(const ArenaVector &record_res, - const ir::StringLiteral *const import_path) -{ - auto predicate_func = [](const auto &item) { return item.second->Declaration()->Node()->IsDefaultExported(); }; - const auto &static_method_bindings = record_res.front()->GlobalClassScope()->StaticMethodScope()->Bindings(); - auto result = std::find_if(static_method_bindings.begin(), static_method_bindings.end(), predicate_func); - if (result == static_method_bindings.end()) { - const auto &static_field_bindings = record_res.front()->GlobalClassScope()->StaticFieldScope()->Bindings(); - result = std::find_if(static_field_bindings.begin(), static_field_bindings.end(), predicate_func); - if (result == static_field_bindings.end()) { - ThrowError(import_path->Start(), "Cannot find default imported element in the target"); - } - } - return result->second; -} - void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const ir::ETSImportDeclaration *const import) { const ir::StringLiteral *const import_path = import->Source(); @@ -563,6 +416,7 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i ? import_path->Str() : util::UString(import_path->Str().Mutf8() + import->Module()->Str().Mutf8(), Allocator()).View(); const auto record_res = ext_records.find(source_name); + if (record_res == ext_records.end()) { ThrowError(import_path->Start(), "Cannot find import: " + std::string(source_name)); } @@ -579,12 +433,98 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i TopScope()->InsertForeignBinding(name, var); }; - if (AddImportNamespaceSpecifiersToTopBindings(specifier, global_bindings, import_program, import_global_scope, - import)) { + + if (specifier->IsImportNamespaceSpecifier()) { + const auto *const namespace_specifier = specifier->AsImportNamespaceSpecifier(); + + if (namespace_specifier->Local()->Name().Empty()) { + for (const auto [bindingName, var] : global_bindings) { + if (bindingName.Is(compiler::Signatures::ETS_GLOBAL)) { + const auto *const class_def = var->Declaration()->Node()->AsClassDeclaration()->Definition(); + ImportGlobalProperties(class_def); + continue; + } + + if (!import_global_scope->IsForeignBinding(bindingName) && + !var->Declaration()->Node()->IsDefaultExported()) { + insert_foreign_binding(bindingName, var); + } + } + + for (const auto [bindingName, var] : import_program->GlobalClassScope()->StaticMethodScope()->Bindings()) { + if (!var->Declaration()->Node()->IsDefaultExported()) { + insert_foreign_binding(bindingName, var); + } + } + + for (const auto [bindingName, var] : import_program->GlobalClassScope()->StaticFieldScope()->Bindings()) { + if (!var->Declaration()->Node()->IsDefaultExported()) { + insert_foreign_binding(bindingName, var); + } + } + } + return; } - if (AddImportSpecifiersToTopBindings(specifier, global_bindings, import, record_res->second)) { + if (specifier->IsImportSpecifier()) { + const auto *const import_specifier = specifier->AsImportSpecifier(); + + if (!import_specifier->Imported()->IsIdentifier()) { + return; + } + + const auto &imported = import_specifier->Imported()->AsIdentifier()->Name(); + + auto *const var = [&]() { + auto found_var = global_bindings.find(imported); + if (found_var == global_bindings.end()) { + const auto &static_method_bindings = + record_res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings(); + found_var = static_method_bindings.find(imported); + if (found_var == static_method_bindings.end()) { + bool found = false; + for (auto res : record_res->second) { + const auto &static_field_bindings = res->GlobalClassScope()->StaticFieldScope()->Bindings(); + found_var = static_field_bindings.find(imported); + if (found_var != static_field_bindings.end()) { + found = true; + found_var->second->AsLocalVariable()->AddFlag(VariableFlags::INITIALIZED); + break; + } + } + if (!found) { + ThrowError(import_path->Start(), "Cannot find imported element " + imported.Mutf8()); + } + } + } + + return found_var->second; + }(); + + const auto &local_name = [this, import_specifier, &imported, &import_path]() { + if (import_specifier->Local() != nullptr) { + auto fnc = [&import_path, &imported](const auto &saved_specifier) { + return import_path->Str() != saved_specifier.first && imported == saved_specifier.second; + }; + + if (!std::any_of(import_specifiers_.begin(), import_specifiers_.end(), fnc)) { + TopScope()->EraseBinding(imported); + } + + import_specifiers_.push_back(std::make_pair(import_path->Str(), imported)); + + return import_specifier->Local()->Name(); + } + + return imported; + }(); + + if (var->Declaration()->Node()->IsDefaultExported()) { + ThrowError(import_path->Start(), "Use the default import syntax to import a default exported element"); + } + + insert_foreign_binding(local_name, var); return; } @@ -592,10 +532,21 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i auto predicate_func = [](const auto &item) { return item.second->Declaration()->Node()->IsDefaultExported(); }; auto item = std::find_if(global_bindings.begin(), global_bindings.end(), predicate_func); + if (item == global_bindings.end()) { - insert_foreign_binding(specifier->AsImportDefaultSpecifier()->Local()->Name(), - FindStaticBinding(record_res->second, import_path)); - return; + const auto &static_method_bindings = + record_res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings(); + item = std::find_if(static_method_bindings.begin(), static_method_bindings.end(), predicate_func); + + if (item == static_method_bindings.end()) { + const auto &static_field_bindings = + record_res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings(); + item = std::find_if(static_field_bindings.begin(), static_field_bindings.end(), predicate_func); + + if (item == static_field_bindings.end()) { + ThrowError(import_path->Start(), "Cannot find default imported element in the target"); + } + } } insert_foreign_binding(specifier->AsImportDefaultSpecifier()->Local()->Name(), item->second); @@ -665,6 +616,7 @@ bool ETSBinder::BuildInternalName(ir::ScriptFunction *script_func) bool is_external = record_table_->IsExternal(); bool compilable = script_func->Body() != nullptr && !is_external; + if (!compilable) { record_table_->Signatures().push_back(func_scope); } @@ -750,6 +702,7 @@ void ETSBinder::BuildLambdaObjectName(const ir::AstNode *ref_node) util::StringView assembler_name(lambda_class->Ident()->Name()); auto *program = static_cast(ref_node->GetTopStatement())->Program(); util::StringView prefix = program->GetPackageName(); + if (!prefix.Empty()) { util::UString full_path(prefix, Allocator()); full_path.Append('.'); @@ -832,6 +785,7 @@ void ETSBinder::BuildProgram() return stmt->IsClassDeclaration() && stmt->AsClassDeclaration()->Definition()->Ident()->Name().Is(compiler::Signatures::ETS_GLOBAL); }); + if (ets_global != stmts.end()) { const auto begin = std::find_if(stmts.rbegin(), stmts.rend(), [](const ir::Statement *stmt) { return stmt->IsETSImportDeclaration() || stmt->IsETSPackageDeclaration(); @@ -852,7 +806,7 @@ void ETSBinder::BuildExternalProgram(parser::Program *ext_program) auto *saved_record_table = record_table_; auto *saved_top_scope = TopScope(); - auto flags = Program()->VarBinder()->IsGenStdLib() ? RecordTableFlags::NONE : RecordTableFlags::EXTERNAL; + auto flags = Program()->Binder()->IsGenStdLib() ? RecordTableFlags::NONE : RecordTableFlags::EXTERNAL; auto *ext_record_table = Allocator()->New(Allocator(), ext_program, flags); external_record_table_.insert({ext_program, ext_record_table}); @@ -896,37 +850,6 @@ void ETSBinder::BuildImportDeclaration(ir::ETSImportDeclaration *decl) } } -bool ETSBinder::ImportGlobalPropertiesForNotDefaultedExports(varbinder::Variable *var, const util::StringView &name, - const ir::ClassElement *class_element) -{ - if (var->Declaration()->Node()->IsDefaultExported()) { - return false; - } - - const auto ins_res = TopScope()->InsertForeignBinding(name, var); - if (!(!ins_res.second && ins_res.first != TopScope()->Bindings().end()) || !(ins_res.first->second != var)) { - return true; - } - if (ins_res.first->second->Declaration()->IsFunctionDecl() && var->Declaration()->IsFunctionDecl()) { - auto *const current_node = ins_res.first->second->Declaration()->Node(); - auto *const method = var->Declaration()->Node()->AsMethodDefinition(); - if (!current_node->AsMethodDefinition()->HasOverload(method)) { - current_node->AsMethodDefinition()->AddOverload(method); - method->Function()->Id()->SetVariable(ins_res.first->second); - method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - } - return true; - } - - auto str = util::Helpers::AppendAll("Variable '", name.Utf8(), "'"); - if (ins_res.first->second->Declaration()->Type() == var->Declaration()->Type()) { - str += " is already defined."; - } else { - str += " is already defined with different type."; - } - ThrowError(class_element->Id()->Start(), str); -} - void ETSBinder::ImportGlobalProperties(const ir::ClassDefinition *const class_def) { const auto scope_ctx = LexicalScope::Enter(this, class_def->Scope()->AsClassScope()); @@ -943,8 +866,34 @@ void ETSBinder::ImportGlobalProperties(const ir::ClassDefinition *const class_de auto *const var = scope_ctx.GetScope()->FindLocal(name, ResolveBindingOptions::ALL); ASSERT(var != nullptr); - if (ImportGlobalPropertiesForNotDefaultedExports(var, name, class_element)) { - return; + if (!var->Declaration()->Node()->IsDefaultExported()) { + const auto ins_res = TopScope()->InsertForeignBinding(name, var); + if (!ins_res.second && ins_res.first != TopScope()->Bindings().end()) { + if (ins_res.first->second != var) { + if (ins_res.first->second->Declaration()->IsFunctionDecl() && + var->Declaration()->IsFunctionDecl()) { + auto *const current_node = ins_res.first->second->Declaration()->Node(); + auto *const method = var->Declaration()->Node()->AsMethodDefinition(); + + if (!current_node->AsMethodDefinition()->HasOverload(method)) { + current_node->AsMethodDefinition()->AddOverload(method); + method->Function()->Id()->SetVariable(ins_res.first->second); + method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); + } + + return; + } + + auto str = util::Helpers::AppendAll("Variable '", name.Utf8(), "'"); + if (ins_res.first->second->Declaration()->Type() == var->Declaration()->Type()) { + str += " is already defined."; + } else { + str += " is already defined with different type."; + } + + ThrowError(class_element->Id()->Start(), str); + } + } } } } @@ -979,4 +928,4 @@ bool ETSBinder::IsDynamicNamespaceVariable(const Variable *var) const return data->specifier->IsImportNamespaceSpecifier(); } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/binder/ETSBinder.h similarity index 81% rename from ets2panda/varbinder/ETSBinder.h rename to ets2panda/binder/ETSBinder.h index 32b7feae10e0d0f8ee9cc872b07369f5db05bc42..481b2347103dc8ef96c0586fe6ed53e9eba99c73 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/binder/ETSBinder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_ETSBINDER_H -#define ES2PANDA_VARBINDER_ETSBINDER_H +#ifndef ES2PANDA_BINDER_ETS_BINDER_H +#define ES2PANDA_BINDER_ETS_BINDER_H -#include "varbinder/TypedBinder.h" -#include "varbinder/recordTable.h" +#include "binder/TypedBinder.h" +#include "binder/recordTable.h" #include "ir/ets/etsImportDeclaration.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { using ComputedLambdaObjects = ArenaMap>; @@ -119,19 +119,6 @@ public: void BuildImportDeclaration(ir::ETSImportDeclaration *decl); void BuildETSNewClassInstanceExpression(ir::ETSNewClassInstanceExpression *class_instance); void AddSpecifiersToTopBindings(ir::AstNode *specifier, const ir::ETSImportDeclaration *import); - bool AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *specifier, - const varbinder::Scope::VariableMap &global_bindings, - const parser::Program *import_program, - const varbinder::GlobalScope *import_global_scope, - const ir::ETSImportDeclaration *import); - bool AddImportSpecifiersToTopBindings(ir::AstNode *specifier, const varbinder::Scope::VariableMap &global_bindings, - const ir::ETSImportDeclaration *import, - const ArenaVector &record_res); - Variable *FindImportSpecifiersVariable(const util::StringView &imported, - const varbinder::Scope::VariableMap &global_bindings, - const ArenaVector &record_res, - const ir::StringLiteral *import_path); - Variable *FindStaticBinding(const ArenaVector &record_res, const ir::StringLiteral *import_path); void AddDynamicSpecifiersToTopBindings(ir::AstNode *specifier, const ir::ETSImportDeclaration *import); void ResolveInterfaceDeclaration(ir::TSInterfaceDeclaration *decl); @@ -203,8 +190,6 @@ private: void InitImplicitThisParam(); void HandleStarImport(ir::TSQualifiedName *import_name, util::StringView full_path); void ImportGlobalProperties(const ir::ClassDefinition *class_def); - bool ImportGlobalPropertiesForNotDefaultedExports(varbinder::Variable *var, const util::StringView &name, - const ir::ClassElement *class_element); RecordTable global_record_table_; RecordTable *record_table_; @@ -218,6 +203,6 @@ private: ir::AstNode *default_export_ {}; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/JSBinder.cpp b/ets2panda/binder/JSBinder.cpp similarity index 88% rename from ets2panda/varbinder/JSBinder.cpp rename to ets2panda/binder/JSBinder.cpp index 58e847748c0e3e70033fd94a759650a4e26b55cb..1e1ead59219b90db78133fad3421ceccaaf4bb64 100644 --- a/ets2panda/varbinder/JSBinder.cpp +++ b/ets2panda/binder/JSBinder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,5 +15,5 @@ #include "JSBinder.h" -namespace panda::es2panda::varbinder { -} // namespace panda::es2panda::varbinder +namespace panda::es2panda::binder { +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/JSBinder.h b/ets2panda/binder/JSBinder.h similarity index 69% rename from ets2panda/varbinder/JSBinder.h rename to ets2panda/binder/JSBinder.h index 0b94c31ee0b38b1eba1f2e1ab5dfc075aa0e721e..0768f3bcc6cb5f07c1568dada9a469527e5c784b 100644 --- a/ets2panda/varbinder/JSBinder.h +++ b/ets2panda/binder/JSBinder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_JS_VARBINDER_H -#define ES2PANDA_VARBINDER_JS_VARBINDER_H +#ifndef ES2PANDA_BINDER_JS_BINDER_H +#define ES2PANDA_BINDER_JS_BINDER_H -#include "varbinder/varbinder.h" +#include "binder/binder.h" -namespace panda::es2panda::varbinder { -class JSBinder : public VarBinder { +namespace panda::es2panda::binder { +class JSBinder : public Binder { public: - explicit JSBinder(ArenaAllocator *allocator) : VarBinder(allocator) {} + explicit JSBinder(ArenaAllocator *allocator) : Binder(allocator) {} NO_COPY_SEMANTIC(JSBinder); NO_MOVE_SEMANTIC(JSBinder); @@ -29,6 +29,6 @@ public: private: }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/TSBinder.cpp b/ets2panda/binder/TSBinder.cpp similarity index 88% rename from ets2panda/varbinder/TSBinder.cpp rename to ets2panda/binder/TSBinder.cpp index 29139e100ecf120ec82a466f02a75308d1238284..c33d7d0ca6f55160ab73d04845703d0295e57ef7 100644 --- a/ets2panda/varbinder/TSBinder.cpp +++ b/ets2panda/binder/TSBinder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,5 +15,5 @@ #include "TSBinder.h" -namespace panda::es2panda::varbinder { -} // namespace panda::es2panda::varbinder +namespace panda::es2panda::binder { +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/TSBinder.h b/ets2panda/binder/TSBinder.h similarity index 83% rename from ets2panda/varbinder/TSBinder.h rename to ets2panda/binder/TSBinder.h index 943a515a271a7d75949c17c884c50461d93f234b..da79cc8b92e9b4dfe14c0977df6d2c72f467a9c5 100644 --- a/ets2panda/varbinder/TSBinder.h +++ b/ets2panda/binder/TSBinder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -13,12 +13,12 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_TS_VARBINDER_H -#define ES2PANDA_VARBINDER_TS_VARBINDER_H +#ifndef ES2PANDA_BINDER_TS_BINDER_H +#define ES2PANDA_BINDER_TS_BINDER_H -#include "varbinder/TypedBinder.h" +#include "binder/TypedBinder.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class TSBinder : public TypedBinder { public: explicit TSBinder(ArenaAllocator *allocator) : TypedBinder(allocator) {} @@ -39,6 +39,6 @@ public: protected: }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/TypedBinder.cpp b/ets2panda/binder/TypedBinder.cpp similarity index 96% rename from ets2panda/varbinder/TypedBinder.cpp rename to ets2panda/binder/TypedBinder.cpp index b1ec180dc5ab71ec78336393fb8ce43b0d68d9ed..0c81a1617f02788132f2d3b0522803d2201b6491 100644 --- a/ets2panda/varbinder/TypedBinder.cpp +++ b/ets2panda/binder/TypedBinder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -20,7 +20,7 @@ #include "ir/ts/tsConstructorType.h" #include "ir/ets/etsFunctionType.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { void TypedBinder::BuildSignatureDeclarationBaseParams(ir::AstNode *type_node) { @@ -79,4 +79,4 @@ void TypedBinder::HandleCustomNodes(ir::AstNode *child_node) } } } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/TypedBinder.h b/ets2panda/binder/TypedBinder.h similarity index 73% rename from ets2panda/varbinder/TypedBinder.h rename to ets2panda/binder/TypedBinder.h index 3b3d8c35208c6f6a1608affdee32ff56dc1d485e..254732d0935549588b9bd5cdbb887b13497a603e 100644 --- a/ets2panda/varbinder/TypedBinder.h +++ b/ets2panda/binder/TypedBinder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_TYPED_VARBINDER_H -#define ES2PANDA_VARBINDER_TYPED_VARBINDER_H +#ifndef ES2PANDA_BINDER_TYPED_BINDER_H +#define ES2PANDA_BINDER_TYPED_BINDER_H -#include "varbinder/varbinder.h" +#include "binder/binder.h" -namespace panda::es2panda::varbinder { -class TypedBinder : public VarBinder { +namespace panda::es2panda::binder { +class TypedBinder : public Binder { public: - explicit TypedBinder(ArenaAllocator *allocator) : VarBinder(allocator) {} + explicit TypedBinder(ArenaAllocator *allocator) : Binder(allocator) {} NO_COPY_SEMANTIC(TypedBinder); NO_MOVE_SEMANTIC(TypedBinder); @@ -31,6 +31,6 @@ protected: void HandleCustomNodes(ir::AstNode *child_node) override; void BuildSignatureDeclarationBaseParams([[maybe_unused]] ir::AstNode *type_node) override; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/varbinder.cpp b/ets2panda/binder/binder.cpp similarity index 83% rename from ets2panda/varbinder/varbinder.cpp rename to ets2panda/binder/binder.cpp index f9c6088996ed7c3fa82050b6b4877a0985bf21a4..2c0650c5c6d81d4963b2f2582df6782f774b08fb 100644 --- a/ets2panda/varbinder/varbinder.cpp +++ b/ets2panda/binder/binder.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ -#include "varbinder.h" +#include "binder.h" -#include "varbinder/privateBinding.h" +#include "binder/privateBinding.h" #include "parser/program/program.h" #include "util/helpers.h" -#include "varbinder/scope.h" -#include "varbinder/tsBinding.h" +#include "binder/scope.h" +#include "binder/tsBinding.h" #include "compiler/core/compilerContext.h" #include "es2panda.h" #include "ir/astNode.h" @@ -58,8 +58,8 @@ #include "ir/base/tsSignatureDeclaration.h" #include "ir/base/tsMethodSignature.h" -namespace panda::es2panda::varbinder { -void VarBinder::InitTopScope() +namespace panda::es2panda::binder { +void Binder::InitTopScope() { if (program_->Kind() == parser::ScriptKind::MODULE) { top_scope_ = Allocator()->New(Allocator()); @@ -71,7 +71,7 @@ void VarBinder::InitTopScope() var_scope_ = top_scope_; } -std::tuple VarBinder::AddParamDecl(ir::AstNode *param) +std::tuple Binder::AddParamDecl(ir::AstNode *param) { ASSERT(scope_->IsFunctionParamScope() || scope_->IsCatchParamScope()); auto [decl, node, var] = static_cast(scope_)->AddParamDecl(Allocator(), param); @@ -83,42 +83,42 @@ std::tuple VarBinder::AddParamDecl(ir::AstNode *par ThrowRedeclaration(node->Start(), decl->Name()); } -void VarBinder::ThrowRedeclaration(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowRedeclaration(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Variable '" << name << "' has already been declared."; ThrowError(pos, ss.str()); } -void VarBinder::ThrowUnresolvableVariable(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowUnresolvableVariable(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Cannot find variable '" << name << "'."; ThrowError(pos, ss.str()); } -void VarBinder::ThrowUnresolvableType(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowUnresolvableType(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Cannot find type '" << name << "'."; ThrowError(pos, ss.str()); } -void VarBinder::ThrowTDZ(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowTDZ(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Variable '" << name << "' is accessed before it's initialization."; ThrowError(pos, ss.str()); } -void VarBinder::ThrowInvalidCapture(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowInvalidCapture(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Cannot capture variable'" << name << "'."; ThrowError(pos, ss.str()); } -void VarBinder::ThrowPrivateFieldMismatch(const lexer::SourcePosition &pos, const util::StringView &name) const +void Binder::ThrowPrivateFieldMismatch(const lexer::SourcePosition &pos, const util::StringView &name) const { std::stringstream ss; ss << "Private field '" << name << "' must be declared in an enclosing class"; @@ -126,7 +126,7 @@ void VarBinder::ThrowPrivateFieldMismatch(const lexer::SourcePosition &pos, cons ThrowError(pos, ss.str()); } -void VarBinder::ThrowError(const lexer::SourcePosition &pos, const std::string_view &msg) const +void Binder::ThrowError(const lexer::SourcePosition &pos, const std::string_view &msg) const { lexer::LineIndex index(program_->SourceCode()); lexer::SourceLocation loc = index.GetLocation(pos); @@ -134,7 +134,7 @@ void VarBinder::ThrowError(const lexer::SourcePosition &pos, const std::string_v throw Error(ErrorType::SYNTAX, program_->SourceFile().Utf8(), msg, loc.line, loc.col); } -void VarBinder::IdentifierAnalysis() +void Binder::IdentifierAnalysis() { ASSERT(program_->Ast()); ASSERT(scope_ == top_scope_); @@ -150,7 +150,7 @@ void VarBinder::IdentifierAnalysis() AddMandatoryParams(); } -void VarBinder::LookupReference(const util::StringView &name) +void Binder::LookupReference(const util::StringView &name) { auto res = scope_->Find(name); if (res.level == 0) { @@ -161,27 +161,7 @@ void VarBinder::LookupReference(const util::StringView &name) res.variable->SetLexical(res.scope); } -bool VarBinder::InstantiateArgumentsImpl(Scope **scope, Scope *iter, const ir::AstNode *node) -{ - if (node->AsScriptFunction()->IsArrow()) { - return false; - } - auto *arguments_variable = - (*scope)->AddDecl(Allocator(), FUNCTION_ARGUMENTS, VariableFlags::INITIALIZED); - if (iter->IsFunctionParamScope()) { - if (arguments_variable == nullptr) { - return true; - } - - *scope = iter->AsFunctionParamScope()->GetFunctionScope(); - (*scope)->InsertBinding(arguments_variable->Name(), arguments_variable); - } - - (*scope)->AddFlag(ScopeFlags::USE_ARGS); - return true; -} - -void VarBinder::InstantiateArguments() +void Binder::InstantiateArguments() { auto *iter = scope_; while (true) { @@ -198,7 +178,21 @@ void VarBinder::InstantiateArguments() break; } - if (InstantiateArgumentsImpl(&scope, iter, node)) { + if (!node->AsScriptFunction()->IsArrow()) { + auto *arguments_variable = + scope->AddDecl(Allocator(), FUNCTION_ARGUMENTS, VariableFlags::INITIALIZED); + + if (iter->IsFunctionParamScope()) { + if (arguments_variable == nullptr) { + break; + } + + scope = iter->AsFunctionParamScope()->GetFunctionScope(); + scope->InsertBinding(arguments_variable->Name(), arguments_variable); + } + + scope->AddFlag(ScopeFlags::USE_ARGS); + break; } @@ -206,7 +200,7 @@ void VarBinder::InstantiateArguments() } } -void VarBinder::PropagateDirectEval() const +void Binder::PropagateDirectEval() const { auto *iter = scope_; @@ -219,13 +213,13 @@ void VarBinder::PropagateDirectEval() const } while (iter != nullptr); } -void VarBinder::InstantiatePrivateContext(const ir::Identifier *ident) const +void Binder::InstantiatePrivateContext(const ir::Identifier *ident) const { auto *class_def = util::Helpers::GetContainingClassDefinition(ident); while (class_def != nullptr) { auto *scope = class_def->Scope(); - Variable *variable = scope->FindLocal(class_def->PrivateId(), varbinder::ResolveBindingOptions::BINDINGS); + Variable *variable = scope->FindLocal(class_def->PrivateId()); if (!variable->HasFlag(VariableFlags::INITIALIZED)) { break; @@ -242,7 +236,7 @@ void VarBinder::InstantiatePrivateContext(const ir::Identifier *ident) const ThrowPrivateFieldMismatch(ident->Start(), ident->Name()); } -void VarBinder::LookupIdentReference(ir::Identifier *ident) +void Binder::LookupIdentReference(ir::Identifier *ident) { if (!ident->IsReference()) { return; @@ -274,7 +268,7 @@ void VarBinder::LookupIdentReference(ir::Identifier *ident) ident->SetVariable(res.variable); } -util::StringView VarBinder::BuildFunctionName(util::StringView name, uint32_t idx) +util::StringView Binder::BuildFunctionName(util::StringView name, uint32_t idx) { std::stringstream ss; ss << "func_" << name << "_" << std::to_string(idx); @@ -283,7 +277,7 @@ util::StringView VarBinder::BuildFunctionName(util::StringView name, uint32_t id return internal_name.View(); } -bool VarBinder::BuildInternalName(ir::ScriptFunction *script_func) +bool Binder::BuildInternalName(ir::ScriptFunction *script_func) { auto *func_scope = script_func->Scope(); auto name = util::Helpers::FunctionName(Allocator(), script_func); @@ -295,7 +289,7 @@ bool VarBinder::BuildInternalName(ir::ScriptFunction *script_func) return !script_func->IsOverload(); } -void VarBinder::BuildVarDeclaratorId(ir::AstNode *child_node) +void Binder::BuildVarDeclaratorId(ir::AstNode *child_node) { switch (child_node->Type()) { case ir::AstNodeType::IDENTIFIER: { @@ -306,7 +300,7 @@ void VarBinder::BuildVarDeclaratorId(ir::AstNode *child_node) break; } - auto *variable = scope_->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); + auto *variable = scope_->FindLocal(name); ident->SetVariable(variable); BuildSignatureDeclarationBaseParams(ident->TypeAnnotation()); variable->AddFlag(VariableFlags::INITIALIZED); @@ -351,7 +345,7 @@ void VarBinder::BuildVarDeclaratorId(ir::AstNode *child_node) } } -void VarBinder::BuildVarDeclarator(ir::VariableDeclarator *var_decl) +void Binder::BuildVarDeclarator(ir::VariableDeclarator *var_decl) { if (var_decl->Parent()->AsVariableDeclaration()->Kind() == ir::VariableDeclaration::VariableDeclarationKind::VAR) { ResolveReferences(var_decl); @@ -365,7 +359,7 @@ void VarBinder::BuildVarDeclarator(ir::VariableDeclarator *var_decl) BuildVarDeclaratorId(var_decl->Id()); } -void VarBinder::BuildClassProperty(const ir::ClassProperty *prop) +void Binder::BuildClassProperty(const ir::ClassProperty *prop) { const ir::ScriptFunction *ctor = util::Helpers::GetContainingConstructor(prop); auto scope_ctx = LexicalScope::Enter(this, ctor->Scope()); @@ -373,7 +367,7 @@ void VarBinder::BuildClassProperty(const ir::ClassProperty *prop) ResolveReferences(prop); } -void VarBinder::InitializeClassBinding(ir::ClassDefinition *class_def) +void Binder::InitializeClassBinding(ir::ClassDefinition *class_def) { auto res = scope_->Find(class_def->Ident()->Name()); @@ -381,7 +375,7 @@ void VarBinder::InitializeClassBinding(ir::ClassDefinition *class_def) res.variable->AddFlag(VariableFlags::INITIALIZED); } -void VarBinder::InitializeClassIdent(ir::ClassDefinition *class_def) +void Binder::InitializeClassIdent(ir::ClassDefinition *class_def) { auto res = scope_->Find(class_def->Ident()->Name()); @@ -389,7 +383,7 @@ void VarBinder::InitializeClassIdent(ir::ClassDefinition *class_def) res.variable->AddFlag(VariableFlags::INITIALIZED); } -void VarBinder::BuildClassDefinition(ir::ClassDefinition *class_def) +void Binder::BuildClassDefinition(ir::ClassDefinition *class_def) { if (class_def->Parent()->IsClassDeclaration() || class_def->Parent()->IsETSStructDeclaration()) { InitializeClassBinding(class_def); @@ -401,7 +395,7 @@ void VarBinder::BuildClassDefinition(ir::ClassDefinition *class_def) ResolveReference(class_def->Super()); } - Variable *variable = scope_->FindLocal(class_def->PrivateId(), varbinder::ResolveBindingOptions::BINDINGS); + Variable *variable = scope_->FindLocal(class_def->PrivateId()); variable->AddFlag(VariableFlags::INITIALIZED); if (class_def->Ident() != nullptr) { @@ -415,7 +409,7 @@ void VarBinder::BuildClassDefinition(ir::ClassDefinition *class_def) } } -void VarBinder::BuildForUpdateLoop(ir::ForUpdateStatement *for_update_stmt) +void Binder::BuildForUpdateLoop(ir::ForUpdateStatement *for_update_stmt) { auto *loop_scope = for_update_stmt->Scope(); @@ -440,8 +434,8 @@ void VarBinder::BuildForUpdateLoop(ir::ForUpdateStatement *for_update_stmt) loop_ctx.GetScope()->ConvertToVariableScope(Allocator()); } -void VarBinder::BuildForInOfLoop(varbinder::LoopScope *loop_scope, ir::AstNode *left, ir::Expression *right, - ir::Statement *body) +void Binder::BuildForInOfLoop(binder::LoopScope *loop_scope, ir::AstNode *left, ir::Expression *right, + ir::Statement *body) { auto decl_scope_ctx = LexicalScope::Enter(this, loop_scope->DeclScope()); @@ -454,7 +448,7 @@ void VarBinder::BuildForInOfLoop(varbinder::LoopScope *loop_scope, ir::AstNode * loop_ctx.GetScope()->ConvertToVariableScope(Allocator()); } -void VarBinder::BuildCatchClause(ir::CatchClause *catch_clause_stmt) +void Binder::BuildCatchClause(ir::CatchClause *catch_clause_stmt) { if (catch_clause_stmt->Param() != nullptr) { auto param_scope_ctx = LexicalScope::Enter(this, catch_clause_stmt->Scope()->ParamScope()); @@ -465,7 +459,7 @@ void VarBinder::BuildCatchClause(ir::CatchClause *catch_clause_stmt) ResolveReference(catch_clause_stmt->Body()); } -void VarBinder::AddCompilableFunction(ir::ScriptFunction *func) +void Binder::AddCompilableFunction(ir::ScriptFunction *func) { if (func->IsArrow()) { VariableScope *outer_var_scope = scope_->EnclosingVariableScope(); @@ -475,12 +469,12 @@ void VarBinder::AddCompilableFunction(ir::ScriptFunction *func) AddCompilableFunctionScope(func->Scope()); } -void VarBinder::AddCompilableFunctionScope(varbinder::FunctionScope *func_scope) +void Binder::AddCompilableFunctionScope(binder::FunctionScope *func_scope) { function_scopes_.push_back(func_scope); } -void VarBinder::VisitScriptFunction(ir::ScriptFunction *func) +void Binder::VisitScriptFunction(ir::ScriptFunction *func) { auto *func_scope = func->Scope(); @@ -509,7 +503,7 @@ void VarBinder::VisitScriptFunction(ir::ScriptFunction *func) } } -void VarBinder::VisitScriptFunctionWithPotentialTypeParams(ir::ScriptFunction *func) +void Binder::VisitScriptFunctionWithPotentialTypeParams(ir::ScriptFunction *func) { if (func->TypeParams() != nullptr) { auto type_param_scope_ctx = LexicalScope::Enter(this, func->TypeParams()->Scope()); @@ -520,7 +514,7 @@ void VarBinder::VisitScriptFunctionWithPotentialTypeParams(ir::ScriptFunction *f VisitScriptFunction(func); } -void VarBinder::ResolveReference(ir::AstNode *child_node) +void Binder::ResolveReference(ir::AstNode *child_node) { switch (child_node->Type()) { case ir::AstNodeType::IDENTIFIER: { @@ -610,12 +604,12 @@ void VarBinder::ResolveReference(ir::AstNode *child_node) } } -void VarBinder::ResolveReferences(const ir::AstNode *parent) +void Binder::ResolveReferences(const ir::AstNode *parent) { parent->Iterate([this](auto *child_node) { ResolveReference(child_node); }); } -LocalVariable *VarBinder::AddMandatoryParam(const std::string_view &name) +LocalVariable *Binder::AddMandatoryParam(const std::string_view &name) { ASSERT(scope_->IsFunctionParamScope()); @@ -631,7 +625,7 @@ LocalVariable *VarBinder::AddMandatoryParam(const std::string_view &name) return param; } -void VarBinder::LookUpMandatoryReferences(const FunctionScope *func_scope, bool need_lexical_func_obj) +void Binder::LookUpMandatoryReferences(const FunctionScope *func_scope, bool need_lexical_func_obj) { LookupReference(MANDATORY_PARAM_NEW_TARGET); LookupReference(MANDATORY_PARAM_THIS); @@ -645,7 +639,7 @@ void VarBinder::LookUpMandatoryReferences(const FunctionScope *func_scope, bool } } -void VarBinder::AddMandatoryParams() +void Binder::AddMandatoryParams() { ASSERT(scope_ == top_scope_); ASSERT(!function_scopes_.empty()); @@ -696,4 +690,4 @@ void VarBinder::AddMandatoryParams() LookUpMandatoryReferences(func_scope, lexical_function_object); } } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/varbinder.h b/ets2panda/binder/binder.h similarity index 79% rename from ets2panda/varbinder/varbinder.h rename to ets2panda/binder/binder.h index b92e05a6f1dd764c984f711b94cd6c2a8c32cbbd..fdeb9556c554988d403d3ee0cd9a2c47062a1eac 100644 --- a/ets2panda/varbinder/varbinder.h +++ b/ets2panda/binder/binder.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_VARBINDER_H -#define ES2PANDA_VARBINDER_VARBINDER_H +#ifndef ES2PANDA_BINDER_BINDER_H +#define ES2PANDA_BINDER_BINDER_H -#include "varbinder/scope.h" -#include "varbinder/variableFlags.h" +#include "binder/scope.h" +#include "binder/variableFlags.h" #include "lexer/token/sourceLocation.h" #include "macros.h" @@ -43,16 +43,16 @@ class MemberExpression; class ClassStaticBlock; } // namespace panda::es2panda::ir -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class ETSBinder; -class VarBinder { +class Binder { public: - explicit VarBinder(ArenaAllocator *allocator) : allocator_(allocator), function_scopes_(allocator_->Adapter()) {} + explicit Binder(ArenaAllocator *allocator) : allocator_(allocator), function_scopes_(allocator_->Adapter()) {} - NO_COPY_SEMANTIC(VarBinder); - NO_MOVE_SEMANTIC(VarBinder); - ~VarBinder() = default; + NO_COPY_SEMANTIC(Binder); + NO_MOVE_SEMANTIC(Binder); + ~Binder() = default; void InitTopScope(); virtual void IdentifierAnalysis(); @@ -64,7 +64,7 @@ public: T *AddTsDecl(const lexer::SourcePosition &pos, Args &&...args); template - std::tuple NewVarDecl(const lexer::SourcePosition &pos, Args &&...args); + std::tuple NewVarDecl(const lexer::SourcePosition &pos, Args &&...args); std::tuple AddParamDecl(ir::AstNode *param); @@ -213,13 +213,11 @@ protected: void AddMandatoryParams(); void LookupReference(const util::StringView &name); void InstantiateArguments(); - bool InstantiateArgumentsImpl(Scope **scope, Scope *iter, const ir::AstNode *node); void InstantiatePrivateContext(const ir::Identifier *ident) const; void BuildVarDeclarator(ir::VariableDeclarator *var_decl); void BuildVarDeclaratorId(ir::AstNode *child_node); void BuildForUpdateLoop(ir::ForUpdateStatement *for_update_stmt); - void BuildForInOfLoop(varbinder::LoopScope *loop_scope, ir::AstNode *left, ir::Expression *right, - ir::Statement *body); + void BuildForInOfLoop(binder::LoopScope *loop_scope, ir::AstNode *left, ir::Expression *right, ir::Statement *body); void BuildCatchClause(ir::CatchClause *catch_clause_stmt); void ResolveReference(ir::AstNode *child_node); void ResolveReferences(const ir::AstNode *parent); @@ -227,7 +225,7 @@ protected: void VisitScriptFunction(ir::ScriptFunction *func); util::StringView BuildFunctionName(util::StringView name, uint32_t idx); - void AddCompilableFunctionScope(varbinder::FunctionScope *func_scope); + void AddCompilableFunctionScope(binder::FunctionScope *func_scope); void InitializeClassBinding(ir::ClassDefinition *class_def); void InitializeClassIdent(ir::ClassDefinition *class_def); @@ -259,10 +257,9 @@ template class LexicalScope { public: template - explicit LexicalScope(VarBinder *varbinder, Args &&...args) - : LexicalScope( - varbinder->Allocator()->New(varbinder->Allocator(), varbinder->scope_, std::forward(args)...), - varbinder) + explicit LexicalScope(Binder *binder, Args &&...args) + : LexicalScope(binder->Allocator()->New(binder->Allocator(), binder->scope_, std::forward(args)...), + binder) { } @@ -273,37 +270,37 @@ public: ~LexicalScope() { - ASSERT(varbinder_); - varbinder_->scope_ = prev_scope_; - varbinder_->var_scope_ = prev_var_scope_; + ASSERT(binder_); + binder_->scope_ = prev_scope_; + binder_->var_scope_ = prev_var_scope_; } - [[nodiscard]] static LexicalScope Enter(VarBinder *varbinder, T *scope, bool check_eval = true) + [[nodiscard]] static LexicalScope Enter(Binder *binder, T *scope, bool check_eval = true) { - LexicalScope lex_scope(scope, varbinder); - if (!check_eval || varbinder->Extension() == ScriptExtension::TS) { + LexicalScope lex_scope(scope, binder); + if (!check_eval || binder->Extension() == ScriptExtension::TS) { return lex_scope; } // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { - varbinder->var_scope_ = scope->GetFunctionScope(); - varbinder->var_scope_->CheckDirectEval(varbinder->compiler_ctx_); + binder->var_scope_ = scope->GetFunctionScope(); + binder->var_scope_->CheckDirectEval(binder->compiler_ctx_); // NOLINTNEXTLINE(readability-braces-around-statements,readability-misleading-indentation) } else if constexpr (std::is_same_v) { - varbinder->var_scope_ = scope; - varbinder->var_scope_->CheckDirectEval(varbinder->compiler_ctx_); + binder->var_scope_ = scope; + binder->var_scope_->CheckDirectEval(binder->compiler_ctx_); // NOLINTNEXTLINE(readability-braces-around-statements,readability-misleading-indentation) } else if constexpr (std::is_same_v) { if (scope->IsLoopScope()) { - varbinder->var_scope_ = scope; - varbinder->var_scope_->CheckDirectEval(varbinder->compiler_ctx_); + binder->var_scope_ = scope; + binder->var_scope_->CheckDirectEval(binder->compiler_ctx_); } // NOLINTNEXTLINE(readability-braces-around-statements,readability-misleading-indentation) } else if constexpr (std::is_same_v) { if (scope->IsLoopDeclarationScope()) { - varbinder->var_scope_ = scope; - varbinder->var_scope_->CheckDirectEval(varbinder->compiler_ctx_); + binder->var_scope_ = scope; + binder->var_scope_->CheckDirectEval(binder->compiler_ctx_); } } @@ -315,20 +312,20 @@ public: private: NO_COPY_SEMANTIC(LexicalScope); - explicit LexicalScope(T *scope, VarBinder *varbinder) - : varbinder_(varbinder), scope_(scope), prev_scope_(varbinder->scope_), prev_var_scope_(varbinder->var_scope_) + explicit LexicalScope(T *scope, Binder *binder) + : binder_(binder), scope_(scope), prev_scope_(binder->scope_), prev_var_scope_(binder->var_scope_) { - varbinder_->scope_ = scope_; + binder_->scope_ = scope_; } - VarBinder *varbinder_ {}; + Binder *binder_ {}; T *scope_ {}; Scope *prev_scope_ {}; VariableScope *prev_var_scope_ {}; }; template -void VarBinder::AddMandatoryParams(const MandatoryParams ¶ms) +void Binder::AddMandatoryParams(const MandatoryParams ¶ms) { ASSERT(scope_->IsFunctionVariableScope()); @@ -340,7 +337,7 @@ void VarBinder::AddMandatoryParams(const MandatoryParams ¶ms) } template -T *VarBinder::AddTsDecl(const lexer::SourcePosition &pos, Args &&...args) +T *Binder::AddTsDecl(const lexer::SourcePosition &pos, Args &&...args) { T *decl = Allocator()->New(std::forward(args)...); @@ -352,7 +349,7 @@ T *VarBinder::AddTsDecl(const lexer::SourcePosition &pos, Args &&...args) } template -T *VarBinder::AddDecl(const lexer::SourcePosition &pos, Args &&...args) +T *Binder::AddDecl(const lexer::SourcePosition &pos, Args &&...args) { T *decl = Allocator()->New(std::forward(args)...); @@ -364,10 +361,10 @@ T *VarBinder::AddDecl(const lexer::SourcePosition &pos, Args &&...args) } template -std::tuple VarBinder::NewVarDecl(const lexer::SourcePosition &pos, Args &&...args) +std::tuple Binder::NewVarDecl(const lexer::SourcePosition &pos, Args &&...args) { T *decl = Allocator()->New(std::forward(args)...); - varbinder::Variable *var = scope_->AddDecl(Allocator(), decl, Extension()); + binder::Variable *var = scope_->AddDecl(Allocator(), decl, Extension()); if (var != nullptr) { return {decl, var}; @@ -375,6 +372,6 @@ std::tuple VarBinder::NewVarDecl(const lexer::Source ThrowRedeclaration(pos, decl->Name()); } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/declaration.cpp b/ets2panda/binder/declaration.cpp similarity index 88% rename from ets2panda/varbinder/declaration.cpp rename to ets2panda/binder/declaration.cpp index e4b47f8586b57dd9aff93f1270f45e891a938e4b..2e6ec9e74422a9c2cf3cd8dd2cfdd32bdd79cd40 100644 --- a/ets2panda/varbinder/declaration.cpp +++ b/ets2panda/binder/declaration.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,5 +15,5 @@ #include "declaration.h" -namespace panda::es2panda::varbinder { -} // namespace panda::es2panda::varbinder +namespace panda::es2panda::binder { +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/declaration.h b/ets2panda/binder/declaration.h similarity index 98% rename from ets2panda/varbinder/declaration.h rename to ets2panda/binder/declaration.h index 8d312cf4bc32b6f2b549b84688df75863c74a6ca..86f26b8c7ba35d8d90e8a17d62e478cb3f43b1e1 100644 --- a/ets2panda/varbinder/declaration.h +++ b/ets2panda/binder/declaration.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -16,7 +16,7 @@ #ifndef ES2PANDA_COMPILER_SCOPES_DECLARATION_H #define ES2PANDA_COMPILER_SCOPES_DECLARATION_H -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "macros.h" #include "util/ustring.h" @@ -28,7 +28,7 @@ class ImportDeclaration; class ETSImportDeclaration; } // namespace panda::es2panda::ir -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Scope; class LocalScope; @@ -369,6 +369,6 @@ public: private: util::StringView export_name_; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/enumMemberResult.h b/ets2panda/binder/enumMemberResult.h similarity index 91% rename from ets2panda/varbinder/enumMemberResult.h rename to ets2panda/binder/enumMemberResult.h index a5588c7d7f2deea5aef56a9a04b1b689bebb00e1..9182118c5b0ad5df1172cb9755331a532de1d490 100644 --- a/ets2panda/varbinder/enumMemberResult.h +++ b/ets2panda/binder/enumMemberResult.h @@ -20,9 +20,9 @@ #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { // Note: if the bool operand is present, the expression cannot be evaluated during compliation using EnumMemberResult = std::variant; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/privateBinding.h b/ets2panda/binder/privateBinding.h similarity index 86% rename from ets2panda/varbinder/privateBinding.h rename to ets2panda/binder/privateBinding.h index 6ef2968956956d8952fbe5204b921e0ae873200c..15a8761982674a55c715965bfd6ed8de455a0b85 100644 --- a/ets2panda/varbinder/privateBinding.h +++ b/ets2panda/binder/privateBinding.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -13,12 +13,12 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_PRIVATE_BINDING_H -#define ES2PANDA_VARBINDER_PRIVATE_BINDING_H +#ifndef ES2PANDA_BINDER_PRIVATE_BINDING_H +#define ES2PANDA_BINDER_PRIVATE_BINDING_H #include "util/ustring.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class PrivateBinding : public util::UString { public: explicit PrivateBinding(ArenaAllocator *allocator, uint32_t id) @@ -34,6 +34,6 @@ public: static constexpr std::string_view PRIVATE_PREFIX = "#"; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/recordTable.cpp b/ets2panda/binder/recordTable.cpp similarity index 96% rename from ets2panda/varbinder/recordTable.cpp rename to ets2panda/binder/recordTable.cpp index 4bfeb7e14e941fdc254c214073953f17f2722e4f..71590bdfbf272c905e9e4dd9a8b74ef436752deb 100644 --- a/ets2panda/varbinder/recordTable.cpp +++ b/ets2panda/binder/recordTable.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,14 +15,14 @@ #include "recordTable.h" #include "parser/program/program.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "ir/base/classDefinition.h" #include "ir/expressions/identifier.h" #include "ir/ts/tsEnumDeclaration.h" #include "ir/ts/tsInterfaceDeclaration.h" #include "generated/signatures.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { BoundContext::BoundContext(RecordTable *record_table, ir::ClassDefinition *class_def) : prev_(record_table->bound_ctx_), record_table_(record_table), saved_record_(record_table->record_) { @@ -87,4 +87,4 @@ util::StringView RecordTable::RecordName() const return std::get(record_)->InternalName(); } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/recordTable.h b/ets2panda/binder/recordTable.h similarity index 97% rename from ets2panda/varbinder/recordTable.h rename to ets2panda/binder/recordTable.h index 2351d211f8d10c891d9d508be4d5b9fa7e5f5b7c..2847f164f952ea8b1ed475013f6df9eb2b778f86 100644 --- a/ets2panda/varbinder/recordTable.h +++ b/ets2panda/binder/recordTable.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -35,7 +35,7 @@ class TSInterfaceDeclaration; class Identifier; } // namespace panda::es2panda::ir -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class FunctionScope; class BoundContext; @@ -156,7 +156,7 @@ private: ArenaSet class_definitions_; ArenaSet interface_declarations_; - ArenaVector signatures_; + ArenaVector signatures_; RecordHolder record_ {nullptr}; parser::Program *program_ {}; BoundContext *bound_ctx_ {}; @@ -184,6 +184,6 @@ private: ir::Identifier *record_ident_; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/binder/scope.cpp similarity index 88% rename from ets2panda/varbinder/scope.cpp rename to ets2panda/binder/scope.cpp index 8999d8cb9eb5e294fd1bbcdaacb90b8f39c38759..22f53e1d214257b3c8091fb2803ee1f151c8bf9a 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/binder/scope.cpp @@ -15,11 +15,11 @@ #include "scope.h" -#include "varbinder/declaration.h" +#include "binder/declaration.h" #include "util/helpers.h" -#include "varbinder/tsBinding.h" -#include "varbinder/variable.h" -#include "varbinder/variableFlags.h" +#include "binder/tsBinding.h" +#include "binder/variable.h" +#include "binder/variableFlags.h" #include "ir/astNode.h" #include "ir/expressions/identifier.h" #include "ir/statements/classDeclaration.h" @@ -45,7 +45,7 @@ #include #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { VariableScope *Scope::EnclosingVariableScope() { Scope *iter = this; @@ -76,10 +76,11 @@ const VariableScope *Scope::EnclosingVariableScope() const return nullptr; } +// NOLINTNEXTLINE(google-default-arguments) Variable *Scope::FindLocal(const util::StringView &name, ResolveBindingOptions options) const { if ((options & ResolveBindingOptions::INTERFACES) != 0) { - std::string ts_binding_name = varbinder::TSBinding::ToTSBinding(name); + std::string ts_binding_name = binder::TSBinding::ToTSBinding(name); util::StringView interface_name_view(ts_binding_name); auto res = bindings_.find(interface_name_view); @@ -177,7 +178,7 @@ std::tuple Scope::IterateShadowedVariables(const util::StringView auto *iter = this; while (true) { - auto *v = iter->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); + auto *v = iter->FindLocal(name); if (v != nullptr && visitor(v)) { return {iter, true}; @@ -193,31 +194,26 @@ std::tuple Scope::IterateShadowedVariables(const util::StringView return {iter, false}; } -Variable *Scope::AddLocalVar(ArenaAllocator *allocator, Decl *new_decl) -{ - auto [scope, shadowed] = - IterateShadowedVariables(new_decl->Name(), [](const Variable *v) { return !v->HasFlag(VariableFlags::VAR); }); - - if (shadowed) { - return nullptr; - } - - VariableFlags var_flags = VariableFlags::HOIST_VAR | VariableFlags::LEXICAL_VAR; - if (scope->IsGlobalScope()) { - return scope->InsertBinding(new_decl->Name(), allocator->New(new_decl, var_flags)) - .first->second; - } - - return scope->PropagateBinding(allocator, new_decl->Name(), new_decl, var_flags); -} - Variable *Scope::AddLocal(ArenaAllocator *allocator, Variable *current_variable, Decl *new_decl, [[maybe_unused]] ScriptExtension extension) { VariableFlags flags = VariableFlags::LEXICAL; switch (new_decl->Type()) { case DeclType::VAR: { - return AddLocalVar(allocator, new_decl); + auto [scope, shadowed] = IterateShadowedVariables( + new_decl->Name(), [](const Variable *v) { return !v->HasFlag(VariableFlags::VAR); }); + + if (shadowed) { + return nullptr; + } + + VariableFlags var_flags = VariableFlags::HOIST_VAR | VariableFlags::LEXICAL_VAR; + if (scope->IsGlobalScope()) { + return scope->InsertBinding(new_decl->Name(), allocator->New(new_decl, var_flags)) + .first->second; + } + + return scope->PropagateBinding(allocator, new_decl->Name(), new_decl, var_flags); } case DeclType::ENUM: { return bindings_.insert({new_decl->Name(), allocator->New(new_decl, false)}).first->second; @@ -290,7 +286,7 @@ void VariableScope::CheckDirectEval(compiler::CompilerContext *compiler_ctx) literals[variable->AsLocalVariable()->LexIdx()] = compiler::Literal(name); } } else { - std::vector bindings(LexicalSlots()); + std::vector bindings(LexicalSlots()); for (const auto &[name, variable] : var_map) { (void)name; @@ -340,8 +336,7 @@ std::tuple ParamScope::AddParamDecl( const auto [name, pattern] = util::Helpers::ParamName(allocator, param, params_.size()); auto *decl = NewDecl(allocator, name); - auto *var = AddParam(allocator, FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS), decl, - VariableFlags::VAR | VariableFlags::LOCAL); + auto *var = AddParam(allocator, FindLocal(name), decl, VariableFlags::VAR | VariableFlags::LOCAL); if (var == nullptr) { return {decl, param, nullptr}; @@ -358,7 +353,7 @@ std::tuple ParamScope::AddParamDecl( auto *var_decl = NewDecl(allocator, binding->Name()); var_decl->BindNode(binding); - if (FindLocal(var_decl->Name(), varbinder::ResolveBindingOptions::BINDINGS) != nullptr) { + if (FindLocal(var_decl->Name()) != nullptr) { return {decl, binding, nullptr}; } @@ -594,13 +589,11 @@ bool ModuleScope::ExportAnalysis() if (exportDecl->IsExportAllDeclaration()) { const auto *export_all_decl = exportDecl->AsExportAllDeclaration(); - if (export_all_decl->Exported() == nullptr) { - continue; - } - - auto result = exported_names.insert(export_all_decl->Exported()->Name()); - if (!result.second) { - return false; + if (export_all_decl->Exported() != nullptr) { + auto result = exported_names.insert(export_all_decl->Exported()->Name()); + if (!result.second) { + return false; + } } continue; @@ -615,7 +608,7 @@ bool ModuleScope::ExportAnalysis() } for (const auto *decl : decls) { - varbinder::Variable *variable = FindLocal(decl->LocalName(), varbinder::ResolveBindingOptions::BINDINGS); + binder::Variable *variable = FindLocal(decl->LocalName()); if (variable == nullptr) { continue; @@ -644,6 +637,7 @@ Variable *LocalScope::AddBinding(ArenaAllocator *allocator, Variable *current_va return AddLocal(allocator, current_variable, new_decl, extension); } +// NOLINTNEXTLINE(google-default-arguments) Variable *ClassScope::FindLocal(const util::StringView &name, ResolveBindingOptions options) const { if ((options & ResolveBindingOptions::TYPE_ALIASES) != 0) { @@ -698,33 +692,49 @@ Variable *ClassScope::FindLocal(const util::StringView &name, ResolveBindingOpti return nullptr; } -void ClassScope::SetBindingProps(Decl *new_decl, BindingProps *props, bool is_static) +Variable *ClassScope::AddBinding(ArenaAllocator *allocator, [[maybe_unused]] Variable *current_variable, Decl *new_decl, + [[maybe_unused]] ScriptExtension extension) { - switch (new_decl->Type()) { + VariableFlags flags = VariableFlags::NONE; + bool is_static = new_decl->Node()->IsStatic(); + ir::Identifier *ident {}; + LocalScope *target_scope {}; + + if (is_static) { + flags |= VariableFlags::STATIC; + } + + const auto decl_type = new_decl->Type(); + switch (decl_type) { case DeclType::CONST: case DeclType::LET: { - props->SetBindingProps(VariableFlags::PROPERTY, new_decl->Node()->AsClassProperty()->Id(), - is_static ? static_field_scope_ : instance_field_scope_); + target_scope = is_static ? static_field_scope_ : instance_field_scope_; + ident = new_decl->Node()->AsClassProperty()->Id(); + flags |= VariableFlags::PROPERTY; break; } case DeclType::INTERFACE: { - props->SetBindingProps(VariableFlags::INTERFACE, new_decl->Node()->AsTSInterfaceDeclaration()->Id(), - is_static ? static_decl_scope_ : instance_decl_scope_); + target_scope = is_static ? static_decl_scope_ : instance_decl_scope_; + ident = new_decl->Node()->AsTSInterfaceDeclaration()->Id(); + flags |= VariableFlags::INTERFACE; break; } case DeclType::CLASS: { - props->SetBindingProps(VariableFlags::CLASS, new_decl->Node()->AsClassDefinition()->Ident(), - is_static ? static_decl_scope_ : instance_decl_scope_); + target_scope = is_static ? static_decl_scope_ : instance_decl_scope_; + ident = new_decl->Node()->AsClassDefinition()->Ident(); + flags |= VariableFlags::CLASS; break; } case DeclType::ENUM_LITERAL: { - props->SetBindingProps(VariableFlags::ENUM_LITERAL, new_decl->Node()->AsTSEnumDeclaration()->Key(), - is_static ? static_decl_scope_ : instance_decl_scope_); + target_scope = is_static ? static_decl_scope_ : instance_decl_scope_; + ident = new_decl->Node()->AsTSEnumDeclaration()->Key(); + flags |= VariableFlags::ENUM_LITERAL; break; } case DeclType::TYPE_ALIAS: { - props->SetBindingProps(VariableFlags::TYPE_ALIAS, new_decl->Node()->AsTSTypeAliasDeclaration()->Id(), - type_alias_scope_); + target_scope = type_alias_scope_; + ident = new_decl->Node()->AsTSTypeAliasDeclaration()->Id(); + flags |= VariableFlags::TYPE_ALIAS; break; } default: { @@ -732,34 +742,22 @@ void ClassScope::SetBindingProps(Decl *new_decl, BindingProps *props, bool is_st break; } } -} - -Variable *ClassScope::AddBinding(ArenaAllocator *allocator, [[maybe_unused]] Variable *current_variable, Decl *new_decl, - [[maybe_unused]] ScriptExtension extension) -{ - bool is_static = new_decl->Node()->IsStatic(); - BindingProps props; - - if (is_static) { - props.SetFlagsType(VariableFlags::STATIC); - } - - SetBindingProps(new_decl, &props, is_static); if (FindLocal(new_decl->Name(), ResolveBindingOptions::ALL) != nullptr) { return nullptr; } - auto *var = props.GetTargetScope()->AddBinding(allocator, nullptr, new_decl, extension); + auto *var = target_scope->AddBinding(allocator, nullptr, new_decl, extension); + if (var == nullptr) { return nullptr; } var->SetScope(this); - var->AddFlag(props.GetFlags()); + var->AddFlag(flags); - if (props.GetIdent() != nullptr) { - props.GetIdent()->SetVariable(var); + if (ident != nullptr) { + ident->SetVariable(var); } return var; @@ -827,11 +825,10 @@ Variable *CatchParamScope::AddBinding(ArenaAllocator *allocator, Variable *curre Variable *CatchScope::AddBinding(ArenaAllocator *allocator, Variable *current_variable, Decl *new_decl, [[maybe_unused]] ScriptExtension extension) { - if (!new_decl->IsVarDecl() && - (param_scope_->FindLocal(new_decl->Name(), varbinder::ResolveBindingOptions::BINDINGS) != nullptr)) { + if (!new_decl->IsVarDecl() && (param_scope_->FindLocal(new_decl->Name()) != nullptr)) { return nullptr; } return AddLocal(allocator, current_variable, new_decl, extension); } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/scope.h b/ets2panda/binder/scope.h similarity index 94% rename from ets2panda/varbinder/scope.h rename to ets2panda/binder/scope.h index 644e49e5c4fb8212c5cfd4d348301a37ac194a26..57a16b50bf75eec1085c4ac2b33f15a9e993ac60 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/binder/scope.h @@ -16,8 +16,8 @@ #ifndef ES2PANDA_COMPILER_SCOPES_SCOPE_H #define ES2PANDA_COMPILER_SCOPES_SCOPE_H -#include "varbinder/declaration.h" -#include "varbinder/variable.h" +#include "binder/declaration.h" +#include "binder/variable.h" #include "es2panda.h" #include "util/enumbitops.h" #include "util/ustring.h" @@ -31,7 +31,7 @@ class IRNode; class CompilerContext; } // namespace panda::es2panda::compiler -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECLARE_CLASSES(type, className) class className; SCOPE_TYPES(DECLARE_CLASSES) @@ -212,8 +212,7 @@ public: Variable *AddDecl(ArenaAllocator *allocator, Decl *decl, [[maybe_unused]] ScriptExtension extension) { decls_.push_back(decl); - return AddBinding(allocator, FindLocal(decl->Name(), varbinder::ResolveBindingOptions::BINDINGS), decl, - extension); + return AddBinding(allocator, FindLocal(decl->Name()), decl, extension); } Variable *AddTsDecl(ArenaAllocator *allocator, Decl *decl, [[maybe_unused]] ScriptExtension extension) @@ -228,7 +227,7 @@ public: template VariableType *AddDecl(ArenaAllocator *allocator, util::StringView name, VariableFlags flags); - template + template static VariableType *CreateVar(ArenaAllocator *allocator, util::StringView name, VariableFlags flags, ir::AstNode *node); @@ -248,7 +247,9 @@ public: virtual Variable *AddBinding(ArenaAllocator *allocator, Variable *current_variable, Decl *new_decl, [[maybe_unused]] ScriptExtension extension) = 0; - virtual Variable *FindLocal(const util::StringView &name, ResolveBindingOptions options) const; + // NOLINTNEXTLINE(google-default-arguments) + virtual Variable *FindLocal(const util::StringView &name, + ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const; ConstScopeFindResult Find(const util::StringView &name, ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const; @@ -289,8 +290,6 @@ protected: Variable *AddLocal(ArenaAllocator *allocator, Variable *current_variable, Decl *new_decl, [[maybe_unused]] ScriptExtension extension); - Variable *AddLocalVar(ArenaAllocator *allocator, Decl *new_decl); - private: template < typename ResultT, typename ScopeT, @@ -644,46 +643,13 @@ public: return anonymous_class_idx_++; } - Variable *FindLocal(const util::StringView &name, ResolveBindingOptions options) const override; + // NOLINTNEXTLINE(google-default-arguments) + Variable *FindLocal(const util::StringView &name, + ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const override; Variable *AddBinding(ArenaAllocator *allocator, Variable *current_variable, Decl *new_decl, [[maybe_unused]] ScriptExtension extension) override; - class BindingProps { - public: - BindingProps() = default; - - void SetFlagsType(VariableFlags flags_type) - { - flags_ |= flags_type; - } - void SetBindingProps(VariableFlags flags, ir::Identifier *ident, LocalScope *target_scope) - { - flags_ |= flags; - ident_ = ident; - target_scope_ = target_scope; - } - VariableFlags GetFlags() const - { - return flags_; - } - ir::Identifier *GetIdent() - { - return ident_; - } - LocalScope *GetTargetScope() - { - return target_scope_; - } - - private: - VariableFlags flags_ = VariableFlags::NONE; - ir::Identifier *ident_ {}; - LocalScope *target_scope_ {}; - }; - - void SetBindingProps(Decl *new_decl, BindingProps *props, bool is_static); - private: LocalScope *type_alias_scope_; LocalScope *static_decl_scope_; @@ -833,7 +799,7 @@ public: using ModuleEntry = ArenaVector>; using ImportDeclList = ArenaVector; using ExportDeclList = ArenaVector; - using LocalExportNameMap = ArenaMultiMap; + using LocalExportNameMap = ArenaMultiMap; explicit ModuleScope(ArenaAllocator *allocator) : GlobalScope(allocator), @@ -962,7 +928,7 @@ T *Scope::NewDecl(ArenaAllocator *allocator, Args &&...args) template VariableType *Scope::AddDecl(ArenaAllocator *allocator, util::StringView name, VariableFlags flags) { - if (FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS)) { + if (FindLocal(name)) { return nullptr; } @@ -995,6 +961,6 @@ Variable *Scope::PropagateBinding(ArenaAllocator *allocator, util::StringView na res->second->Reset(std::forward(args)...); return res->second; } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/tsBinding.h b/ets2panda/binder/tsBinding.h similarity index 88% rename from ets2panda/varbinder/tsBinding.h rename to ets2panda/binder/tsBinding.h index 70e8af6abf291c08b2a63179bbd62f3fdd0a9abd..eb845ee65fa093165e8fedcc55e3ec3c2e3e7fb8 100644 --- a/ets2panda/varbinder/tsBinding.h +++ b/ets2panda/binder/tsBinding.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef ES2PANDA_VARBINDER_TS_BINDING_H -#define ES2PANDA_VARBINDER_TS_BINDING_H +#ifndef ES2PANDA_BINDER_TS_BINDING_H +#define ES2PANDA_BINDER_TS_BINDING_H #include "util/ustring.h" #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { // Note: if the bool operand is present, the expression cannot be evaluated during compilation using EnumMemberResult = std::variant; @@ -39,6 +39,6 @@ public: static constexpr std::string_view TS_PREFIX = "%"; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/variable.cpp b/ets2panda/binder/variable.cpp similarity index 93% rename from ets2panda/varbinder/variable.cpp rename to ets2panda/binder/variable.cpp index 873af44b6c53c5d8af6865a574317e8f7ea2b7fa..ea807ca31b2b66abe7cc23780b166384a92dca53 100644 --- a/ets2panda/varbinder/variable.cpp +++ b/ets2panda/binder/variable.cpp @@ -15,11 +15,11 @@ #include "variable.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { LocalVariable::LocalVariable(Decl *decl, VariableFlags flags) : Variable(decl, flags) { if (decl->IsConstDecl()) { @@ -60,4 +60,4 @@ void EnumVariable::ResetDecl(Decl *decl) { decl_ = decl; } -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder diff --git a/ets2panda/varbinder/variable.h b/ets2panda/binder/variable.h similarity index 96% rename from ets2panda/varbinder/variable.h rename to ets2panda/binder/variable.h index a3bd25761d32e14f7eb96b95da4b68081181a776..43605ba965f1eb6a646c73ad72f77d871979a2ed 100644 --- a/ets2panda/varbinder/variable.h +++ b/ets2panda/binder/variable.h @@ -16,8 +16,8 @@ #ifndef ES2PANDA_COMPILER_SCOPES_VARIABLE_H #define ES2PANDA_COMPILER_SCOPES_VARIABLE_H -#include "varbinder/enumMemberResult.h" -#include "varbinder/variableFlags.h" +#include "binder/enumMemberResult.h" +#include "binder/variableFlags.h" #include "ir/irnode.h" #include "macros.h" #include "util/ustring.h" @@ -29,7 +29,7 @@ class Type; enum class PropertyType; } // namespace panda::es2panda::checker -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Decl; class Scope; class VariableScope; @@ -96,7 +96,7 @@ public: ts_type_ = ts_type; } - void SetScope(varbinder::Scope *scope) + void SetScope(binder::Scope *scope) { scope_ = scope; } @@ -276,5 +276,5 @@ private: EnumMemberResult value_ {}; bool back_reference_ {}; }; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/varbinder/variableFlags.h b/ets2panda/binder/variableFlags.h similarity index 98% rename from ets2panda/varbinder/variableFlags.h rename to ets2panda/binder/variableFlags.h index 87e165e4cead92a3ea44803aeaee632009e571ca..49e8603c3c3b917c42a4cc1bf4150dfd7cac0860 100644 --- a/ets2panda/varbinder/variableFlags.h +++ b/ets2panda/binder/variableFlags.h @@ -19,7 +19,7 @@ #include #include "util/enumbitops.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECLARATION_KINDS(_) \ _(VAR, VarDecl) \ @@ -184,6 +184,6 @@ enum class ScopeFlags : uint32_t { }; DEFINE_BITOPS(ScopeFlags) -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder #endif diff --git a/ets2panda/checker/ASchecker.cpp b/ets2panda/checker/ASchecker.cpp index 492c3b5d7a52df22cf6c1b6ce471290751c3e120..e0132644267eebd4f92c10d2ead2196b83e5955c 100644 --- a/ets2panda/checker/ASchecker.cpp +++ b/ets2panda/checker/ASchecker.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -18,9 +18,9 @@ namespace panda::es2panda::checker { -bool ASChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) +bool ASChecker::StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) { - Initialize(varbinder); + Initialize(binder); if (options.dump_ast) { std::cout << Program()->Dump() << std::endl; diff --git a/ets2panda/checker/ASchecker.h b/ets2panda/checker/ASchecker.h index d2840c05332312e2a9fee333e3e0714b1ac6ef91..9d6d36a6c21dd23ee768c79371e12881238c692a 100644 --- a/ets2panda/checker/ASchecker.h +++ b/ets2panda/checker/ASchecker.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -25,7 +25,7 @@ public: // NOLINTNEXTLINE(readability-redundant-member-init) explicit ASChecker() : Checker() {} - bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, + bool StartChecker([[maybe_unused]] binder::Binder *binder, [[maybe_unused]] const CompilerOptions &options) override; Type *CheckTypeCached([[maybe_unused]] ir::Expression *expr) override { @@ -34,7 +34,7 @@ public: void ResolveStructuredTypeMembers([[maybe_unused]] Type *type) override {} - Type *GetTypeOfVariable([[maybe_unused]] varbinder::Variable *var) override + Type *GetTypeOfVariable([[maybe_unused]] binder::Variable *var) override { return nullptr; } diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 1b18db86c4a0cd71e901844ad228d72eebb6614b..2e05e528f30d1b428c49aef664379507c47a488b 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -14,10 +14,8 @@ */ #include "ETSAnalyzer.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" -#include "checker/ETSchecker.h" -#include "checker/ets/castingContext.h" +#include "binder/binder.h" +#include "binder/ETSBinder.h" #include "checker/ets/typeRelationContext.h" #include "ir/base/catchClause.h" #include "ir/base/classProperty.h" @@ -235,57 +233,37 @@ checker::Type *ETSAnalyzer::Check(ir::ETSPackageDeclaration *st) const checker::Type *ETSAnalyzer::Check(ir::ETSParameterExpression *expr) const { - ETSChecker *checker = GetETSChecker(); - if (expr->TsType() == nullptr) { - checker::Type *param_type; - - if (expr->Ident()->TsType() != nullptr) { - param_type = expr->Ident()->TsType(); - } else { - param_type = !expr->IsRestParameter() ? expr->Ident()->Check(checker) : expr->spread_->Check(checker); - if (expr->IsDefault()) { - [[maybe_unused]] auto *const init_type = expr->Initializer()->Check(checker); - } - } - - expr->SetTsType(param_type); - } - - return expr->TsType(); + (void)expr; + UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSPrimitiveType *node) const +checker::Type *ETSAnalyzer::Check(ir::ETSPrimitiveType *node) const { - return nullptr; + (void)node; + UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ETSStructDeclaration *node) const { - ETSChecker *checker = GetETSChecker(); - node->Definition()->Check(checker); - return nullptr; + (void)node; + UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ETSTypeReference *node) const { - ETSChecker *checker = GetETSChecker(); - return node->GetType(checker); + (void)node; + UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ETSTypeReferencePart *node) const -{ - ETSChecker *checker = GetETSChecker(); - return node->GetType(checker); -} - -checker::Type *ETSAnalyzer::Check(ir::ETSUnionType *node) const { (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSWildcardType *node) const +checker::Type *ETSAnalyzer::Check(ir::ETSWildcardType *node) const { + (void)node; UNREACHABLE(); } // compile methods for EXPRESSIONS in alphabetical order @@ -297,70 +275,8 @@ checker::Type *ETSAnalyzer::Check(ir::ArrayExpression *expr) const checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const { - ETSChecker *checker = GetETSChecker(); - if (expr->TsType() != nullptr) { - return expr->TsType(); - } - - auto *func_type = checker->BuildFunctionSignature(expr->Function(), false); - - if (expr->Function()->IsAsyncFunc()) { - auto *ret_type = static_cast(expr->Function()->Signature()->ReturnType()); - if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { - checker->ThrowTypeError("Return type of async lambda must be 'Promise'", expr->Function()->Start()); - } - } - - checker::ScopeContext scope_ctx(checker, expr->Function()->Scope()); - - if (checker->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD)) { - /* - example code: - ``` - class A { - prop:number - } - function A.method() { - let a = () => { - console.println(this.prop) - } - } - ``` - here the enclosing class of arrow function should be Class A - */ - checker->Context().SetContainingClass( - checker->Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS).variable->TsType()->AsETSObjectType()); - } - - checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), - checker->Context().ContainingClass()); - checker->AddStatus(checker::CheckerStatus::IN_LAMBDA); - checker->Context().SetContainingSignature(func_type->CallSignatures()[0]); - - auto *body_type = expr->Function()->Body()->Check(checker); - - if (expr->Function()->Body()->IsExpression()) { - if (expr->Function()->ReturnTypeAnnotation() == nullptr) { - func_type->CallSignatures()[0]->SetReturnType(body_type); - } - - checker::AssignmentContext( - checker->Relation(), expr->Function()->Body()->AsExpression(), body_type, - func_type->CallSignatures()[0]->ReturnType(), expr->Function()->Start(), - {"Return statements return type is not compatible with the containing functions return type"}, - checker::TypeRelationFlag::DIRECT_RETURN); - } - - checker->Context().SetContainingSignature(nullptr); - checker->CheckCapturedVariables(); - - for (auto [var, _] : checker->Context().CapturedVars()) { - (void)_; - expr->CapturedVars().push_back(var); - } - - expr->SetTsType(func_type); - return expr->TsType(); + (void)expr; + UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const @@ -756,6 +672,7 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const // First (or single) return statement in the function: func_return_type = st->argument_ == nullptr ? checker->GlobalBuiltinVoidType() : st->argument_->Check(checker); + if (func_return_type->HasTypeFlag(checker::TypeFlag::CONSTANT)) { // remove CONSTANT type modifier if exists func_return_type = func_return_type->Instantiate(checker->Allocator(), checker->Relation(), @@ -765,7 +682,7 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const containing_func->Signature()->SetReturnType(func_return_type); containing_func->Signature()->RemoveSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE); - checker->VarBinder()->AsETSBinder()->BuildFunctionName(containing_func); + checker->Binder()->AsETSBinder()->BuildFunctionName(containing_func); if (st->argument_ != nullptr && st->argument_->IsObjectExpression()) { st->argument_->AsObjectExpression()->SetPreferredType(func_return_type); @@ -827,6 +744,7 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const if (argument_type == nullptr) { checker->ThrowTypeError("Invalid return statement expression", st->argument_->Start()); } + // argument_->SetTsType(argument_type); st->argument_->AddBoxingUnboxingFlag(checker->GetBoxingFlag(argument_type)); } @@ -840,14 +758,18 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const func_return_type = checker->FindLeastUpperBound(func_return_type, argument_type); containing_func->Signature()->SetReturnType(func_return_type); containing_func->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); + } else if (func_return_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE_RETURN) && argument_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE_RETURN)) { // function return type is of primitive type (including enums): relation->SetFlags(checker::TypeRelationFlag::DIRECT_RETURN | checker::TypeRelationFlag::IN_ASSIGNMENT_CONTEXT | checker::TypeRelationFlag::ASSIGNMENT_CONTEXT); + if (relation->IsAssignableTo(func_return_type, argument_type)) { func_return_type = argument_type; + // func_return_type = argument_type->Instantiate(checker->Allocator(), relation, + // checker->GetGlobalTypesHolder()); containing_func->Signature()->SetReturnType(func_return_type); containing_func->Signature()->AddSignatureFlag( checker::SignatureFlags::INFERRED_RETURN_TYPE); diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index 7bc4f8a620d0ad44391157385a74ee2919de8498..21443c000cdf566073727a9f38f42e06345f5fe5 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 7a088cb5b61ad3dbd71159cbe7ac30cc2b32c22c..489c479925239bfd9a6c2608ab657887d759729d 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -21,7 +21,7 @@ #include "ir/expressions/callExpression.h" #include "ir/ts/tsInterfaceDeclaration.h" #include "ir/statements/blockStatement.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "parser/program/program.h" #include "checker/ets/aliveAnalyzer.h" @@ -29,13 +29,13 @@ #include "util/helpers.h" namespace panda::es2panda::checker { -void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) +void ETSChecker::InitializeBuiltins(binder::ETSBinder *binder) { if (HasStatus(CheckerStatus::BUILTINS_INITIALIZED)) { return; } - const auto var_map = varbinder->TopScope()->Bindings(); + const auto var_map = binder->TopScope()->Bindings(); auto init_builtin = [var_map](ETSChecker *checker, std::string_view signature) -> util::StringView { const auto iterator = var_map.find(signature); @@ -54,7 +54,7 @@ void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) continue; } - if (var->HasFlag(varbinder::VariableFlags::BUILTIN_TYPE)) { + if (var->HasFlag(binder::VariableFlags::BUILTIN_TYPE)) { Type *type {nullptr}; if (var->Declaration()->Node()->IsClassDefinition()) { type = BuildClassProperties(var->Declaration()->Node()->AsClassDefinition()); @@ -69,9 +69,9 @@ void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) AddStatus(CheckerStatus::BUILTINS_INITIALIZED); } -bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) +bool ETSChecker::StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) { - Initialize(varbinder); + Initialize(binder); if (options.dump_ast) { std::cout << Program()->Dump() << std::endl; @@ -81,10 +81,10 @@ bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, return false; } - varbinder->SetGenStdLib(options.compilation_mode == CompilationMode::GEN_STD_LIB); - varbinder->IdentifierAnalysis(); + binder->SetGenStdLib(options.compilation_mode == CompilationMode::GEN_STD_LIB); + binder->IdentifierAnalysis(); - auto *ets_binder = varbinder->AsETSBinder(); + auto *ets_binder = binder->AsETSBinder(); InitializeBuiltins(ets_binder); for (auto &entry : ets_binder->DynamicImportVars()) { @@ -105,7 +105,7 @@ bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, for (auto lambda : ets_binder->LambdaObjects()) { ASSERT(!lambda.second.first->TsType()->AsETSObjectType()->AssemblerName().Empty()); } - for (auto *func : varbinder->Functions()) { + for (auto *func : binder->Functions()) { ASSERT(!func->Node()->AsScriptFunction()->Scope()->InternalName().Empty()); } #endif @@ -136,7 +136,7 @@ void ETSChecker::CheckProgram(parser::Program *program, bool run_analysis) AliveAnalyzer(Program()->Ast(), this); } - ASSERT(VarBinder()->AsETSBinder()->GetExternalRecordTable().find(program)->second); + ASSERT(Binder()->AsETSBinder()->GetExternalRecordTable().find(program)->second); SetProgram(saved_program); } @@ -314,14 +314,14 @@ const GlobalArraySignatureMap &ETSChecker::GlobalArrayTypes() const } // For use in Signature::ToAssemblerType -const Type *MaybeBoxedType(Checker *checker, const varbinder::Variable *var) +const Type *MaybeBoxedType(Checker *checker, const binder::Variable *var) { return checker->AsETSChecker()->MaybeBoxedType(var); } void ETSChecker::HandleUpdatedCallExpressionNode(ir::CallExpression *call_expr) { - VarBinder()->AsETSBinder()->HandleCustomNodes(call_expr); + Binder()->AsETSBinder()->HandleCustomNodes(call_expr); } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 79927a9efd664cfcb41eb5fdce88a7fbe92a0add..1cdd1f1694880378644a32a14612852ed30af37d 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -19,17 +19,16 @@ #include "checker/checkerContext.h" #include "checker/types/ets/etsObjectType.h" #include "checker/checker.h" -#include "varbinder/enumMemberResult.h" +#include "binder/enumMemberResult.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterInstantiation.h" #include "util/enumbitops.h" #include "util/ustring.h" -#include "checker/resolveResult.h" #include "checker/types/ets/types.h" #include "checker/ets/typeConverter.h" #include "checker/ets/primitiveWrappers.h" #include "checker/types/globalTypesHolder.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "macros.h" @@ -39,8 +38,8 @@ #include #include -namespace panda::es2panda::varbinder { -class VarBinder; +namespace panda::es2panda::binder { +class Binder; class Decl; class EnumVariable; class FunctionDecl; @@ -50,9 +49,58 @@ class Variable; class ETSBinder; class RecordTable; class FunctionParamScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { +enum class OperationType { + BITWISE_AND, + BITWISE_OR, + BITWISE_XOR, + LEFT_SHIFT, + RIGHT_SHIFT, + ADDITION, + SUBTRACTION, + MULTIPLICATION, + DIVISION, + MOD, + LESS_THAN, + LESS_THAN_EQUAL, + GREATER_THAN, + GREATER_THAN_EQUAL, +}; + +enum class OverrideErrorCode { + NO_ERROR, + OVERRIDING_STATIC, + OVERRIDDEN_STATIC, + OVERRIDDEN_FINAL, + INCOMPATIBLE_RETURN, + OVERRIDDEN_WEAKER, +}; + +enum class ResolvedKind { + PROPERTY, + INSTANCE_EXTENSION_FUNCTION, +}; + +class ResolveResult { +public: + explicit ResolveResult(binder::Variable *v, ResolvedKind kind) : variable_(v), kind_(kind) {} + + binder::Variable *Variable() + { + return variable_; + } + + ResolvedKind Kind() + { + return kind_; + } + +private: + binder::Variable *variable_ {}; + ResolvedKind kind_ {}; +}; using ComputedAbstracts = ArenaUnorderedMap, std::unordered_set>>; @@ -118,11 +166,11 @@ public: GlobalArraySignatureMap &GlobalArrayTypes(); const GlobalArraySignatureMap &GlobalArrayTypes() const; - void InitializeBuiltins(varbinder::ETSBinder *varbinder); - bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) override; + void InitializeBuiltins(binder::ETSBinder *binder); + bool StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) override; Type *CheckTypeCached(ir::Expression *expr) override; void ResolveStructuredTypeMembers([[maybe_unused]] Type *type) override {} - Type *GetTypeOfVariable([[maybe_unused]] varbinder::Variable *var) override; + Type *GetTypeOfVariable([[maybe_unused]] binder::Variable *var) override; // Object ETSObjectType *BuildClassProperties(ir::ClassDefinition *class_def); @@ -141,15 +189,15 @@ public: void CreateTypeForClassOrInterfaceTypeParameters(ETSObjectType *type); void SetTypeParameterType(ir::TSTypeParameter *type_param, Type *type_param_type); void ValidateOverriding(ETSObjectType *class_type, const lexer::SourcePosition &pos); - void AddImplementedSignature(std::vector *implemented_signatures, varbinder::LocalVariable *function, + void AddImplementedSignature(std::vector *implemented_signatures, binder::LocalVariable *function, ETSFunctionType *it); void CheckInnerClassMembers(const ETSObjectType *class_type); void CheckClassDefinition(ir::ClassDefinition *class_def); - void FindAssignment(const ir::AstNode *node, const varbinder::LocalVariable *class_var, bool &initialized); - void FindAssignments(const ir::AstNode *node, const varbinder::LocalVariable *class_var, bool &initialized); + void FindAssignment(const ir::AstNode *node, const binder::LocalVariable *class_var, bool &initialized); + void FindAssignments(const ir::AstNode *node, const binder::LocalVariable *class_var, bool &initialized); void CheckConstFields(const ETSObjectType *class_type); - void CheckConstFieldInitialized(const ETSObjectType *class_type, varbinder::LocalVariable *class_var); - void CheckConstFieldInitialized(const Signature *signature, varbinder::LocalVariable *class_var); + void CheckConstFieldInitialized(const ETSObjectType *class_type, binder::LocalVariable *class_var); + void CheckConstFieldInitialized(const Signature *signature, binder::LocalVariable *class_var); void ComputeAbstractsFromInterface(ETSObjectType *interface_type); ArenaVector &GetAbstractsForClass(ETSObjectType *class_type); std::vector CollectAbstractSignaturesFromObject(const ETSObjectType *obj_type); @@ -158,7 +206,7 @@ public: void CheckCyclicConstructorCall(Signature *signature); std::vector ResolveMemberReference(const ir::MemberExpression *member_expr, const ETSObjectType *target); - varbinder::Variable *ResolveInstanceExtension(const ir::MemberExpression *member_expr); + binder::Variable *ResolveInstanceExtension(const ir::MemberExpression *member_expr); void CheckImplicitSuper(ETSObjectType *class_type, Signature *ctor_sig); void CheckValidInheritance(ETSObjectType *class_type, ir::ClassDefinition *class_def); void CheckGetterSetterProperties(ETSObjectType *class_type); @@ -179,7 +227,6 @@ public: CharType *CreateCharType(char16_t value); ETSStringType *CreateETSStringLiteralType(util::StringView value); ETSArrayType *CreateETSArrayType(Type *element_type); - Type *CreateETSUnionType(ArenaVector &&constituent_types); ETSFunctionType *CreateETSFunctionType(Signature *signature); ETSFunctionType *CreateETSFunctionType(Signature *signature, util::StringView name); ETSFunctionType *CreateETSFunctionType(ir::ScriptFunction *func, Signature *signature, util::StringView name); @@ -203,42 +250,9 @@ public: // Arithmetic Type *NegateNumericType(Type *type, ir::Expression *node); Type *BitwiseNegateIntegralType(Type *type, ir::Expression *node); - std::tuple CheckBinaryOperator(ir::Expression *left, ir::Expression *right, ir::Expression *expr, + std::tuple CheckBinaryOperator(ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, bool force_promotion = false); - checker::Type *CheckBinaryOperatorMulDivMod(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *left_type, checker::Type *right_type, - Type *unboxed_l, Type *unboxed_r); - checker::Type *CheckBinaryOperatorPlus(ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, - lexer::SourcePosition pos, bool is_equal_op, checker::Type *left_type, - checker::Type *right_type, Type *unboxed_l, Type *unboxed_r); - checker::Type *CheckBinaryOperatorShift(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *left_type, checker::Type *right_type, - Type *unboxed_l, Type *unboxed_r); - checker::Type *CheckBinaryOperatorBitwise(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *left_type, checker::Type *right_type, - Type *unboxed_l, Type *unboxed_r); - checker::Type *CheckBinaryOperatorLogical(ir::Expression *left, ir::Expression *right, ir::Expression *expr, - lexer::SourcePosition pos, checker::Type *left_type, - checker::Type *right_type, Type *unboxed_l, Type *unboxed_r); - std::tuple CheckBinaryOperatorStrictEqual(ir::Expression *left, lexer::SourcePosition pos, - checker::Type *left_type, checker::Type *right_type); - std::tuple CheckBinaryOperatorEqual(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - checker::Type *left_type, checker::Type *right_type, - Type *unboxed_l, Type *unboxed_r); - std::tuple CheckBinaryOperatorLessGreater(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, - lexer::SourcePosition pos, bool is_equal_op, - checker::Type *left_type, checker::Type *right_type, - Type *unboxed_l, Type *unboxed_r); - std::tuple CheckBinaryOperatorInstanceOf(lexer::SourcePosition pos, checker::Type *left_type, - checker::Type *right_type); - checker::Type *CheckBinaryOperatorNullishCoalescing(ir::Expression *right, lexer::SourcePosition pos, - checker::Type *left_type, checker::Type *right_type); Type *HandleArithmeticOperationOnTypes(Type *left, Type *right, lexer::TokenType operation_type); void FlagExpressionWithUnboxing(Type *type, Type *unboxed_type, ir::Expression *type_expression); template @@ -312,36 +326,36 @@ public: void CheckThrowMarkers(Signature *source, Signature *target); void ValidateSignatureAccessibility(ETSObjectType *callee, Signature *signature, const lexer::SourcePosition &pos); void CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpression *lambda, ETSObjectType *functional_interface); - ir::ClassProperty *CreateLambdaCapturedField(const varbinder::Variable *captured_var, varbinder::ClassScope *scope, + ir::ClassProperty *CreateLambdaCapturedField(const binder::Variable *captured_var, binder::ClassScope *scope, size_t &idx, const lexer::SourcePosition &pos); - ir::ClassProperty *CreateLambdaCapturedThis(varbinder::ClassScope *scope, size_t &idx, + ir::ClassProperty *CreateLambdaCapturedThis(binder::ClassScope *scope, size_t &idx, const lexer::SourcePosition &pos); void CreateLambdaObjectForFunctionReference(ir::AstNode *ref_node, Signature *signature, ETSObjectType *functional_interface); - ir::AstNode *CreateLambdaImplicitField(varbinder::ClassScope *scope, const lexer::SourcePosition &pos); + ir::AstNode *CreateLambdaImplicitField(binder::ClassScope *scope, const lexer::SourcePosition &pos); ir::MethodDefinition *CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool is_static_reference); ir::MethodDefinition *CreateLambdaImplicitCtor(ArenaVector &properties); ir::MethodDefinition *CreateProxyMethodForLambda(ir::ClassDefinition *klass, ir::ArrowFunctionExpression *lambda, ArenaVector &captured, bool is_static); - varbinder::FunctionParamScope *CreateProxyMethodParams(ir::ArrowFunctionExpression *lambda, - ArenaVector &proxy_params, - ArenaVector &captured, bool is_static); + binder::FunctionParamScope *CreateProxyMethodParams(ir::ArrowFunctionExpression *lambda, + ArenaVector &proxy_params, + ArenaVector &captured, bool is_static); void ReplaceIdentifierReferencesInProxyMethod(ir::AstNode *body, ArenaVector &proxy_params, ArenaVector &lambda_params, - ArenaVector &captured); + ArenaVector &captured); void ReplaceIdentifierReferencesInProxyMethod( ir::AstNode *node, ArenaVector &proxy_params, - std::unordered_map &merged_target_references); + std::unordered_map &merged_target_references); void ReplaceIdentifierReferenceInProxyMethod( ir::AstNode *node, ArenaVector &proxy_params, - std::unordered_map &merged_target_references); - ir::Statement *CreateLambdaCtorFieldInit(util::StringView name, varbinder::Variable *var); - varbinder::FunctionParamScope *CreateLambdaCtorImplicitParams(ArenaVector ¶ms, - ArenaVector &properties); - std::tuple CreateLambdaCtorImplicitParam( + std::unordered_map &merged_target_references); + ir::Statement *CreateLambdaCtorFieldInit(util::StringView name, binder::Variable *var); + binder::FunctionParamScope *CreateLambdaCtorImplicitParams(ArenaVector ¶ms, + ArenaVector &properties); + std::tuple CreateLambdaCtorImplicitParam( ArenaVector ¶ms, const lexer::SourceRange &pos, bool is_static_reference); ir::MethodDefinition *CreateLambdaInvokeProto(); - void CreateLambdaFuncDecl(ir::MethodDefinition *func, varbinder::LocalScope *scope); + void CreateLambdaFuncDecl(ir::MethodDefinition *func, binder::LocalScope *scope); void ResolveProxyMethod(ir::MethodDefinition *proxy_method, ir::ArrowFunctionExpression *lambda); void ResolveLambdaObject(ir::ClassDefinition *lambda_object, Signature *signature, ETSObjectType *functional_interface, ir::AstNode *ref_node); @@ -358,51 +372,41 @@ public: void CreateFunctionalInterfaceForFunctionType(ir::ETSFunctionType *func_type); ir::MethodDefinition *CreateInvokeFunction(ir::ETSFunctionType *func_type); void CheckCapturedVariables(); - void CheckCapturedVariableInSubnodes(ir::AstNode *node, varbinder::Variable *var); - void CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *var); + void CheckCapturedVariableInSubnodes(ir::AstNode *node, binder::Variable *var); + void CheckCapturedVariable(ir::AstNode *node, binder::Variable *var); void BuildFunctionalInterfaceName(ir::ETSFunctionType *func_type); void CreateAsyncProxyMethods(ir::ClassDefinition *class_def); - ir::MethodDefinition *CreateAsyncImplMethod(ir::MethodDefinition *async_method, ir::ClassDefinition *class_def); ir::MethodDefinition *CreateAsyncProxy(ir::MethodDefinition *async_method, ir::ClassDefinition *class_def, bool create_decl = true); ir::MethodDefinition *CreateMethod(const util::StringView &name, ir::ModifierFlags modifiers, ir::ScriptFunctionFlags flags, ArenaVector &¶ms, - varbinder::FunctionParamScope *param_scope, ir::TypeNode *return_type, + binder::FunctionParamScope *param_scope, ir::TypeNode *return_type, ir::AstNode *body); - varbinder::FunctionParamScope *CopyParams(const ArenaVector ¶ms, - ArenaVector &out_params); - void ReplaceScope(ir::AstNode *root, ir::AstNode *old_node, varbinder::Scope *new_scope); + binder::FunctionParamScope *CopyParams(const ArenaVector ¶ms, + ArenaVector &out_params); + void ReplaceScope(ir::AstNode *root, ir::AstNode *old_node, binder::Scope *new_scope); // Helpers - size_t ComputeProxyMethods(ir::ClassDefinition *klass); - ir::ModifierFlags GetFlagsForProxyLambda(bool is_static); - ir::ScriptFunction *CreateProxyFunc(ir::ArrowFunctionExpression *lambda, ArenaVector &captured, - bool is_static); - ir::AstNode *GetProxyMethodBody(ir::ArrowFunctionExpression *lambda, varbinder::FunctionScope *scope); static std::string GetAsyncImplName(const util::StringView &name); - static std::string GetAsyncImplName(ir::MethodDefinition *async_method); std::vector GetNameForSynteticObjectType(const util::StringView &source); void SetPropertiesForModuleObject(checker::ETSObjectType *module_obj_type, const util::StringView &import_path); void SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *module_obj_type); Type *GetReferencedTypeFromBase(Type *base_type, ir::Expression *name); Type *GetReferencedTypeBase(ir::Expression *name); - Type *GetTypeFromInterfaceReference(varbinder::Variable *var); - Type *GetTypeFromTypeAliasReference(varbinder::Variable *var); - Type *GetTypeFromClassReference(varbinder::Variable *var); - Type *GetTypeFromEnumReference(varbinder::Variable *var); - Type *GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos); + Type *GetTypeFromInterfaceReference(binder::Variable *var); + Type *GetTypeFromTypeAliasReference(binder::Variable *var); + Type *GetTypeFromClassReference(binder::Variable *var); + Type *GetTypeFromEnumReference(binder::Variable *var); + Type *GetTypeFromTypeParameterReference(binder::LocalVariable *var, const lexer::SourcePosition &pos); Type *GetNonConstantTypeFromPrimitiveType(Type *type); - bool IsNullOrVoidExpression(const ir::Expression *expr) const; bool IsConstantExpression(ir::Expression *expr, Type *type); - void ValidateUnaryOperatorOperand(varbinder::Variable *variable); + void ValidateUnaryOperatorOperand(binder::Variable *variable); std::tuple ApplyBinaryOperatorPromotion(Type *left, Type *right, TypeFlag test, bool do_promotion = true); checker::Type *ApplyConditionalOperatorPromotion(checker::ETSChecker *checker, checker::Type *unboxed_l, checker::Type *unboxed_r); - Type *ApplyUnaryOperatorPromotion(Type *type, bool create_const = true, bool do_promotion = true, - bool is_cond_expr = false); + Type *ApplyUnaryOperatorPromotion(Type *type, bool create_const = true, bool do_promotion = true); Type *HandleBooleanLogicalOperators(Type *left_type, Type *right_type, lexer::TokenType token_type); - Type *HandleBooleanLogicalOperatorsExtended(Type *left_type, Type *right_type, ir::BinaryExpression *expr); checker::Type *CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *type_annotation, ir::Expression *init, ir::ModifierFlags flags); void CheckTruthinessOfType(ir::Expression *expr); @@ -420,17 +424,16 @@ public: bool IsTypeBuiltinType(Type *type); bool IsReferenceType(const Type *type); const ir::AstNode *FindJumpTarget(ir::AstNodeType node_type, const ir::AstNode *node, const ir::Identifier *target); - void ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos); - varbinder::VariableFlags GetAccessFlagFromNode(const ir::AstNode *node); + void ValidatePropertyAccess(binder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos); + binder::VariableFlags GetAccessFlagFromNode(const ir::AstNode *node); void CheckSwitchDiscriminant(ir::Expression *discriminant); Type *ETSBuiltinTypeAsPrimitiveType(Type *object_type); - Type *ETSBuiltinTypeAsConditionalType(Type *object_type); Type *PrimitiveTypeAsETSBuiltinType(Type *object_type); void AddBoxingUnboxingFlagToNode(ir::AstNode *node, Type *boxing_unboxing_type); ir::BoxingUnboxingFlags GetBoxingFlag(Type *boxing_type); ir::BoxingUnboxingFlags GetUnboxingFlag(Type *unboxing_type); - Type *MaybeBoxedType(const varbinder::Variable *var, ArenaAllocator *allocator) const; - Type *MaybeBoxedType(const varbinder::Variable *var) + Type *MaybeBoxedType(const binder::Variable *var, ArenaAllocator *allocator) const; + Type *MaybeBoxedType(const binder::Variable *var) { return MaybeBoxedType(var, Allocator()); } @@ -440,15 +443,15 @@ public: void CheckIdentifierSwitchCase(ir::Expression *current_case, ir::Expression *compare_case, const lexer::SourcePosition &pos); std::string GetStringFromLiteral(ir::Expression *case_test) const; - varbinder::Variable *FindVariableInFunctionScope(util::StringView name); - std::pair FindVariableInClassOrEnclosing( + binder::Variable *FindVariableInFunctionScope(util::StringView name); + std::pair FindVariableInClassOrEnclosing( util::StringView name, const ETSObjectType *class_type); - varbinder::Variable *FindVariableInGlobal(const ir::Identifier *identifier); - void ValidateResolvedIdentifier(ir::Identifier *ident, varbinder::Variable *resolved); - bool IsVariableStatic(const varbinder::Variable *var) const; - bool IsVariableGetterSetter(const varbinder::Variable *var) const; - bool IsSameDeclarationType(varbinder::LocalVariable *target, varbinder::LocalVariable *compare); - void SaveCapturedVariable(varbinder::Variable *var, const lexer::SourcePosition &pos); + binder::Variable *FindVariableInGlobal(const ir::Identifier *identifier); + void ValidateResolvedIdentifier(ir::Identifier *ident, binder::Variable *resolved); + bool IsVariableStatic(const binder::Variable *var) const; + bool IsVariableGetterSetter(const binder::Variable *var) const; + bool IsSameDeclarationType(binder::LocalVariable *target, binder::LocalVariable *compare); + void SaveCapturedVariable(binder::Variable *var, const lexer::SourcePosition &pos); void AddBoxingFlagToPrimitiveType(TypeRelation *relation, Type *target); void AddUnboxingFlagToPrimitiveType(TypeRelation *relation, Type *source, Type *self); void CheckUnboxedTypeWidenable(TypeRelation *relation, Type *target, Type *self); @@ -456,7 +459,7 @@ public: void CheckBoxedSourceTypeAssignable(TypeRelation *relation, Type *source, Type *target); void CheckUnboxedSourceTypeWithWideningAssignable(TypeRelation *relation, Type *source, Type *target); void CheckValidGenericTypeParameter(Type *arg_type, const lexer::SourcePosition &pos); - void ValidateResolvedProperty(const varbinder::LocalVariable *property, const ETSObjectType *target, + void ValidateResolvedProperty(const binder::LocalVariable *property, const ETSObjectType *target, const ir::Identifier *ident, PropertySearchFlags flags); bool IsValidSetterLeftSide(const ir::MemberExpression *member); bool CheckRethrowingParams(const ir::AstNode *ancestor_function, const ir::AstNode *node); @@ -528,38 +531,38 @@ public: } private: - using ClassBuilder = std::function *)>; - using ClassInitializerBuilder = std::function *, - ArenaVector *)>; - using MethodBuilder = std::function *, + using ClassBuilder = std::function *)>; + using ClassInitializerBuilder = + std::function *, ArenaVector *)>; + using MethodBuilder = std::function *, ArenaVector *, Type **)>; void BuildClass(util::StringView name, const ClassBuilder &builder); template std::conditional_t CreateClassInitializer( - varbinder::ClassScope *class_scope, const ClassInitializerBuilder &builder, ETSObjectType *type = nullptr); + binder::ClassScope *class_scope, const ClassInitializerBuilder &builder, ETSObjectType *type = nullptr); - ir::ETSParameterExpression *AddParam(varbinder::FunctionParamScope *param_scope, util::StringView name, + ir::ETSParameterExpression *AddParam(binder::FunctionParamScope *param_scope, util::StringView name, checker::Type *type); template - ir::MethodDefinition *CreateClassMethod(varbinder::ClassScope *class_scope, std::string_view method_name, + ir::MethodDefinition *CreateClassMethod(binder::ClassScope *class_scope, std::string_view method_name, panda::es2panda::ir::ModifierFlags modifier_flags, const MethodBuilder &builder); template ir::ScriptFunction *CreateDynamicCallIntrinsic(ir::Expression *callee, const ArenaVector &arguments, Language lang); - ir::ClassStaticBlock *CreateDynamicCallClassInitializer(varbinder::ClassScope *class_scope, Language lang, + ir::ClassStaticBlock *CreateDynamicCallClassInitializer(binder::ClassScope *class_scope, Language lang, bool is_construct); - ir::ClassStaticBlock *CreateDynamicModuleClassInitializer(varbinder::ClassScope *class_scope, + ir::ClassStaticBlock *CreateDynamicModuleClassInitializer(binder::ClassScope *class_scope, const std::vector &imports); - ir::MethodDefinition *CreateDynamicModuleClassInitMethod(varbinder::ClassScope *class_scope); + ir::MethodDefinition *CreateDynamicModuleClassInitMethod(binder::ClassScope *class_scope); - ir::MethodDefinition *CreateLambdaObjectClassInitializer(varbinder::ClassScope *class_scope, + ir::MethodDefinition *CreateLambdaObjectClassInitializer(binder::ClassScope *class_scope, ETSObjectType *functional_interface); - ir::MethodDefinition *CreateLambdaObjectClassInvokeMethod(varbinder::ClassScope *class_scope, + ir::MethodDefinition *CreateLambdaObjectClassInvokeMethod(binder::ClassScope *class_scope, Signature *invoke_signature, ir::TypeNode *ret_type_annotation); diff --git a/ets2panda/checker/JSchecker.cpp b/ets2panda/checker/JSchecker.cpp index c86bd4ddf1761977bd1bac45b445739a76f16c0e..6e2bd624ba73655251e5e54cdac8eabc42cd4094 100644 --- a/ets2panda/checker/JSchecker.cpp +++ b/ets2panda/checker/JSchecker.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,15 +15,15 @@ #include "JSchecker.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "parser/program/program.h" namespace panda::es2panda::checker { -bool JSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) +bool JSChecker::StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) { - Initialize(varbinder); - varbinder->IdentifierAnalysis(); + Initialize(binder); + binder->IdentifierAnalysis(); if (options.dump_ast) { std::cout << Program()->Dump() << std::endl; diff --git a/ets2panda/checker/JSchecker.h b/ets2panda/checker/JSchecker.h index 9dd522c283243e1b1fa7247a5321ee1227ef5106..604737be7209b4be4872f8da7ea1be971cb7a807 100644 --- a/ets2panda/checker/JSchecker.h +++ b/ets2panda/checker/JSchecker.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -25,7 +25,7 @@ public: // NOLINTNEXTLINE(readability-redundant-member-init) explicit JSChecker() : Checker() {} - bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) override; + bool StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) override; Type *CheckTypeCached([[maybe_unused]] ir::Expression *expr) override { @@ -34,7 +34,7 @@ public: void ResolveStructuredTypeMembers([[maybe_unused]] Type *type) override {} - Type *GetTypeOfVariable([[maybe_unused]] varbinder::Variable *var) override + Type *GetTypeOfVariable([[maybe_unused]] binder::Variable *var) override { return nullptr; } diff --git a/ets2panda/checker/SemanticAnalyzer.h b/ets2panda/checker/SemanticAnalyzer.h index 0cb278a5561912a283fb507930aa21a69469399a..72cfe3735de6e7438ae231ba39f65cf98146e39e 100644 --- a/ets2panda/checker/SemanticAnalyzer.h +++ b/ets2panda/checker/SemanticAnalyzer.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -17,152 +17,6 @@ #define ES2PANDA_CHECKER_SEMANTICANALYZER_H #include "compiler/core/dynamicContext.h" -#include "ir/opaqueTypeNode.h" -#include "ir/as/namedType.h" -#include "ir/as/prefixAssertionExpression.h" -#include "ir/base/catchClause.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classProperty.h" -#include "ir/base/classStaticBlock.h" -#include "ir/base/decorator.h" -#include "ir/base/metaProperty.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/property.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/base/templateElement.h" -#include "ir/base/tsIndexSignature.h" -#include "ir/base/tsMethodSignature.h" -#include "ir/base/tsPropertySignature.h" -#include "ir/base/tsSignatureDeclaration.h" -#include "ir/ets/etsClassLiteral.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/ets/etsImportDeclaration.h" -#include "ir/ets/etsLaunchExpression.h" -#include "ir/ets/etsNewArrayInstanceExpression.h" -#include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" -#include "ir/ets/etsPackageDeclaration.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ets/etsPrimitiveType.h" -#include "ir/ets/etsScript.h" -#include "ir/ets/etsStructDeclaration.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsWildcardType.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/awaitExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/chainExpression.h" -#include "ir/expressions/classExpression.h" -#include "ir/expressions/conditionalExpression.h" -#include "ir/expressions/directEvalExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/importExpression.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/newExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/omittedExpression.h" -#include "ir/expressions/sequenceExpression.h" -#include "ir/expressions/superExpression.h" -#include "ir/expressions/taggedTemplateExpression.h" -#include "ir/expressions/templateLiteral.h" -#include "ir/expressions/thisExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/expressions/updateExpression.h" -#include "ir/expressions/yieldExpression.h" -#include "ir/expressions/literals/bigIntLiteral.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "ir/expressions/literals/charLiteral.h" -#include "ir/expressions/literals/nullLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/regExpLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/exportAllDeclaration.h" -#include "ir/module/exportDefaultDeclaration.h" -#include "ir/module/exportNamedDeclaration.h" -#include "ir/module/exportSpecifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/module/importDefaultSpecifier.h" -#include "ir/module/importNamespaceSpecifier.h" -#include "ir/module/importSpecifier.h" -#include "ir/statements/assertStatement.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/breakStatement.h" -#include "ir/statements/classDeclaration.h" -#include "ir/statements/continueStatement.h" -#include "ir/statements/debuggerStatement.h" -#include "ir/statements/doWhileStatement.h" -#include "ir/statements/emptyStatement.h" -#include "ir/statements/expressionStatement.h" -#include "ir/statements/forInStatement.h" -#include "ir/statements/forOfStatement.h" -#include "ir/statements/forUpdateStatement.h" -#include "ir/statements/functionDeclaration.h" -#include "ir/statements/ifStatement.h" -#include "ir/statements/labelledStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/statements/switchCaseStatement.h" -#include "ir/statements/switchStatement.h" -#include "ir/statements/throwStatement.h" -#include "ir/statements/tryStatement.h" -#include "ir/statements/variableDeclaration.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/statements/whileStatement.h" -#include "ir/ts/tsAnyKeyword.h" -#include "ir/ts/tsArrayType.h" -#include "ir/ts/tsAsExpression.h" -#include "ir/ts/tsBigintKeyword.h" -#include "ir/ts/tsBooleanKeyword.h" -#include "ir/ts/tsClassImplements.h" -#include "ir/ts/tsConditionalType.h" -#include "ir/ts/tsConstructorType.h" -#include "ir/ts/tsEnumDeclaration.h" -#include "ir/ts/tsEnumMember.h" -#include "ir/ts/tsExternalModuleReference.h" -#include "ir/ts/tsFunctionType.h" -#include "ir/ts/tsImportEqualsDeclaration.h" -#include "ir/ts/tsImportType.h" -#include "ir/ts/tsIndexedAccessType.h" -#include "ir/ts/tsInferType.h" -#include "ir/ts/tsInterfaceBody.h" -#include "ir/ts/tsInterfaceDeclaration.h" -#include "ir/ts/tsInterfaceHeritage.h" -#include "ir/ts/tsIntersectionType.h" -#include "ir/ts/tsLiteralType.h" -#include "ir/ts/tsMappedType.h" -#include "ir/ts/tsModuleBlock.h" -#include "ir/ts/tsModuleDeclaration.h" -#include "ir/ts/tsNamedTupleMember.h" -#include "ir/ts/tsNeverKeyword.h" -#include "ir/ts/tsNonNullExpression.h" -#include "ir/ts/tsNullKeyword.h" -#include "ir/ts/tsNumberKeyword.h" -#include "ir/ts/tsObjectKeyword.h" -#include "ir/ts/tsParameterProperty.h" -#include "ir/ts/tsParenthesizedType.h" -#include "ir/ts/tsQualifiedName.h" -#include "ir/ts/tsStringKeyword.h" -#include "ir/ts/tsThisType.h" -#include "ir/ts/tsTupleType.h" -#include "ir/ts/tsTypeAliasDeclaration.h" -#include "ir/ts/tsTypeAssertion.h" -#include "ir/ts/tsTypeLiteral.h" -#include "ir/ts/tsTypeOperator.h" -#include "ir/ts/tsTypeParameterDeclaration.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsTypePredicate.h" -#include "ir/ts/tsTypeQuery.h" -#include "ir/ts/tsTypeReference.h" -#include "ir/ts/tsUndefinedKeyword.h" -#include "ir/ts/tsUnionType.h" -#include "ir/ts/tsUnknownKeyword.h" -#include "ir/ts/tsVoidKeyword.h" namespace panda::es2panda::checker { class Checker; diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 6b42c2deb681f0d36cb4402187745b155a66a41c..f5bfa79b2f493c500b2a5eb57e720362351182ea 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -16,7 +16,12 @@ #include "TSAnalyzer.h" #include "checker/TSchecker.h" -#include "checker/ts/destructuringContext.h" +#include "ir/base/catchClause.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/scriptFunction.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/returnStatement.h" +#include "ir/typeNode.h" #include "util/helpers.h" namespace panda::es2panda::checker { @@ -59,7 +64,7 @@ checker::Type *TSAnalyzer::Check(ir::CatchClause *st) const checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassDefinition *node) const { TSChecker *checker = GetTSChecker(); - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } @@ -186,39 +191,39 @@ checker::Type *TSAnalyzer::Check(ir::ETSPackageDeclaration *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSParameterExpression *expr) const -{ - UNREACHABLE(); -} - -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSPrimitiveType *node) const +checker::Type *TSAnalyzer::Check(ir::ETSParameterExpression *expr) const { + (void)expr; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSStructDeclaration *node) const +checker::Type *TSAnalyzer::Check(ir::ETSPrimitiveType *node) const { + (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSTypeReference *node) const +checker::Type *TSAnalyzer::Check(ir::ETSStructDeclaration *node) const { + (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSTypeReferencePart *node) const +checker::Type *TSAnalyzer::Check(ir::ETSTypeReference *node) const { + (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ETSUnionType *node) const +checker::Type *TSAnalyzer::Check(ir::ETSTypeReferencePart *node) const { (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSWildcardType *node) const +checker::Type *TSAnalyzer::Check(ir::ETSWildcardType *node) const { + (void)node; UNREACHABLE(); } // compile methods for EXPRESSIONS in alphabetical order @@ -230,35 +235,8 @@ checker::Type *TSAnalyzer::Check(ir::ArrayExpression *expr) const checker::Type *TSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const { - 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())); - - if (!expr->Function()->Body()->IsExpression()) { - expr->Function()->Body()->Check(checker); - } - - return func_type; + (void)expr; + UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::AssignmentExpression *expr) const diff --git a/ets2panda/checker/TSAnalyzer.h b/ets2panda/checker/TSAnalyzer.h index 72f353f284fd76ee7e5630162d1708926a42fcb0..d03ff8ea1490700f951f75166510a080a3d7912d 100644 --- a/ets2panda/checker/TSAnalyzer.h +++ b/ets2panda/checker/TSAnalyzer.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/TSchecker.cpp b/ets2panda/checker/TSchecker.cpp index 672834816b93bb785e1be55bbdc7d0f097f96211..f4b2d6c8b9c1c10d6af3f497af96415824340c9c 100644 --- a/ets2panda/checker/TSchecker.cpp +++ b/ets2panda/checker/TSchecker.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -20,10 +20,10 @@ namespace panda::es2panda::checker { -bool TSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) +bool TSChecker::StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) { - Initialize(varbinder); - varbinder->IdentifierAnalysis(); + Initialize(binder); + binder->IdentifierAnalysis(); if (options.dump_ast) { std::cout << Program()->Dump() << std::endl; diff --git a/ets2panda/checker/TSchecker.h b/ets2panda/checker/TSchecker.h index 37d45b60ac604388b80645124eea48fb22eaad81..e3819833f856ca148d1609ae42802617aeaccb35 100644 --- a/ets2panda/checker/TSchecker.h +++ b/ets2panda/checker/TSchecker.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -17,7 +17,7 @@ #define ES2PANDA_CHECKER_TS_CHECKER_H #include "checker/checker.h" -#include "varbinder/enumMemberResult.h" +#include "binder/enumMemberResult.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/ts/types.h" #include "util/enumbitops.h" @@ -29,15 +29,15 @@ #include #include -namespace panda::es2panda::varbinder { -class VarBinder; +namespace panda::es2panda::binder { +class Binder; class Decl; class EnumVariable; class FunctionDecl; class LocalVariable; class Scope; class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class AstNode; @@ -240,7 +240,7 @@ public: return bigint_literal_map_; } - bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) override; + bool StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) override; Type *CheckTypeCached(ir::Expression *expr) override; // Util @@ -264,20 +264,20 @@ public: Type *ExtractDefinitelyFalsyTypes(Type *type); Type *RemoveDefinitelyFalsyTypes(Type *type); TypeFlag GetFalsyFlags(Type *type); - bool IsVariableUsedInConditionBody(ir::AstNode *parent, varbinder::Variable *search_var); - bool FindVariableInBinaryExpressionChain(ir::AstNode *parent, varbinder::Variable *search_var); - bool IsVariableUsedInBinaryExpressionChain(ir::AstNode *parent, varbinder::Variable *search_var); + bool IsVariableUsedInConditionBody(ir::AstNode *parent, binder::Variable *search_var); + bool FindVariableInBinaryExpressionChain(ir::AstNode *parent, binder::Variable *search_var); + bool IsVariableUsedInBinaryExpressionChain(ir::AstNode *parent, binder::Variable *search_var); [[noreturn]] void ThrowBinaryLikeError(lexer::TokenType op, Type *left_type, Type *right_type, lexer::SourcePosition line_info); [[noreturn]] void ThrowAssignmentError(Type *source, Type *target, lexer::SourcePosition line_info, bool is_as_src_left_type = false); void ElaborateElementwise(Type *target_type, ir::Expression *source_node, const lexer::SourcePosition &pos); void InferSimpleVariableDeclaratorType(ir::VariableDeclarator *declarator); - Type *GetTypeOfVariable(varbinder::Variable *var) override; + Type *GetTypeOfVariable(binder::Variable *var) override; Type *GetUnaryResultType(Type *operand_type); - Type *GetTypeFromClassOrInterfaceReference(ir::TSTypeReference *node, varbinder::Variable *var); - Type *GetTypeFromTypeAliasReference(ir::TSTypeReference *node, varbinder::Variable *var); - Type *GetTypeReferenceType(ir::TSTypeReference *node, varbinder::Variable *var); + Type *GetTypeFromClassOrInterfaceReference(ir::TSTypeReference *node, binder::Variable *var); + Type *GetTypeFromTypeAliasReference(ir::TSTypeReference *node, binder::Variable *var); + Type *GetTypeReferenceType(ir::TSTypeReference *node, binder::Variable *var); // Type creation Type *CreateNumberLiteralType(double value); @@ -304,12 +304,12 @@ public: ArenaVector &signature_declarations); void ResolveIndexInfosOfObjectType(ObjectType *type, ArenaVector &index_declarations); void ResolveDeclaredMembers(InterfaceType *type); - bool ValidateInterfaceMemberRedeclaration(ObjectType *type, varbinder::Variable *prop, + bool ValidateInterfaceMemberRedeclaration(ObjectType *type, binder::Variable *prop, const lexer::SourcePosition &loc_info); - varbinder::Variable *GetPropertyOfType(Type *type, const util::StringView &name, bool get_partial = false, - varbinder::VariableFlags propagate_flags = varbinder::VariableFlags::NONE); - varbinder::Variable *GetPropertyOfUnionType(UnionType *type, const util::StringView &name, bool get_partial, - varbinder::VariableFlags propagate_flags); + binder::Variable *GetPropertyOfType(Type *type, const util::StringView &name, bool get_partial = false, + binder::VariableFlags propagate_flags = binder::VariableFlags::NONE); + binder::Variable *GetPropertyOfUnionType(UnionType *type, const util::StringView &name, bool get_partial, + binder::VariableFlags propagate_flags); void CheckIndexConstraints(Type *type); void ResolveUnionTypeMembers(UnionType *type); void ResolveObjectTypeMembers(ObjectType *type); @@ -323,19 +323,19 @@ public: // Function Type *HandleFunctionReturn(ir::ScriptFunction *func); void CheckFunctionParameterDeclarations(const ArenaVector ¶ms, SignatureInfo *signature_info); - std::tuple CheckFunctionParameter( + std::tuple CheckFunctionParameter( ir::Expression *param, SignatureInfo *signature_info); - std::tuple CheckFunctionIdentifierParameter( + std::tuple CheckFunctionIdentifierParameter( ir::Identifier *param); - std::tuple CheckFunctionAssignmentPatternParameter( + std::tuple CheckFunctionAssignmentPatternParameter( ir::AssignmentExpression *param); - std::tuple CheckFunctionRestParameter( + std::tuple CheckFunctionRestParameter( ir::SpreadElement *param, SignatureInfo *signature_info); - std::tuple CheckFunctionArrayPatternParameter( + std::tuple CheckFunctionArrayPatternParameter( ir::ArrayExpression *param); - std::tuple CheckFunctionObjectPatternParameter( + std::tuple CheckFunctionObjectPatternParameter( ir::ObjectExpression *param); - void InferFunctionDeclarationType(const varbinder::FunctionDecl *decl, varbinder::Variable *func_var); + void InferFunctionDeclarationType(const binder::FunctionDecl *decl, binder::Variable *func_var); void CollectTypesFromReturnStatements(ir::AstNode *parent, ArenaVector *return_types); void CheckAllCodePathsInNonVoidFunctionReturnOrThrow(ir::ScriptFunction *func, lexer::SourcePosition line_info, const char *err_msg); diff --git a/ets2panda/checker/checker.cpp b/ets2panda/checker/checker.cpp index 292edd9efcebe14b07dbf1d45ab23f299b78abde..ff783e86b861ecedd741f7623fe016c49078234f 100644 --- a/ets2panda/checker/checker.cpp +++ b/ets2panda/checker/checker.cpp @@ -20,9 +20,9 @@ #include "ir/statements/blockStatement.h" #include "parser/program/program.h" #include "util/helpers.h" -#include "varbinder/varbinder.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/binder.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "es2panda.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/ts/unionType.h" @@ -41,11 +41,11 @@ Checker::Checker() { } -void Checker::Initialize(varbinder::VarBinder *varbinder) +void Checker::Initialize(binder::Binder *binder) { - varbinder_ = varbinder; - scope_ = varbinder_->TopScope(); - program_ = varbinder_->Program(); + binder_ = binder; + scope_ = binder_->TopScope(); + program_ = binder_->Program(); } std::string Checker::FormatMsg(std::initializer_list list) @@ -93,7 +93,7 @@ void Checker::Warning(const std::string_view message, const lexer::SourcePositio lexer::LineIndex index(program_->SourceCode()); lexer::SourceLocation loc = index.GetLocation(pos); - // NOTE: This should go to stderr but currently the test system does not handle stderr messages + // TODO(user) This should go to stderr but currently the test system does not handle stderr messages auto file_name = program_->SourceFile().Utf8(); file_name = file_name.substr(file_name.find_last_of(panda::os::file::File::GetPathDelim()) + 1); std::cout << "Warning: " << message << " [" << file_name << ":" << loc.line << ":" << loc.col << "]" << std::endl; @@ -211,9 +211,9 @@ void Checker::SetProgram(parser::Program *program) program_ = program; } -varbinder::VarBinder *Checker::VarBinder() const +binder::Binder *Checker::Binder() const { - return varbinder_; + return binder_; } void Checker::SetAnalyzer(SemanticAnalyzer *analyzer) diff --git a/ets2panda/checker/checker.h b/ets2panda/checker/checker.h index 9927c78589745ccaa56b973dd6495904e8a761e0..223836ae38acce4da3260c7bbff70389d990d4b6 100644 --- a/ets2panda/checker/checker.h +++ b/ets2panda/checker/checker.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_CHECKER_CHECKER_H #define ES2PANDA_CHECKER_CHECKER_H -#include "varbinder/enumMemberResult.h" +#include "binder/enumMemberResult.h" #include "checker/checkerContext.h" #include "checker/SemanticAnalyzer.h" #include "checker/types/typeRelation.h" @@ -42,15 +42,15 @@ class BlockStatement; enum class AstNodeType; } // namespace panda::es2panda::ir -namespace panda::es2panda::varbinder { -class VarBinder; +namespace panda::es2panda::binder { +class Binder; class Decl; class EnumVariable; class FunctionDecl; class LocalVariable; class Scope; class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class ETSChecker; @@ -59,12 +59,11 @@ class GlobalTypesHolder; using StringLiteralPool = std::unordered_map; using NumberLiteralPool = std::unordered_map; -using FunctionParamsResolveResult = std::variant &, bool>; -using InterfacePropertyMap = - std::unordered_map>; +using FunctionParamsResolveResult = std::variant &, bool>; +using InterfacePropertyMap = std::unordered_map>; using TypeOrNode = std::variant; using IndexInfoTypePair = std::pair; -using PropertyMap = std::unordered_map; +using PropertyMap = std::unordered_map; using ArgRange = std::pair; class Checker { @@ -79,7 +78,7 @@ public: return &allocator_; } - varbinder::Scope *Scope() const + binder::Scope *Scope() const { return scope_; } @@ -149,9 +148,9 @@ public: return reinterpret_cast(this); } - virtual bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) = 0; + virtual bool StartChecker([[maybe_unused]] binder::Binder *binder, const CompilerOptions &options) = 0; virtual Type *CheckTypeCached(ir::Expression *expr) = 0; - virtual Type *GetTypeOfVariable(varbinder::Variable *var) = 0; + virtual Type *GetTypeOfVariable(binder::Variable *var) = 0; virtual void ResolveStructuredTypeMembers(Type *type) = 0; std::string FormatMsg(std::initializer_list list); @@ -186,10 +185,10 @@ public: friend class TypeStackElement; friend class SavedCheckerContext; - varbinder::VarBinder *VarBinder() const; + binder::Binder *Binder() const; protected: - void Initialize(varbinder::VarBinder *varbinder); + void Initialize(binder::Binder *binder); parser::Program *Program() const; void SetProgram(parser::Program *program); @@ -199,9 +198,9 @@ private: GlobalTypesHolder *global_types_; TypeRelation *relation_; SemanticAnalyzer *analyzer_ {}; - varbinder::VarBinder *varbinder_ {}; + binder::Binder *binder_ {}; parser::Program *program_ {}; - varbinder::Scope *scope_ {}; + binder::Scope *scope_ {}; RelationHolder identical_results_; RelationHolder assignable_results_; @@ -245,8 +244,7 @@ private: class ScopeContext { public: - explicit ScopeContext(Checker *checker, varbinder::Scope *new_scope) - : checker_(checker), prev_scope_(checker_->scope_) + explicit ScopeContext(Checker *checker, binder::Scope *new_scope) : checker_(checker), prev_scope_(checker_->scope_) { checker_->scope_ = new_scope; } @@ -261,7 +259,7 @@ public: private: Checker *checker_; - varbinder::Scope *prev_scope_; + binder::Scope *prev_scope_; }; class SavedCheckerContext { diff --git a/ets2panda/checker/checkerContext.h b/ets2panda/checker/checkerContext.h index d1b9ba20978ec2e57871fa11e6d16f5e5c502475..4e62f10e77f15b4a0983c65638255b7c6aef4eb4 100644 --- a/ets2panda/checker/checkerContext.h +++ b/ets2panda/checker/checkerContext.h @@ -17,7 +17,7 @@ #define ES2PANDA_CHECKER_CHECKER_CONTEXT_H #include -#include "varbinder/variable.h" +#include "binder/variable.h" #include "util/enumbitops.h" #include @@ -49,7 +49,7 @@ enum class CheckerStatus : uint32_t { DEFINE_BITOPS(CheckerStatus) -using CapturedVarsMap = ArenaUnorderedMap; +using CapturedVarsMap = ArenaUnorderedMap; class CheckerContext { public: @@ -112,7 +112,7 @@ public: containing_class_ = containing_class; } - void AddCapturedVar(varbinder::Variable *var, const lexer::SourcePosition &pos) + void AddCapturedVar(binder::Variable *var, const lexer::SourcePosition &pos) { captured_vars_.emplace(var, pos); } diff --git a/ets2panda/checker/ets/aliveAnalyzer.cpp b/ets2panda/checker/ets/aliveAnalyzer.cpp index bcc0bb107f31cfdaf377b3ad4f7994d0662be354..c47f5915e9b4cbc7eed077c56d4da589b7478631 100644 --- a/ets2panda/checker/ets/aliveAnalyzer.cpp +++ b/ets2panda/checker/ets/aliveAnalyzer.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -43,9 +43,9 @@ #include "ir/ets/etsNewClassInstanceExpression.h" #include "ir/ets/etsStructDeclaration.h" #include "ir/ts/tsInterfaceDeclaration.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" #include "checker/ETSchecker.h" #include "ir/base/catchClause.h" @@ -300,9 +300,10 @@ void AliveAnalyzer::AnalyzeDoLoop(const ir::DoWhileStatement *do_while) AnalyzeStat(do_while->Body()); status_ = Or(status_, ResolveContinues(do_while)); AnalyzeNode(do_while->Test()); - ASSERT(do_while->Test()->TsType() && do_while->Test()->TsType()->IsConditionalExprType()); - const auto expr_res = do_while->Test()->TsType()->ResolveConditionExpr(); - status_ = And(status_, static_cast(!std::get<0>(expr_res) || !std::get<1>(expr_res))); + ASSERT(do_while->Test()->TsType() && do_while->Test()->TsType()->IsETSBooleanType()); + auto *cond_type = do_while->Test()->TsType()->AsETSBooleanType(); + status_ = And(status_, + static_cast(!(cond_type->HasTypeFlag(TypeFlag::CONSTANT) && cond_type->GetValue()))); status_ = Or(status_, ResolveBreaks(do_while)); } @@ -310,28 +311,26 @@ void AliveAnalyzer::AnalyzeWhileLoop(const ir::WhileStatement *while_stmt) { SetOldPendingExits(PendingExits()); AnalyzeNode(while_stmt->Test()); - ASSERT(while_stmt->Test()->TsType() && while_stmt->Test()->TsType()->IsConditionalExprType()); - const auto expr_res = while_stmt->Test()->TsType()->ResolveConditionExpr(); - status_ = And(status_, static_cast(!std::get<0>(expr_res) || std::get<1>(expr_res))); + ASSERT(while_stmt->Test()->TsType() && while_stmt->Test()->TsType()->IsETSBooleanType()); + auto *cond_type = while_stmt->Test()->TsType()->AsETSBooleanType(); + status_ = And(status_, + static_cast(!(cond_type->HasTypeFlag(TypeFlag::CONSTANT) && !cond_type->GetValue()))); AnalyzeStat(while_stmt->Body()); status_ = Or(status_, ResolveContinues(while_stmt)); - status_ = Or(ResolveBreaks(while_stmt), From(!std::get<0>(expr_res) || !std::get<1>(expr_res))); + status_ = + Or(ResolveBreaks(while_stmt), From(!(cond_type->HasTypeFlag(TypeFlag::CONSTANT) && cond_type->GetValue()))); } void AliveAnalyzer::AnalyzeForLoop(const ir::ForUpdateStatement *for_stmt) { AnalyzeNode(for_stmt->Init()); SetOldPendingExits(PendingExits()); - const Type *cond_type {}; - bool resolve_type = false; - bool res = false; - + const ETSBooleanType *cond_type {}; if (for_stmt->Test() != nullptr) { AnalyzeNode(for_stmt->Test()); - ASSERT(for_stmt->Test()->TsType() && for_stmt->Test()->TsType()->IsConditionalExprType()); - cond_type = for_stmt->Test()->TsType(); - std::tie(resolve_type, res) = for_stmt->Test()->TsType()->ResolveConditionExpr(); - status_ = From(!resolve_type || res); + ASSERT(for_stmt->Test()->TsType() && for_stmt->Test()->TsType()->IsETSBooleanType()); + cond_type = for_stmt->Test()->TsType()->AsETSBooleanType(); + status_ = From(!(cond_type->HasTypeFlag(TypeFlag::CONSTANT) && !cond_type->GetValue())); } else { status_ = LivenessStatus::ALIVE; } @@ -339,7 +338,8 @@ void AliveAnalyzer::AnalyzeForLoop(const ir::ForUpdateStatement *for_stmt) AnalyzeStat(for_stmt->Body()); status_ = Or(status_, ResolveContinues(for_stmt)); AnalyzeNode(for_stmt->Update()); - status_ = Or(ResolveBreaks(for_stmt), From(cond_type != nullptr && (!resolve_type || !res))); + status_ = Or(ResolveBreaks(for_stmt), + From(cond_type != nullptr && !(cond_type->HasTypeFlag(TypeFlag::CONSTANT) && cond_type->GetValue()))); } void AliveAnalyzer::AnalyzeForOfLoop(const ir::ForOfStatement *for_of_stmt) @@ -428,7 +428,7 @@ void AliveAnalyzer::AnalyzeSwitch(const ir::SwitchStatement *switch_stmt) AnalyzeStats(case_clause->Consequent()); if (status_ == LivenessStatus::ALIVE && !case_clause->Consequent().empty() && i < size - 1) { - // NOTE Add lint categories and option to enable/disable compiler warnings + // TODO(user) Add lint categories and option to enable/disable compiler warnings checker_->Warning("Possible fall-through into case", case_clause->Start()); } } diff --git a/ets2panda/checker/ets/aliveAnalyzer.h b/ets2panda/checker/ets/aliveAnalyzer.h index c9c80f2d01903e2246c3cb2b3d7724622b4d4852..948b0472e3fb03d82d75603941df186655d51055 100644 --- a/ets2panda/checker/ets/aliveAnalyzer.h +++ b/ets2panda/checker/ets/aliveAnalyzer.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 6f112eb89d7d43c64e7c3e1da884f771e7c53faf..d5fd4872f8932d998a04c6fc478461cb6f19cc47 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -16,9 +16,9 @@ #include "arithmetic.h" #include "ir/expressions/identifier.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" #include "checker/ETSchecker.h" namespace panda::es2panda::checker { @@ -126,321 +126,15 @@ Type *ETSChecker::HandleRelationOperationOnTypes(Type *left, Type *right, lexer: return PerformRelationOperationOnTypes(left, right, operation_type); } -checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *const left_type, - checker::Type *const right_type, Type *unboxed_l, - Type *unboxed_r) -{ - checker::Type *ts_type {}; - auto [promotedType, bothConst] = - ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - if (promotedType == nullptr && !bothConst) { - ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); - } - - if (bothConst) { - ts_type = HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); - } - - ts_type = (ts_type != nullptr) ? ts_type : promotedType; - return ts_type; -} - -checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *const left_type, - checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - if (left_type->IsETSStringType() || right_type->IsETSStringType()) { - return HandleStringConcatenation(left_type, right_type); - } - - auto [promotedType, bothConst] = - ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - if (promotedType == nullptr && !bothConst) { - ThrowTypeError("Bad operand type, the types of the operands must be numeric type or String.", pos); - } - - if (bothConst) { - return HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); - } - - return promotedType; -} - -checker::Type *ETSChecker::CheckBinaryOperatorShift(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *const left_type, - checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - auto promoted_left_type = ApplyUnaryOperatorPromotion(unboxed_l, false, !is_equal_op); - auto promoted_right_type = ApplyUnaryOperatorPromotion(unboxed_r, false, !is_equal_op); - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - if (promoted_left_type == nullptr || !promoted_left_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL) || - promoted_right_type == nullptr || !promoted_right_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL)) { - ThrowTypeError("Bad operand type, the types of the operands must be integral type.", pos); - } - - if (promoted_left_type->HasTypeFlag(TypeFlag::CONSTANT) && promoted_right_type->HasTypeFlag(TypeFlag::CONSTANT)) { - return HandleArithmeticOperationOnTypes(promoted_left_type, promoted_right_type, operation_type); - } - - switch (ETSType(promoted_left_type)) { - case TypeFlag::BYTE: { - return GlobalByteType(); - } - case TypeFlag::SHORT: { - return GlobalShortType(); - } - case TypeFlag::CHAR: { - return GlobalCharType(); - } - case TypeFlag::INT: { - return GlobalIntType(); - } - case TypeFlag::LONG: { - return GlobalLongType(); - } - default: { - UNREACHABLE(); - } - } - return nullptr; -} - -checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir::Expression *right, - lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *const left_type, - checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - if (unboxed_l != nullptr && unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxed_r != nullptr && - unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - return HandleBooleanLogicalOperators(unboxed_l, unboxed_r, operation_type); - } - - auto [promotedType, bothConst] = - ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_INTEGRAL, !is_equal_op); - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - if (promotedType == nullptr && !bothConst) { - ThrowTypeError("Bad operand type, the types of the operands must be integral type.", pos); - } - - if (bothConst) { - return HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); - } - - return promotedType; -} - -checker::Type *ETSChecker::CheckBinaryOperatorLogical(ir::Expression *left, ir::Expression *right, ir::Expression *expr, - lexer::SourcePosition pos, checker::Type *const left_type, - checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - if (unboxed_l == nullptr || !unboxed_l->IsConditionalExprType() || unboxed_r == nullptr || - !unboxed_r->IsConditionalExprType()) { - ThrowTypeError("Bad operand type, the types of the operands must be of possible condition type.", pos); - } - - if (unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - } - - if (unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - } - - if (expr->IsBinaryExpression()) { - return HandleBooleanLogicalOperatorsExtended(unboxed_l, unboxed_r, expr->AsBinaryExpression()); - } - - UNREACHABLE(); -} - -std::tuple ETSChecker::CheckBinaryOperatorStrictEqual(ir::Expression *left, lexer::SourcePosition pos, - checker::Type *const left_type, - checker::Type *const right_type) -{ - checker::Type *ts_type {}; - if (!(left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) || - !(right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT))) { - ThrowTypeError("Both operands have to be reference types", pos); - } - - Relation()->SetNode(left); - if (!Relation()->IsCastableTo(left_type, right_type) && !Relation()->IsCastableTo(right_type, left_type)) { - ThrowTypeError("The operands of strict equality are not compatible with each other", pos); - } - ts_type = GlobalETSBooleanType(); - if (right_type->IsETSDynamicType() && left_type->IsETSDynamicType()) { - return {ts_type, GlobalBuiltinJSValueType()}; - } - return {ts_type, GlobalETSObjectType()}; -} - -std::tuple ETSChecker::CheckBinaryOperatorEqual( - ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, - checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - checker::Type *ts_type {}; - if (left_type->IsETSEnumType() && right_type->IsETSEnumType()) { - if (!left_type->AsETSEnumType()->IsSameEnumType(right_type->AsETSEnumType())) { - ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); - } - - ts_type = GlobalETSBooleanType(); - return {ts_type, left_type}; - } - - if (left_type->IsETSStringEnumType() && right_type->IsETSStringEnumType()) { - if (!left_type->AsETSStringEnumType()->IsSameEnumType(right_type->AsETSStringEnumType())) { - ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); - } - - ts_type = GlobalETSBooleanType(); - return {ts_type, left_type}; - } - - if (IsReferenceType(left_type) && IsReferenceType(right_type)) { - ts_type = GlobalETSBooleanType(); - auto *op_type = GlobalETSObjectType(); - return {ts_type, op_type}; - } - - if (unboxed_l != nullptr && unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxed_r != nullptr && - unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { - if (unboxed_l->HasTypeFlag(checker::TypeFlag::CONSTANT) && - unboxed_r->HasTypeFlag(checker::TypeFlag::CONSTANT)) { - bool res = unboxed_l->AsETSBooleanType()->GetValue() == unboxed_r->AsETSBooleanType()->GetValue(); - - ts_type = CreateETSBooleanType(operation_type == lexer::TokenType::PUNCTUATOR_EQUAL ? res : !res); - return {ts_type, ts_type}; - } - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - ts_type = GlobalETSBooleanType(); - return {ts_type, ts_type}; - } - return {nullptr, nullptr}; -} - -std::tuple ETSChecker::CheckBinaryOperatorLessGreater( - ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, - bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) -{ - checker::Type *ts_type {}; - auto [promotedType, bothConst] = - ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); - - FlagExpressionWithUnboxing(left_type, unboxed_l, left); - FlagExpressionWithUnboxing(right_type, unboxed_r, right); - - if (left_type->IsETSUnionType()) { - ts_type = GlobalETSBooleanType(); - return {ts_type, left_type->AsETSUnionType()}; - } - - if (right_type->IsETSUnionType()) { - ts_type = GlobalETSBooleanType(); - return {ts_type, right_type->AsETSUnionType()}; - } - - if (promotedType == nullptr && !bothConst) { - ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); - } - - if (bothConst) { - ts_type = HandleRelationOperationOnTypes(left_type, right_type, operation_type); - return {ts_type, ts_type}; - } - - ts_type = GlobalETSBooleanType(); - auto *op_type = promotedType; - return {ts_type, op_type}; -} - -std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::SourcePosition pos, - checker::Type *const left_type, - checker::Type *const right_type) -{ - checker::Type *ts_type {}; - if (!left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION) || - !right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { - ThrowTypeError("Bad operand type, the types of the operands must be same type.", pos); - } - - if (right_type->IsETSDynamicType() || left_type->IsETSDynamicType()) { - if (!(right_type->IsETSDynamicType() && left_type->IsETSDynamicType())) { - ThrowTypeError("Bad operand type, both types of the operands must be dynamic.", pos); - } - } - - ts_type = GlobalETSBooleanType(); - checker::Type *op_type = right_type->IsETSDynamicType() ? GlobalBuiltinJSValueType() : GlobalETSObjectType(); - return {ts_type, op_type}; -} - -Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, lexer::SourcePosition pos, - checker::Type *const left_type, checker::Type *const right_type) -{ - if (!left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { - ThrowTypeError("Left-hand side expression must be a reference type.", pos); - } - - checker::Type *non_nullable_left_type = left_type; - - if (left_type->IsNullableType()) { - non_nullable_left_type = left_type->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder()); - non_nullable_left_type->RemoveTypeFlag(TypeFlag::NULLABLE); - } - - // NOTE: check convertibility and use numeric promotion - - if (right_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - Relation()->SetNode(right); - auto boxed_right_type = PrimitiveTypeAsETSBuiltinType(right_type); - if (boxed_right_type == nullptr) { - ThrowTypeError("Invalid right-hand side expression", pos); - } - right->AddBoxingUnboxingFlag(GetBoxingFlag(boxed_right_type)); - return FindLeastUpperBound(non_nullable_left_type, boxed_right_type); - } - - return FindLeastUpperBound(non_nullable_left_type, right_type); -} - // NOLINTNEXTLINE(readability-function-size) std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, ir::Expression *right, - ir::Expression *expr, lexer::TokenType operation_type, - lexer::SourcePosition pos, bool force_promotion) + lexer::TokenType operation_type, lexer::SourcePosition pos, + bool force_promotion) { checker::Type *const left_type = left->Check(this); checker::Type *const right_type = right->Check(this); - const bool is_logical_extended_operator = (operation_type == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) || - (operation_type == lexer::TokenType::PUNCTUATOR_LOGICAL_OR); - Type *unboxed_l = is_logical_extended_operator ? ETSBuiltinTypeAsConditionalType(left_type) - : ETSBuiltinTypeAsPrimitiveType(left_type); - Type *unboxed_r = is_logical_extended_operator ? ETSBuiltinTypeAsConditionalType(right_type) - : ETSBuiltinTypeAsPrimitiveType(right_type); - + Type *unboxed_l = ETSBuiltinTypeAsPrimitiveType(left_type); + Type *unboxed_r = ETSBuiltinTypeAsPrimitiveType(right_type); checker::Type *ts_type {}; bool is_equal_op = (operation_type > lexer::TokenType::PUNCTUATOR_SUBSTITUTION && operation_type < lexer::TokenType::PUNCTUATOR_ARROW) && @@ -453,10 +147,24 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, case lexer::TokenType::PUNCTUATOR_DIVIDE_EQUAL: case lexer::TokenType::PUNCTUATOR_MOD: case lexer::TokenType::PUNCTUATOR_MOD_EQUAL: { - ts_type = CheckBinaryOperatorMulDivMod(left, right, operation_type, pos, is_equal_op, left_type, right_type, - unboxed_l, unboxed_r); + auto [promotedType, bothConst] = + ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + if (promotedType == nullptr && !bothConst) { + ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); + } + + if (bothConst) { + ts_type = HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); + } + + ts_type = (ts_type != nullptr) ? ts_type : promotedType; break; } + case lexer::TokenType::PUNCTUATOR_MINUS: case lexer::TokenType::PUNCTUATOR_MINUS_EQUAL: { if (left_type->IsETSStringType() || right_type->IsETSStringType()) { @@ -467,8 +175,27 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, } case lexer::TokenType::PUNCTUATOR_PLUS: case lexer::TokenType::PUNCTUATOR_PLUS_EQUAL: { - ts_type = CheckBinaryOperatorPlus(left, right, operation_type, pos, is_equal_op, left_type, right_type, - unboxed_l, unboxed_r); + if (left_type->IsETSStringType() || right_type->IsETSStringType()) { + ts_type = HandleStringConcatenation(left_type, right_type); + break; + } + + auto [promotedType, bothConst] = + ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + if (promotedType == nullptr && !bothConst) { + ThrowTypeError("Bad operand type, the types of the operands must be numeric type or String.", pos); + } + + if (bothConst) { + ts_type = HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); + break; + } + + ts_type = promotedType; break; } case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: @@ -477,8 +204,49 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT_EQUAL: case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT_EQUAL: { - ts_type = CheckBinaryOperatorShift(left, right, operation_type, pos, is_equal_op, left_type, right_type, - unboxed_l, unboxed_r); + auto promoted_left_type = ApplyUnaryOperatorPromotion(unboxed_l, false, !is_equal_op); + auto promoted_right_type = ApplyUnaryOperatorPromotion(unboxed_r, false, !is_equal_op); + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + if (promoted_left_type == nullptr || !promoted_left_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL) || + promoted_right_type == nullptr || !promoted_right_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL)) { + ThrowTypeError("Bad operand type, the types of the operands must be integral type.", pos); + } + + if (promoted_left_type->HasTypeFlag(TypeFlag::CONSTANT) && + promoted_right_type->HasTypeFlag(TypeFlag::CONSTANT)) { + ts_type = HandleArithmeticOperationOnTypes(promoted_left_type, promoted_right_type, operation_type); + break; + } + + switch (ETSType(promoted_left_type)) { + case TypeFlag::BYTE: { + ts_type = GlobalByteType(); + break; + } + case TypeFlag::SHORT: { + ts_type = GlobalShortType(); + break; + } + case TypeFlag::CHAR: { + ts_type = GlobalCharType(); + break; + } + case TypeFlag::INT: { + ts_type = GlobalIntType(); + break; + } + case TypeFlag::LONG: { + ts_type = GlobalLongType(); + break; + } + default: { + UNREACHABLE(); + } + } + break; } case lexer::TokenType::PUNCTUATOR_BITWISE_OR: @@ -487,44 +255,177 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, case lexer::TokenType::PUNCTUATOR_BITWISE_AND_EQUAL: case lexer::TokenType::PUNCTUATOR_BITWISE_XOR_EQUAL: case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: { - ts_type = CheckBinaryOperatorBitwise(left, right, operation_type, pos, is_equal_op, left_type, right_type, - unboxed_l, unboxed_r); + if (unboxed_l != nullptr && unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && + unboxed_r != nullptr && unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + ts_type = HandleBooleanLogicalOperators(unboxed_l, unboxed_r, operation_type); + break; + } + + auto [promotedType, bothConst] = + ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_INTEGRAL, !is_equal_op); + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + if (promotedType == nullptr && !bothConst) { + ThrowTypeError("Bad operand type, the types of the operands must be integral type.", pos); + } + + if (bothConst) { + ts_type = HandleArithmeticOperationOnTypes(left_type, right_type, operation_type); + break; + } + + ts_type = promotedType; break; } case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - ts_type = CheckBinaryOperatorLogical(left, right, expr, pos, left_type, right_type, unboxed_l, unboxed_r); + if (unboxed_l == nullptr || !unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) || + unboxed_r == nullptr || !unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { + ThrowTypeError("Bad operand type, the types of the operands must be boolean type.", pos); + } + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + ts_type = HandleBooleanLogicalOperators(unboxed_l, unboxed_r, operation_type); break; } case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: { - return CheckBinaryOperatorStrictEqual(left, pos, left_type, right_type); + if (!(left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) || + !(right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT))) { + ThrowTypeError("Both operands have to be reference types", pos); + } + + Relation()->SetNode(left); + if (!Relation()->IsCastableTo(left_type, right_type) && !Relation()->IsCastableTo(right_type, left_type)) { + ThrowTypeError("The operands of strict equality are not compatible with each other", pos); + } + ts_type = GlobalETSBooleanType(); + if (right_type->IsETSDynamicType() && left_type->IsETSDynamicType()) { + return {ts_type, GlobalBuiltinJSValueType()}; + } + return {ts_type, GlobalETSObjectType()}; } case lexer::TokenType::PUNCTUATOR_EQUAL: case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: { - std::tuple res = - CheckBinaryOperatorEqual(left, right, operation_type, pos, left_type, right_type, unboxed_l, unboxed_r); - if (!(std::get<0>(res) == nullptr && std::get<1>(res) == nullptr)) { - return res; + if (left_type->IsETSEnumType() && right_type->IsETSEnumType()) { + if (!left_type->AsETSEnumType()->IsSameEnumType(right_type->AsETSEnumType())) { + ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); + } + + ts_type = GlobalETSBooleanType(); + return {ts_type, left_type}; + } + + if (left_type->IsETSStringEnumType() && right_type->IsETSStringEnumType()) { + if (!left_type->AsETSStringEnumType()->IsSameEnumType(right_type->AsETSStringEnumType())) { + ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); + } + + ts_type = GlobalETSBooleanType(); + return {ts_type, left_type}; + } + + if (IsReferenceType(left_type) && IsReferenceType(right_type)) { + ts_type = GlobalETSBooleanType(); + auto *op_type = GlobalETSObjectType(); + return {ts_type, op_type}; } + + if (unboxed_l != nullptr && unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && + unboxed_r != nullptr && unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { + if (unboxed_l->HasTypeFlag(checker::TypeFlag::CONSTANT) && + unboxed_r->HasTypeFlag(checker::TypeFlag::CONSTANT)) { + bool res = unboxed_l->AsETSBooleanType()->GetValue() == unboxed_r->AsETSBooleanType()->GetValue(); + + ts_type = CreateETSBooleanType(operation_type == lexer::TokenType::PUNCTUATOR_EQUAL ? res : !res); + break; + } + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + ts_type = GlobalETSBooleanType(); + break; + } + [[fallthrough]]; } case lexer::TokenType::PUNCTUATOR_LESS_THAN: case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: case lexer::TokenType::PUNCTUATOR_GREATER_THAN: case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: { - return CheckBinaryOperatorLessGreater(left, right, operation_type, pos, is_equal_op, left_type, right_type, - unboxed_l, unboxed_r); + auto [promotedType, bothConst] = + ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); + + FlagExpressionWithUnboxing(left_type, unboxed_l, left); + FlagExpressionWithUnboxing(right_type, unboxed_r, right); + + if (promotedType == nullptr && !bothConst) { + ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); + } + + if (bothConst) { + ts_type = HandleRelationOperationOnTypes(left_type, right_type, operation_type); + break; + } + + ts_type = GlobalETSBooleanType(); + auto *op_type = promotedType; + return {ts_type, op_type}; } case lexer::TokenType::KEYW_INSTANCEOF: { - return CheckBinaryOperatorInstanceOf(pos, left_type, right_type); + if (!left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || + !right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + ThrowTypeError("Bad operand type, the types of the operands must be same type.", pos); + } + + if (right_type->IsETSDynamicType() || left_type->IsETSDynamicType()) { + if (!(right_type->IsETSDynamicType() && left_type->IsETSDynamicType())) { + ThrowTypeError("Bad operand type, both types of the operands must be dynamic.", pos); + } + } + + ts_type = GlobalETSBooleanType(); + checker::Type *op_type = + right_type->IsETSDynamicType() ? GlobalBuiltinJSValueType() : GlobalETSObjectType(); + return {ts_type, op_type}; } case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { - ts_type = CheckBinaryOperatorNullishCoalescing(right, pos, left_type, right_type); + if (!left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + ThrowTypeError("Left-hand side expression must be a reference type.", pos); + } + + checker::Type *non_nullable_left_type = left_type; + + if (left_type->IsNullableType()) { + non_nullable_left_type = left_type->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder()); + non_nullable_left_type->RemoveTypeFlag(TypeFlag::NULLABLE); + } + + // TODO(user): check convertibility and use numeric promotion + + if (right_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + Relation()->SetNode(right); + auto boxed_right_type = PrimitiveTypeAsETSBuiltinType(right_type); + if (boxed_right_type == nullptr) { + ThrowTypeError("Invalid right-hand side expression", pos); + } + right->AddBoxingUnboxingFlag(GetBoxingFlag(boxed_right_type)); + ts_type = FindLeastUpperBound(non_nullable_left_type, boxed_right_type); + break; + } + + ts_type = FindLeastUpperBound(non_nullable_left_type, right_type); break; } default: { - // NOTE + // TODO(user): UNREACHABLE(); break; } diff --git a/ets2panda/checker/ets/arithmetic.h b/ets2panda/checker/ets/arithmetic.h index 5471d52e97513f69a28659423bd5e945df52dfa9..cd5e720afde351e53179787f498e401ccc287aca 100644 --- a/ets2panda/checker/ets/arithmetic.h +++ b/ets2panda/checker/ets/arithmetic.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/checker/ets/baseAnalyzer.cpp b/ets2panda/checker/ets/baseAnalyzer.cpp index 18cbe6fe290720718977c749ac22c4fa89574be5..fb05670f566354249acd3b867cd2a0de5ef3303e 100644 --- a/ets2panda/checker/ets/baseAnalyzer.cpp +++ b/ets2panda/checker/ets/baseAnalyzer.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/checker/ets/baseAnalyzer.h b/ets2panda/checker/ets/baseAnalyzer.h index 039fbe34f6ca7e7f87cd68d084ac2940fcaa4293..bcee5fc399fc2ae390f04a543e793b5d47eda574 100644 --- a/ets2panda/checker/ets/baseAnalyzer.h +++ b/ets2panda/checker/ets/baseAnalyzer.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/boxingConverter.cpp b/ets2panda/checker/ets/boxingConverter.cpp index 5bc90847f7c58b122928823161922c005dcca5c2..f65512001c0af80b72f71e57d1f7de0cedcfcf03 100644 --- a/ets2panda/checker/ets/boxingConverter.cpp +++ b/ets2panda/checker/ets/boxingConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/boxingConverter.h b/ets2panda/checker/ets/boxingConverter.h index ed53d9db60b61f8f91fd08fcf341cf66b6829ff0..ecd0dd0042a35b3f0a4f7ab86db1abce31cc5ace 100644 --- a/ets2panda/checker/ets/boxingConverter.h +++ b/ets2panda/checker/ets/boxingConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/castingContext.cpp b/ets2panda/checker/ets/castingContext.cpp index a9c5418494b24cb50f003d9d2aac530f8846d277..7d70c66d40884d5ff83595b1995234432b2c161f 100644 --- a/ets2panda/checker/ets/castingContext.cpp +++ b/ets2panda/checker/ets/castingContext.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/ets/castingContext.h b/ets2panda/checker/ets/castingContext.h index c5ff8257b868f3157b08d7ca98d30663bac0f43a..527ff8a22538dab670b8a9607c87c3cb41fdf120 100644 --- a/ets2panda/checker/ets/castingContext.h +++ b/ets2panda/checker/ets/castingContext.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/ets/conversion.cpp b/ets2panda/checker/ets/conversion.cpp index 2c9ac1fa405c06cd9fe914f085cb0cd7d1707f42..4804f788b36dc9d362103e01d8b487e93491e7ec 100644 --- a/ets2panda/checker/ets/conversion.cpp +++ b/ets2panda/checker/ets/conversion.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -86,7 +86,7 @@ bool IsAllowedNarrowingReferenceConversion(TypeRelation *const relation, Type *c // - If there exists a parameterized type X that is a supertype of T, and a parameterized type Y that is a supertype // of S, such that the erasures of X and Y are the same, then X and Y are not provably distinct - // NOTE: implement + // TODO(user): implement // - One of the following cases applies: @@ -95,7 +95,7 @@ bool IsAllowedNarrowingReferenceConversion(TypeRelation *const relation, Type *c auto *const t = target->AsETSObjectType(); // 1. S and T are class types, and either |S| <: |T| or |T| <: |S|. - // NOTE: use type erased S and T + // FIXME: use type erased S and T relation->Result(false); if ((t->IsSupertypeOf(relation, s), relation->IsTrue()) || (s->IsSupertypeOf(relation, t), relation->IsTrue())) { @@ -138,7 +138,7 @@ bool IsAllowedNarrowingReferenceConversion(TypeRelation *const relation, Type *c if (source->HasTypeFlag(TypeFlag::ETS_OBJECT) && target->HasTypeFlag(TypeFlag::ETS_ARRAY)) { // 7. S is the class type Object of the interface type java.io.Serializable or Cloneable (the only interfaces // implemented by arrays (link to class objects for arrays)), and T is an array type. - // NOTE: implement + // TODO(user): implement return true; } @@ -158,21 +158,21 @@ bool IsAllowedNarrowingReferenceConversion(TypeRelation *const relation, Type *c } // 9. S is a type variable, and a narrowing reference conversion exists from the upper bound of S to T. - // NOTE:: implement + // TODO(user): implement // 10. T is a type variable, and either a widening reference conversion or a narrowing reference conversion exists // from S to the upper bound of T. - // NOTE: implement + // TODO(user): implement // 11. S is an intersection type S1 & … & Sn, and for all i (1 ≤ i ≤ n), either a widening reference // conversion or a // narrowing reference conversion exists from Si to T. - // NOTE: implement + // TODO(user): implement // 12. T is an intersection type T1 & … & Tn, and for all i (1 ≤ i ≤ n), either a widening reference // conversion or a // narrowing reference conversion exists from S to Ti. - // NOTE: implement + // TODO(user): implement return false; } @@ -193,7 +193,7 @@ bool IsUncheckedNarrowingReferenceConversion([[maybe_unused]] TypeRelation *cons // - A narrowing reference conversion from a type S to an intersection type T1 & … & Tn // is unchecked if there exists a Ti (1 ≤ i ≤ n) such that S is not a subtype of Ti, and a // narrowing reference conversion from S to Ti is unchecked. - // NOTE: implement + // TODO(user): implement return false; } diff --git a/ets2panda/checker/ets/conversion.h b/ets2panda/checker/ets/conversion.h index 2b94bfbfc6cfd3526ee1eb240955c6a3da5b3c74..af4fb8bf0ec3b06105e6ddeecf68219d8416860d 100644 --- a/ets2panda/checker/ets/conversion.h +++ b/ets2panda/checker/ets/conversion.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/ets/dynamic.cpp b/ets2panda/checker/ets/dynamic.cpp index 69c9b8526815b156243b20ee8c9d8dcffb606b32..02aac052b538e6e6cc31bbe276fc5c2e0336959e 100644 --- a/ets2panda/checker/ets/dynamic.cpp +++ b/ets2panda/checker/ets/dynamic.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,10 +15,10 @@ #include "checker/ETSchecker.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" +#include "binder/scope.h" +#include "binder/declaration.h" +#include "binder/binder.h" +#include "binder/ETSBinder.h" #include "checker/types/ets/etsDynamicFunctionType.h" #include "ir/base/classProperty.h" #include "ir/base/classStaticBlock.h" @@ -46,20 +46,20 @@ namespace panda::es2panda::checker { -ir::ETSParameterExpression *ETSChecker::AddParam(varbinder::FunctionParamScope *param_scope, util::StringView name, +ir::ETSParameterExpression *ETSChecker::AddParam(binder::FunctionParamScope *param_scope, util::StringView name, checker::Type *type) { - auto param_ctx = varbinder::LexicalScope::Enter(VarBinder(), param_scope, false); + auto param_ctx = binder::LexicalScope::Enter(Binder(), param_scope, false); auto *param_ident = AllocNode(name, Allocator()); auto *param = AllocNode(param_ident, nullptr); - auto *param_var = std::get<1>(VarBinder()->AddParamDecl(param)); + auto *param_var = std::get<1>(Binder()->AddParamDecl(param)); param_var->SetTsType(type); param->Ident()->SetVariable(param_var); param->Ident()->SetTsType(type); return param; } -static bool IsByValueCall(varbinder::ETSBinder *varbinder, ir::Expression *callee) +static bool IsByValueCall(binder::ETSBinder *binder, ir::Expression *callee) { if (callee->IsMemberExpression()) { return !callee->AsMemberExpression()->ObjType()->IsETSDynamicType(); @@ -70,7 +70,7 @@ static bool IsByValueCall(varbinder::ETSBinder *varbinder, ir::Expression *calle } auto *var = callee->AsIdentifier()->Variable(); - auto *data = varbinder->DynamicImportDataForVar(var); + auto *data = binder->DynamicImportDataForVar(var); if (data != nullptr) { auto *specifier = data->specifier; if (specifier->IsImportSpecifier()) { @@ -86,13 +86,13 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle Language lang) { auto *name = AllocNode("invoke", Allocator()); - auto *param_scope = Allocator()->New(Allocator(), nullptr); - auto *scope = Allocator()->New(Allocator(), param_scope); + auto *param_scope = Allocator()->New(Allocator(), nullptr); + auto *scope = Allocator()->New(Allocator(), param_scope); ArenaVector params(Allocator()->Adapter()); auto *info = CreateSignatureInfo(); - info->min_arg_count = arguments.size() + 2U; + info->min_arg_count = arguments.size() + 2; auto dynamic_type = GlobalBuiltinDynamicType(lang); @@ -101,7 +101,7 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle info->params.push_back(obj_param->Ident()->Variable()->AsLocalVariable()); ir::ETSParameterExpression *param2; - if (!IsByValueCall(VarBinder()->AsETSBinder(), callee)) { + if (!IsByValueCall(Binder()->AsETSBinder(), callee)) { param2 = AddParam(param_scope, "qname", GlobalETSStringLiteralType()); } else { param2 = AddParam(param_scope, "this", dynamic_type); @@ -147,7 +147,7 @@ static void ToString(ETSChecker *checker, const ArenaVector &a } } -static void ToString([[maybe_unused]] ETSChecker *checker, const ArenaVector &arguments, +static void ToString([[maybe_unused]] ETSChecker *checker, const ArenaVector &arguments, std::stringstream &ss) { for (auto *arg : arguments) { @@ -164,6 +164,7 @@ Signature *ETSChecker::ResolveDynamicCallExpression(ir::Expression *callee, cons auto &dynamic_intrinsics = *DynamicCallIntrinsics(is_construct); auto map_it = dynamic_intrinsics.find(lang); + if (map_it == dynamic_intrinsics.cend()) { std::tie(map_it, std::ignore) = dynamic_intrinsics.emplace(lang, Allocator()->Adapter()); } @@ -172,7 +173,7 @@ Signature *ETSChecker::ResolveDynamicCallExpression(ir::Expression *callee, cons std::stringstream ss; ss << "dyncall"; - if (IsByValueCall(VarBinder()->AsETSBinder(), callee)) { + if (IsByValueCall(Binder()->AsETSBinder(), callee)) { ss << "-byvalue"; } @@ -192,25 +193,25 @@ Signature *ETSChecker::ResolveDynamicCallExpression(ir::Expression *callee, cons template Signature *ETSChecker::ResolveDynamicCallExpression( ir::Expression *callee, const ArenaVector &arguments, Language lang, bool is_construct); -template Signature *ETSChecker::ResolveDynamicCallExpression( - ir::Expression *callee, const ArenaVector &arguments, Language lang, bool is_construct); +template Signature *ETSChecker::ResolveDynamicCallExpression( + ir::Expression *callee, const ArenaVector &arguments, Language lang, bool is_construct); template std::conditional_t ETSChecker::CreateClassInitializer( - varbinder::ClassScope *class_scope, const ClassInitializerBuilder &builder, ETSObjectType *type) + binder::ClassScope *class_scope, const ClassInitializerBuilder &builder, ETSObjectType *type) { - varbinder::LocalScope *method_scope = nullptr; + binder::LocalScope *method_scope = nullptr; if constexpr (IS_STATIC) { method_scope = class_scope->StaticMethodScope(); } else { method_scope = class_scope->InstanceMethodScope(); } - auto class_ctx = varbinder::LexicalScope::Enter(VarBinder(), method_scope); + auto class_ctx = binder::LexicalScope::Enter(Binder(), method_scope); ArenaVector params(Allocator()->Adapter()); - auto *param_scope = Allocator()->New(Allocator(), class_scope); - auto *scope = Allocator()->New(Allocator(), param_scope); + auto *param_scope = Allocator()->New(Allocator(), class_scope); + auto *scope = Allocator()->New(Allocator(), param_scope); ArenaVector statements(Allocator()->Adapter()); @@ -247,9 +248,9 @@ std::conditional_t ET auto *func_expr = AllocNode(func); - VarBinder()->AsETSBinder()->BuildInternalName(func); - VarBinder()->AsETSBinder()->BuildFunctionName(func); - VarBinder()->Functions().push_back(func->Scope()); + Binder()->AsETSBinder()->BuildInternalName(func); + Binder()->AsETSBinder()->BuildFunctionName(func); + Binder()->Functions().push_back(func->Scope()); if constexpr (IS_STATIC) { auto *static_block = AllocNode(func_expr, Allocator()); @@ -268,13 +269,12 @@ std::conditional_t ET } } -ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(varbinder::ClassScope *class_scope, Language lang, +ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(binder::ClassScope *class_scope, Language lang, bool is_construct) { return CreateClassInitializer( - class_scope, - [this, lang, is_construct](varbinder::FunctionScope *scope, ArenaVector *statements, - [[maybe_unused]] ArenaVector *params) { + class_scope, [this, lang, is_construct](binder::FunctionScope *scope, ArenaVector *statements, + [[maybe_unused]] ArenaVector *params) { auto [builtin_class_name, builtin_method_name] = util::Helpers::SplitSignature(is_construct ? compiler::Signatures::Dynamic::InitNewClassBuiltin(lang) : compiler::Signatures::Dynamic::InitCallClassBuiltin(lang)); @@ -288,7 +288,7 @@ ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(varbinder::C std::stringstream ss; auto name = is_construct ? compiler::Signatures::Dynamic::NewClass(lang) : compiler::Signatures::Dynamic::CallClass(lang); - auto package = VarBinder()->Program()->GetPackageName(); + auto package = Binder()->Program()->GetPackageName(); ss << compiler::Signatures::CLASS_REF_BEGIN; if (!package.Empty()) { @@ -316,10 +316,10 @@ ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(varbinder::C void ETSChecker::BuildClass(util::StringView name, const ClassBuilder &builder) { auto *class_id = AllocNode(name, Allocator()); - auto [decl, var] = VarBinder()->NewVarDecl(class_id->Start(), class_id->Name()); + auto [decl, var] = Binder()->NewVarDecl(class_id->Start(), class_id->Name()); class_id->SetVariable(var); - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); auto *class_def = AllocNode(Allocator(), class_ctx.GetScope(), class_id, ir::ClassDefinitionModifiers::DECLARATION, ir::ModifierFlags::NONE, @@ -330,13 +330,13 @@ void ETSChecker::BuildClass(util::StringView name, const ClassBuilder &builder) class_def->SetTsType(class_def_type); auto *class_decl = AllocNode(class_def, Allocator()); - class_decl->SetParent(VarBinder()->TopScope()->Node()); + class_decl->SetParent(Binder()->TopScope()->Node()); class_def->Scope()->BindNode(class_decl); decl->BindNode(class_def); - VarBinder()->Program()->Ast()->Statements().push_back(class_decl); + Binder()->Program()->Ast()->Statements().push_back(class_decl); - varbinder::BoundContext bound_ctx(VarBinder()->AsETSBinder()->GetGlobalRecordTable(), class_def); + binder::BoundContext bound_ctx(Binder()->AsETSBinder()->GetGlobalRecordTable(), class_def); ArenaVector class_body(Allocator()->Adapter()); @@ -358,7 +358,7 @@ void ETSChecker::BuildDynamicCallClass(bool is_construct) auto &intrinsics = entry.second; auto class_name = is_construct ? compiler::Signatures::Dynamic::NewClass(lang) : compiler::Signatures::Dynamic::CallClass(lang); - BuildClass(class_name, [this, lang, &intrinsics, is_construct](varbinder::ClassScope *scope, + BuildClass(class_name, [this, lang, &intrinsics, is_construct](binder::ClassScope *scope, ArenaVector *class_body) { for (auto &[_, func] : intrinsics) { (void)_; @@ -372,8 +372,8 @@ void ETSChecker::BuildDynamicCallClass(bool is_construct) ir::ModifierFlags::STATIC, Allocator(), false); - VarBinder()->AsETSBinder()->BuildInternalName(func); - VarBinder()->AsETSBinder()->BuildFunctionName(func); + Binder()->AsETSBinder()->BuildInternalName(func); + Binder()->AsETSBinder()->BuildFunctionName(func); class_body->push_back(method); } @@ -384,10 +384,10 @@ void ETSChecker::BuildDynamicCallClass(bool is_construct) } ir::ClassStaticBlock *ETSChecker::CreateDynamicModuleClassInitializer( - varbinder::ClassScope *class_scope, const std::vector &imports) + binder::ClassScope *class_scope, const std::vector &imports) { return CreateClassInitializer( - class_scope, [this, imports](varbinder::FunctionScope *scope, ArenaVector *statements, + class_scope, [this, imports](binder::FunctionScope *scope, ArenaVector *statements, [[maybe_unused]] ArenaVector *params) { for (auto *import : imports) { auto builtin = compiler::Signatures::Dynamic::LoadModuleBuiltin(import->Language()); @@ -423,16 +423,14 @@ ir::ClassStaticBlock *ETSChecker::CreateDynamicModuleClassInitializer( } template -ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class_scope, - const std::string_view method_name, +ir::MethodDefinition *ETSChecker::CreateClassMethod(binder::ClassScope *class_scope, const std::string_view method_name, panda::es2panda::ir::ModifierFlags modifier_flags, const MethodBuilder &builder) { - auto class_ctx = - varbinder::LexicalScope::Enter(VarBinder(), class_scope->StaticMethodScope()); + auto class_ctx = binder::LexicalScope::Enter(Binder(), class_scope->StaticMethodScope()); ArenaVector params(Allocator()->Adapter()); - auto *param_scope = Allocator()->New(Allocator(), class_scope); - auto *scope = Allocator()->New(Allocator(), param_scope); + auto *param_scope = Allocator()->New(Allocator(), class_scope); + auto *scope = Allocator()->New(Allocator(), param_scope); auto *id = AllocNode(method_name, Allocator()); ArenaVector statements(Allocator()->Adapter()); @@ -463,18 +461,18 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, func->Id(), func_expr, modifier_flags, Allocator(), false); - VarBinder()->AsETSBinder()->BuildInternalName(func); - VarBinder()->AsETSBinder()->BuildFunctionName(func); - VarBinder()->Functions().push_back(func->Scope()); + Binder()->AsETSBinder()->BuildInternalName(func); + Binder()->AsETSBinder()->BuildFunctionName(func); + Binder()->Functions().push_back(func->Scope()); - auto *decl = Allocator()->New(id->Name()); + auto *decl = Allocator()->New(id->Name()); decl->BindNode(method); auto *func_type = CreateETSFunctionType(signature, id->Name()); - auto *var = scope->AddDecl(Allocator(), decl, VarBinder()->Extension()); + auto *var = scope->AddDecl(Allocator(), decl, Binder()->Extension()); var->SetTsType(func_type); method->SetTsType(func_type); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + var->AddFlag(binder::VariableFlags::PROPERTY); func->Id()->SetVariable(var); auto *class_type = class_scope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType(); @@ -487,24 +485,24 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class return method; } -ir::MethodDefinition *ETSChecker::CreateDynamicModuleClassInitMethod(varbinder::ClassScope *class_scope) +ir::MethodDefinition *ETSChecker::CreateDynamicModuleClassInitMethod(binder::ClassScope *class_scope) { return CreateClassMethod(class_scope, compiler::Signatures::DYNAMIC_MODULE_CLASS_INIT, ir::ModifierFlags::PUBLIC | ir::ModifierFlags::STATIC, - [this]([[maybe_unused]] varbinder::FunctionScope *scope, + [this]([[maybe_unused]] binder::FunctionScope *scope, [[maybe_unused]] ArenaVector *statements, [[maybe_unused]] ArenaVector *params, Type **return_type) { *return_type = GlobalBuiltinVoidType(); }); } -ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder::ClassScope *class_scope, +ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(binder::ClassScope *class_scope, Signature *invoke_signature, ir::TypeNode *ret_type_annotation) { return CreateClassMethod( class_scope, compiler::Signatures::LAMBDA_OBJECT_INVOKE, ir::ModifierFlags::PUBLIC, [this, class_scope, invoke_signature, - ret_type_annotation](varbinder::FunctionScope *scope, ArenaVector *statements, + ret_type_annotation](binder::FunctionScope *scope, ArenaVector *statements, ArenaVector *params, Type **return_type) { util::UString this_param_name(std::string("this"), Allocator()); ir::ETSParameterExpression *this_param = @@ -544,7 +542,7 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: void ETSChecker::EmitDynamicModuleClassInitCall() { - auto *global_class = VarBinder()->Program()->GlobalClass(); + auto *global_class = Binder()->Program()->GlobalClass(); auto &body = global_class->Body(); auto it = std::find_if(body.begin(), body.end(), [](ir::AstNode *node) { return node->IsClassStaticBlock(); }); @@ -571,13 +569,13 @@ void ETSChecker::EmitDynamicModuleClassInitCall() void ETSChecker::BuildDynamicImportClass() { - auto dynamic_imports = VarBinder()->AsETSBinder()->DynamicImports(); + auto dynamic_imports = Binder()->AsETSBinder()->DynamicImports(); if (dynamic_imports.empty()) { return; } BuildClass(compiler::Signatures::DYNAMIC_MODULE_CLASS, - [this, dynamic_imports](varbinder::ClassScope *scope, ArenaVector *class_body) { + [this, dynamic_imports](binder::ClassScope *scope, ArenaVector *class_body) { std::unordered_set fields; std::vector imports; @@ -605,11 +603,11 @@ void ETSChecker::BuildDynamicImportClass() Allocator(), false); field->SetTsType(GlobalBuiltinDynamicType(import->Language())); - auto *decl = Allocator()->New(field_ident->Name()); + auto *decl = Allocator()->New(field_ident->Name()); decl->BindNode(field); - auto *var = scope->AddDecl(Allocator(), decl, VarBinder()->Extension()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + auto *var = scope->AddDecl(Allocator(), decl, Binder()->Extension()); + var->AddFlag(binder::VariableFlags::PROPERTY); field_ident->SetVariable(var); var->SetTsType(GlobalBuiltinDynamicType(import->Language())); @@ -625,12 +623,12 @@ void ETSChecker::BuildDynamicImportClass() EmitDynamicModuleClassInitCall(); } -ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInitializer(varbinder::ClassScope *class_scope, +ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInitializer(binder::ClassScope *class_scope, ETSObjectType *functional_interface) { return CreateClassInitializer( class_scope, - [this, class_scope](varbinder::FunctionScope *scope, ArenaVector *statements, + [this, class_scope](binder::FunctionScope *scope, ArenaVector *statements, ArenaVector *params) { util::UString this_param_name(std::string("this"), Allocator()); ir::ETSParameterExpression *this_param = @@ -679,7 +677,7 @@ void ETSChecker::BuildLambdaObjectClass(ETSObjectType *functional_interface, ir: BuildClass(util::StringView(synthetic_lambda_obj_name), [this, invoke_signature, ret_type_annotation, - functional_interface](varbinder::ClassScope *scope, ArenaVector *class_body) { + functional_interface](binder::ClassScope *scope, ArenaVector *class_body) { auto *class_type = scope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType(); class_type->AddInterface(functional_interface); @@ -689,11 +687,11 @@ void ETSChecker::BuildLambdaObjectClass(ETSObjectType *functional_interface, ir: Allocator(), false); field->SetTsType(GlobalBuiltinJSValueType()); - auto *decl = Allocator()->New(field_ident->Name()); + auto *decl = Allocator()->New(field_ident->Name()); decl->BindNode(field); - auto *var = scope->AddDecl(Allocator(), decl, VarBinder()->Extension()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + auto *var = scope->AddDecl(Allocator(), decl, Binder()->Extension()); + var->AddFlag(binder::VariableFlags::PROPERTY); var->SetTsType(GlobalBuiltinJSValueType()); field_ident->SetVariable(var); diff --git a/ets2panda/checker/ets/enum.cpp b/ets2panda/checker/ets/enum.cpp index 30e069a25bb02ecb546e7475f312eb5033988b05..d785b17cca0131fabf59cc537bb0b431864b0806 100644 --- a/ets2panda/checker/ets/enum.cpp +++ b/ets2panda/checker/ets/enum.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "varbinder/ETSBinder.h" -#include "varbinder/variable.h" +#include "binder/ETSBinder.h" +#include "binder/variable.h" #include "checker/ETSchecker.h" #include "ir/base/classProperty.h" #include "ir/base/methodDefinition.h" @@ -78,7 +78,7 @@ void AppendParentNames(util::UString &qualified_name, const ir::AstNode *const n } template -[[nodiscard]] ir::Identifier *MakeArray(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, +[[nodiscard]] ir::Identifier *MakeArray(ETSChecker *const checker, binder::ETSBinder *const binder, const ETSEnumInterface *const enum_type, const util::StringView &name, Type *const element_type, ElementMaker &&element_maker) { @@ -98,29 +98,27 @@ template array_ident, array_expr, nullptr, ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::CONST, checker->Allocator(), false); array_class_prop->SetTsType(array_expr->TsType()); - array_class_prop->SetParent(varbinder->Program()->GlobalClass()); + array_class_prop->SetParent(binder->Program()->GlobalClass()); array_ident->SetTsType(array_class_prop->TsType()); - varbinder->Program()->GlobalClass()->Body().push_back(array_class_prop); + binder->Program()->GlobalClass()->Body().push_back(array_class_prop); auto [array_decl, array_var] = - varbinder->NewVarDecl(array_ident->Start(), array_ident->Name(), array_class_prop); + binder->NewVarDecl(array_ident->Start(), array_ident->Name(), array_class_prop); array_ident->SetVariable(array_var); array_var->SetTsType(array_class_prop->TsType()); - array_var->AddFlag(varbinder::VariableFlags::PUBLIC | varbinder::VariableFlags::STATIC | - varbinder::VariableFlags::PROPERTY); - array_decl->Node()->SetParent(varbinder->Program()->GlobalClass()); + array_var->AddFlag(binder::VariableFlags::PUBLIC | binder::VariableFlags::STATIC | binder::VariableFlags::PROPERTY); + array_decl->Node()->SetParent(binder->Program()->GlobalClass()); return array_ident; } -[[nodiscard]] ir::ETSParameterExpression *MakeFunctionParam(ETSChecker *const checker, - varbinder::ETSBinder *const varbinder, - varbinder::FunctionParamScope *const scope, +[[nodiscard]] ir::ETSParameterExpression *MakeFunctionParam(ETSChecker *const checker, binder::ETSBinder *const binder, + binder::FunctionParamScope *const scope, const util::StringView &name, Type *const type) { - const auto param_ctx = varbinder::LexicalScope::Enter(varbinder, scope, false); + const auto param_ctx = binder::LexicalScope::Enter(binder, scope, false); auto *const param_ident = checker->Allocator()->New(name, checker->Allocator()); auto *const param = checker->Allocator()->New(param_ident, nullptr); - auto *const param_var = std::get<1>(varbinder->AddParamDecl(param)); + auto *const param_var = std::get<1>(binder->AddParamDecl(param)); param_var->SetTsType(type); param->Ident()->SetVariable(param_var); param->Ident()->SetTsType(type); @@ -135,14 +133,13 @@ template return allocator->New(reference_part); } -[[nodiscard]] ir::ScriptFunction *MakeFunction(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, - varbinder::FunctionParamScope *const param_scope, +[[nodiscard]] ir::ScriptFunction *MakeFunction(ETSChecker *const checker, binder::ETSBinder *const binder, + binder::FunctionParamScope *const param_scope, ArenaVector &¶ms, ArenaVector &&body, ir::TypeNode *const return_type_annotation) { - auto *const function_scope = - varbinder->Allocator()->New(checker->Allocator(), param_scope); + auto *const function_scope = binder->Allocator()->New(checker->Allocator(), param_scope); function_scope->BindParamScope(param_scope); param_scope->BindFunctionScope(function_scope); @@ -153,15 +150,15 @@ template function_scope, std::move(params), nullptr, body_block, return_type_annotation, ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); - varbinder->AsETSBinder()->BuildInternalName(function); - varbinder->AsETSBinder()->AddCompilableFunction(function); + binder->AsETSBinder()->BuildInternalName(function); + binder->AsETSBinder()->AddCompilableFunction(function); param_scope->BindNode(function); function_scope->BindNode(function); return function; } -void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, ir::Identifier *const ident, +void MakeMethodDef(ETSChecker *const checker, binder::ETSBinder *const binder, ir::Identifier *const ident, ir::ScriptFunction *const function) { auto *const function_expr = checker->Allocator()->New(function); @@ -169,18 +166,18 @@ void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbin auto *const method_def = checker->Allocator()->New( ir::MethodDefinitionKind::METHOD, ident, function_expr, ir::ModifierFlags::PUBLIC, checker->Allocator(), false); - method_def->SetParent(varbinder->Program()->GlobalClass()); + method_def->SetParent(binder->Program()->GlobalClass()); function_expr->SetParent(method_def); - auto *const method_var = std::get<1>(varbinder->NewVarDecl( + auto *const method_var = std::get<1>(binder->NewVarDecl( method_def->Start(), checker->Allocator(), method_def->Id()->Name(), method_def)); - method_var->AddFlag(varbinder::VariableFlags::STATIC | varbinder::VariableFlags::SYNTHETIC | - varbinder::VariableFlags::METHOD); + method_var->AddFlag(binder::VariableFlags::STATIC | binder::VariableFlags::SYNTHETIC | + binder::VariableFlags::METHOD); method_def->Function()->Id()->SetVariable(method_var); } [[nodiscard]] ETSFunctionType *MakeProxyFunctionType(ETSChecker *const checker, const util::StringView &name, - const std::initializer_list ¶ms, + const std::initializer_list ¶ms, ir::ScriptFunction *const global_function, Type *const return_type) { auto *const signature_info = checker->CreateSignatureInfo(); @@ -214,7 +211,7 @@ void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbin ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const enum_type) { - return MakeArray(this, VarBinder()->AsETSBinder(), enum_type, "NamesArray", GlobalBuiltinETSStringType(), + return MakeArray(this, Binder()->AsETSBinder(), enum_type, "NamesArray", GlobalBuiltinETSStringType(), [this](const ir::TSEnumMember *const member) { auto *const enum_name_string_literal = Allocator()->New(member->Key()->AsIdentifier()->Name()); @@ -226,7 +223,7 @@ ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const e ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enum_type) { return MakeArray( - this, VarBinder()->AsETSBinder(), enum_type, "ValuesArray", GlobalIntType(), + this, Binder()->AsETSBinder(), enum_type, "ValuesArray", GlobalIntType(), [this](const ir::TSEnumMember *const member) { auto *const enum_value_literal = Allocator()->New(lexer::Number( member->AsTSEnumMember()->Init()->AsNumberLiteral()->Number().GetValue())); @@ -237,7 +234,7 @@ ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enum_type) ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const enum_type) { - return MakeArray(this, VarBinder()->AsETSBinder(), enum_type, "StringValuesArray", GlobalETSStringLiteralType(), + return MakeArray(this, Binder()->AsETSBinder(), enum_type, "StringValuesArray", GlobalETSStringLiteralType(), [this, is_string_enum = enum_type->IsETSStringEnumType()](const ir::TSEnumMember *const member) { auto const string_value = is_string_enum ? member->AsTSEnumMember()->Init()->AsStringLiteral()->Str() @@ -260,7 +257,7 @@ ir::Identifier *ETSChecker::CreateEnumItemsArray(ETSEnumInterface *const enum_ty enum_type_ident->SetTsType(enum_type); return MakeArray( - this, VarBinder()->AsETSBinder(), enum_type, "ItemsArray", enum_type, + this, Binder()->AsETSBinder(), enum_type, "ItemsArray", enum_type, [this, enum_type_ident](const ir::TSEnumMember *const member) { auto *const enum_member_ident = Allocator()->New(member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); @@ -275,10 +272,10 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na ETSEnumInterface *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalScope()); auto *const input_ordinal_ident = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), param_scope, "ordinal", GlobalIntType()); + MakeFunctionParam(this, Binder()->AsETSBinder(), param_scope, "ordinal", GlobalIntType()); auto *const in_array_size_expr = [this, names_array_ident, input_ordinal_ident]() { auto *const length_ident = Allocator()->New("length", Allocator()); @@ -333,15 +330,15 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na auto *const enum_type_annotation = MakeTypeReference(Allocator(), enum_type->GetName()); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), enum_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + enum_type_annotation); function->AddFlag(ir::ScriptFunctionFlags::THROWS); auto *const ident = MakeQualifiedIdentifier(Allocator(), enum_type->GetDecl(), ETSEnumType::FROM_INT_METHOD_NAME); function->SetIdent(ident); function->Scope()->BindInternalName(ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), ident, function); return {MakeGlobalSignature(this, function, enum_type), nullptr}; } @@ -350,10 +347,9 @@ ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const s ETSEnumInterface *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); - auto *const input_enum_ident = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), param_scope, "ordinal", enum_type); + auto *const input_enum_ident = MakeFunctionParam(this, Binder()->AsETSBinder(), param_scope, "ordinal", enum_type); auto *const return_stmt = [this, input_enum_ident, string_values_array_ident]() { auto *const array_access_expr = Allocator()->New( @@ -370,15 +366,15 @@ ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const s params.push_back(input_enum_ident); auto *const string_type_annotation = MakeTypeReference(Allocator(), GlobalBuiltinETSStringType()->Name()); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), string_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + string_type_annotation); auto *const function_ident = MakeQualifiedIdentifier(Allocator(), enum_type->GetDecl(), ETSEnumType::TO_STRING_METHOD_NAME); function->SetIdent(function_ident); function->Scope()->BindInternalName(function_ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), function_ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), function_ident, function); return { MakeGlobalSignature(this, function, GlobalETSStringLiteralType()), @@ -389,9 +385,9 @@ ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const v ETSEnumType *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); - auto *const input_enum_ident = MakeFunctionParam(this, VarBinder()->AsETSBinder(), param_scope, "e", enum_type); + auto *const input_enum_ident = MakeFunctionParam(this, Binder()->AsETSBinder(), param_scope, "e", enum_type); auto *const return_stmt = [this, input_enum_ident, values_array_ident]() { auto *const array_access_expr = Allocator()->New( @@ -408,15 +404,15 @@ ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const v params.push_back(input_enum_ident); auto *const int_type_annotation = Allocator()->New(ir::PrimitiveType::INT); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), int_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + int_type_annotation); auto *const function_ident = MakeQualifiedIdentifier(Allocator(), enum_type->GetDecl(), ETSEnumType::GET_VALUE_METHOD_NAME); function->SetIdent(function_ident); function->Scope()->BindInternalName(function_ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), function_ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), function_ident, function); return {MakeGlobalSignature(this, function, GlobalIntType()), MakeProxyFunctionType(this, ETSEnumType::GET_VALUE_METHOD_NAME, {}, function, GlobalIntType())}; @@ -426,10 +422,9 @@ ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const na ETSEnumInterface *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - auto *const input_enum_ident = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), param_scope, "ordinal", enum_type); + auto *const input_enum_ident = MakeFunctionParam(this, Binder()->AsETSBinder(), param_scope, "ordinal", enum_type); auto *const return_stmt = [this, input_enum_ident, names_array_ident]() { auto *const array_access_expr = Allocator()->New( @@ -447,15 +442,15 @@ ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const na auto *const string_type_annotation = MakeTypeReference(Allocator(), GlobalBuiltinETSStringType()->Name()); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), string_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + string_type_annotation); auto *const function_ident = MakeQualifiedIdentifier(Allocator(), enum_type->GetDecl(), ETSEnumType::GET_NAME_METHOD_NAME); function->SetIdent(function_ident); function->Scope()->BindInternalName(function_ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), function_ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), function_ident, function); return {MakeGlobalSignature(this, function, GlobalBuiltinETSStringType()), MakeProxyFunctionType(this, ETSEnumType::GET_NAME_METHOD_NAME, {}, function, GlobalBuiltinETSStringType())}; @@ -465,21 +460,21 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na ETSEnumInterface *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalScope()); auto *const input_name_ident = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), param_scope, "name", GlobalBuiltinETSStringType()); + MakeFunctionParam(this, Binder()->AsETSBinder(), param_scope, "name", GlobalBuiltinETSStringType()); - varbinder::LexicalScope loop_decl_scope(VarBinder()); + binder::LexicalScope loop_decl_scope(Binder()); auto *const for_loop_i_ident = [this]() { auto *const ident = Allocator()->New("i", Allocator()); ident->SetTsType(GlobalIntType()); - auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); + auto [decl, var] = Binder()->NewVarDecl(ident->Start(), ident->Name()); ident->SetVariable(var); var->SetTsType(GlobalIntType()); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::LOCAL); + var->SetScope(Binder()->GetScope()); + var->AddFlag(binder::VariableFlags::LOCAL); decl->BindNode(ident); return ident; }(); @@ -528,7 +523,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na return Allocator()->New(names_equal_expr, return_stmt, nullptr); }(); - varbinder::LexicalScope loop_scope(VarBinder()); + binder::LexicalScope loop_scope(Binder()); loop_scope.GetScope()->BindDecls(loop_decl_scope.GetScope()); auto *const for_loop = Allocator()->New(loop_scope.GetScope(), for_loop_init_var_decl, @@ -569,8 +564,8 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na auto *const enum_type_annotation = MakeTypeReference(Allocator(), enum_type->GetName()); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), enum_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + enum_type_annotation); function->AddFlag(ir::ScriptFunctionFlags::THROWS); auto *const function_ident = @@ -578,7 +573,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na function->SetIdent(function_ident); function->Scope()->BindInternalName(function_ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), function_ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), function_ident, function); return {MakeGlobalSignature(this, function, enum_type), MakeProxyFunctionType(this, ETSEnumType::VALUE_OF_METHOD_NAME, @@ -590,7 +585,7 @@ ETSEnumType::Method ETSChecker::CreateEnumValuesMethod(ir::Identifier *const ite ETSEnumInterface *const enum_type) { auto *const param_scope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); + Binder()->Allocator()->New(Allocator(), Program()->GlobalScope()); auto *const return_stmt = Allocator()->New(items_array_ident); ArenaVector body(Allocator()->Adapter()); @@ -601,15 +596,15 @@ ETSEnumType::Method ETSChecker::CreateEnumValuesMethod(ir::Identifier *const ite auto *const enum_array_type_annotation = Allocator()->New(MakeTypeReference(Allocator(), enum_type->GetName())); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), param_scope, std::move(params), - std::move(body), enum_array_type_annotation); + auto *const function = MakeFunction(this, Binder()->AsETSBinder(), param_scope, std::move(params), std::move(body), + enum_array_type_annotation); auto *const function_ident = MakeQualifiedIdentifier(Allocator(), enum_type->GetDecl(), ETSEnumType::VALUES_METHOD_NAME); function->SetIdent(function_ident); function->Scope()->BindInternalName(function_ident->Name()); - MakeMethodDef(this, VarBinder()->AsETSBinder(), function_ident, function); + MakeMethodDef(this, Binder()->AsETSBinder(), function_ident, function); return {MakeGlobalSignature(this, function, CreateETSArrayType(enum_type)), MakeProxyFunctionType(this, ETSEnumType::VALUES_METHOD_NAME, {}, function, CreateETSArrayType(enum_type))}; diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index f2fb7931da23dcf883b53d24062e05d329abda4e..70c655715f990d01fe3b2afec84330fe71870e6a 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -13,14 +13,13 @@ * limitations under the License. */ -#include "varbinder/varbinder.h" -#include "varbinder/declaration.h" -#include "varbinder/ETSBinder.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" -#include "varbinder/variableFlags.h" +#include "binder/binder.h" +#include "binder/declaration.h" +#include "binder/ETSBinder.h" +#include "binder/scope.h" +#include "binder/variable.h" +#include "binder/variableFlags.h" #include "checker/ETSchecker.h" -#include "checker/ets/function_helpers.h" #include "checker/ets/typeRelationContext.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" #include "checker/types/ets/etsObjectType.h" @@ -67,6 +66,24 @@ namespace panda::es2panda::checker { +ir::TypeNode *GetGenericTypeArgument(const ArenaVector &callee_type_args, + const ArenaVector &sig_type_params, + const checker::Type *sig_param_type) +{ + const auto *const sig_param_type_var = sig_param_type->Variable(); + const auto it = + std::find_if(sig_type_params.begin(), sig_type_params.end(), [&sig_param_type_var](ir::TSTypeParameter *tp) { + return tp->Name()->Variable() == sig_param_type_var; + }); + + if (it == sig_type_params.end()) { + return nullptr; + } + + const size_t index = std::distance(sig_type_params.begin(), it); + return callee_type_args[index]; +} + bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) { ASSERT(type_param->IsETSObjectType() && @@ -94,6 +111,19 @@ bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) return true; } +static Type *MaybeBoxedType(ETSChecker *checker, Type *type, ir::Expression *expr) +{ + if (!type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + return type; + } + auto *relation = checker->Relation(); + auto *old_node = relation->GetNode(); + relation->SetNode(expr); + auto *res = checker->PrimitiveTypeAsETSBuiltinType(type); + relation->SetNode(old_node); + return res; +} + /* A very rough and imprecise partial type inference */ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_params, Type *param_type, Type *argument_type, Substitution *substitution) @@ -124,6 +154,73 @@ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_para } } +static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *checker, Signature *signature, + const ArenaVector &arguments) +{ + Substitution *substitution = checker->NewSubstitution(); + auto *sig_info = signature->GetSignatureInfo(); + ArenaVector &type_params = sig_info->type_params; + for (size_t ix = 0; ix < arguments.size(); ix++) { + auto *arg = arguments[ix]; + if (arg->IsObjectExpression()) { + continue; + } + auto *arg_type = arg->Check(checker); + arg_type = MaybeBoxedType(checker, arg_type, arg); + auto *param_type = + (ix < signature->MinArgCount()) ? sig_info->params[ix]->TsType() : sig_info->rest_var->TsType(); + if (param_type == nullptr) { + continue; + } + checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution); + } + return substitution; +} + +static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *checker, Signature *signature, + const ir::TSTypeParameterInstantiation *type_arguments, + const lexer::SourcePosition &pos, + TypeRelationFlag flags) +{ + auto *substitution = checker->NewSubstitution(); + ArenaVector &type_params = signature->GetSignatureInfo()->type_params; + ArenaVector type_arg_types {checker->Allocator()->Adapter()}; + for (auto *ta_expr : type_arguments->Params()) { + auto *type_arg = ta_expr->GetType(checker); + type_arg = MaybeBoxedType(checker, type_arg, ta_expr); + type_arg_types.push_back(type_arg); + } + if (type_params.size() != type_arg_types.size()) { + if ((flags & TypeRelationFlag::NO_THROW) == 0) { + checker->ThrowTypeError( + {"Expected ", type_params.size(), " type arguments, got ", type_arg_types.size(), " ."}, pos); + } + return nullptr; + } + for (size_t ix = 0; ix < type_arg_types.size(); ix++) { + if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix])) { + return nullptr; + } + substitution->emplace(type_params[ix], type_arg_types[ix]); + } + return substitution; +} + +static Signature *MaybeSubstituteTypeParameters(ETSChecker *checker, Signature *signature, + const ir::TSTypeParameterInstantiation *type_arguments, + const ArenaVector &arguments, + const lexer::SourcePosition &pos, TypeRelationFlag flags) +{ + if (type_arguments == nullptr && signature->GetSignatureInfo()->type_params.empty()) { + return signature; + } + const Substitution *substitution = + (type_arguments != nullptr) + ? BuildExplicitSubstitutionForArguments(checker, signature, type_arguments, pos, flags) + : BuildImplicitSubstitutionForArguments(checker, signature, arguments); + return (substitution == nullptr) ? nullptr : signature->Substitute(checker->Relation(), substitution); +} + // NOLINTBEGIN(modernize-avoid-c-arrays) static constexpr char const INVALID_CALL_ARGUMENT_1[] = "Call argument at index "; static constexpr char const INVALID_CALL_ARGUMENT_2[] = " is not compatible with the signature's type at that index."; @@ -306,12 +403,12 @@ Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, TypeRelationFlag flags = TypeRelationFlag::WIDENING | resolve_flags; collect_signatures(flags); } else { - std::array flag_variants {TypeRelationFlag::NO_THROW | TypeRelationFlag::NO_UNBOXING | - TypeRelationFlag::NO_BOXING, - TypeRelationFlag::NO_THROW, - TypeRelationFlag::NO_THROW | TypeRelationFlag::WIDENING | - TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_BOXING, - TypeRelationFlag::NO_THROW | TypeRelationFlag::WIDENING}; + std::array flag_variants {TypeRelationFlag::NO_THROW | TypeRelationFlag::NO_UNBOXING | + TypeRelationFlag::NO_BOXING, + TypeRelationFlag::NO_THROW, + TypeRelationFlag::NO_THROW | TypeRelationFlag::WIDENING | + TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_BOXING, + TypeRelationFlag::NO_THROW | TypeRelationFlag::WIDENING}; for (auto flags : flag_variants) { flags = flags | resolve_flags; collect_signatures(flags); @@ -479,7 +576,7 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig continue; } if (most_specific_signature->Owner() == sig->Owner()) { - // NOTE: audovichenko. Remove this 'if' when #12443 gets resolved + // TODO(audovichenko): Remove this 'if' when #12443 gets resolved if (most_specific_signature->Function() == sig->Function()) { // The same signature continue; @@ -612,6 +709,47 @@ checker::ETSFunctionType *ETSChecker::BuildMethodSignature(ir::MethodDefinition return func_type; } +static bool HasSameAssemblySignature(ETSFunctionType *func1, ETSFunctionType *func2) +{ + for (auto *sig1 : func1->CallSignatures()) { + for (auto *sig2 : func2->CallSignatures()) { + if (sig1->MinArgCount() != sig2->MinArgCount()) { + continue; + } + bool all_same = true; + for (size_t ix = 0; ix < sig1->MinArgCount(); ix++) { + std::stringstream s1; + std::stringstream s2; + sig1->Params()[ix]->TsType()->ToAssemblerTypeWithRank(s1); + sig2->Params()[ix]->TsType()->ToAssemblerTypeWithRank(s2); + if (s1.str() != s2.str()) { + all_same = false; + break; + } + } + if (!all_same) { + continue; + } + auto *rv1 = sig1->RestVar(); + auto *rv2 = sig2->RestVar(); + if (rv1 == nullptr && rv2 == nullptr) { + return true; + } + if (rv1 == nullptr || rv2 == nullptr) { // exactly one of them is null + return false; + } + std::stringstream s1; + std::stringstream s2; + rv1->TsType()->ToAssemblerTypeWithRank(s1); + rv2->TsType()->ToAssemblerTypeWithRank(s2); + if (s1.str() == s2.str()) { + return true; + } + } + } + return false; +} + void ETSChecker::CheckIdenticalOverloads(ETSFunctionType *func, ETSFunctionType *overload, const ir::MethodDefinition *const current_func) { @@ -667,7 +805,7 @@ checker::ETSFunctionType *ETSChecker::BuildFunctionSignature(ir::ScriptFunction } else { auto const *const param_ident = param->Ident(); - varbinder::Variable *const param_var = param_ident->Variable(); + binder::Variable *const param_var = param_ident->Variable(); ASSERT(param_var); auto *const param_type_annotation = param->TypeAnnotation(); @@ -685,7 +823,7 @@ checker::ETSFunctionType *ETSChecker::BuildFunctionSignature(ir::ScriptFunction } if (func->IsEntryPoint()) { - if (func->Params().size() >= 2U) { + if (func->Params().size() >= 2) { ThrowTypeError("0 or 1 argument are allowed", func->Start()); } @@ -713,7 +851,7 @@ checker::ETSFunctionType *ETSChecker::BuildFunctionSignature(ir::ScriptFunction : GlobalBuiltinVoidType(); if (return_type == nullptr) { - const auto var_map = VarBinder()->TopScope()->Bindings(); + const auto var_map = Binder()->TopScope()->Bindings(); const auto builtin_void = var_map.find(compiler::Signatures::BUILTIN_VOID_CLASS); ASSERT(builtin_void != var_map.end()); @@ -747,7 +885,7 @@ checker::ETSFunctionType *ETSChecker::BuildFunctionSignature(ir::ScriptFunction auto *func_type = CreateETSFunctionType(func, signature, func_name); func->SetSignature(signature); func_type->SetVariable(name_var); - VarBinder()->AsETSBinder()->BuildFunctionName(func); + Binder()->AsETSBinder()->BuildFunctionName(func); if (func->IsAbstract()) { signature->AddSignatureFlag(SignatureFlags::ABSTRACT); @@ -1002,6 +1140,18 @@ bool ETSChecker::CheckOverride(Signature *signature, ETSObjectType *site) return is_overriding_any_signature; } +static bool CheckInterfaceOverride(ETSChecker *const checker, ETSObjectType *const interface, + Signature *const signature) +{ + bool is_overriding = checker->CheckOverride(signature, interface); + + for (auto *const super_interface : interface->Interfaces()) { + is_overriding |= CheckInterfaceOverride(checker, super_interface, signature); + } + + return is_overriding; +} + void ETSChecker::CheckOverride(Signature *signature) { auto *owner = signature->Owner(); @@ -1077,7 +1227,7 @@ void ETSChecker::ValidateSignatureAccessibility(ETSObjectType *callee, Signature } } -void ETSChecker::CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *var) +void ETSChecker::CheckCapturedVariable(ir::AstNode *node, binder::Variable *var) { if (node->IsIdentifier()) { auto *parent = node->Parent(); @@ -1087,7 +1237,7 @@ void ETSChecker::CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *v ResolveIdentifier(ident_node); if (ident_node->Variable() == var) { - var->AddFlag(varbinder::VariableFlags::BOXED); + var->AddFlag(binder::VariableFlags::BOXED); } } } @@ -1095,7 +1245,7 @@ void ETSChecker::CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *v CheckCapturedVariableInSubnodes(node, var); } -void ETSChecker::CheckCapturedVariableInSubnodes(ir::AstNode *node, varbinder::Variable *var) +void ETSChecker::CheckCapturedVariableInSubnodes(ir::AstNode *node, binder::Variable *var) { node->Iterate([this, var](ir::AstNode *child_node) { CheckCapturedVariable(child_node, var); }); } @@ -1106,7 +1256,7 @@ void ETSChecker::CheckCapturedVariables() for (auto [var, _] : Context().CapturedVars()) { (void)_; if ((var->Declaration() == nullptr) || var->Declaration()->IsConstDecl() || - !var->HasFlag(varbinder::VariableFlags::LOCAL) || var->GetScope()->Node()->IsArrowFunctionExpression()) { + !var->HasFlag(binder::VariableFlags::LOCAL) || var->GetScope()->Node()->IsArrowFunctionExpression()) { continue; } @@ -1122,26 +1272,25 @@ void ETSChecker::CheckCapturedVariables() void ETSChecker::BuildFunctionalInterfaceName(ir::ETSFunctionType *func_type) { - VarBinder()->AsETSBinder()->BuildFunctionalInterfaceName(func_type); + Binder()->AsETSBinder()->BuildFunctionalInterfaceName(func_type); } void ETSChecker::CreateFunctionalInterfaceForFunctionType(ir::ETSFunctionType *func_type) { auto *ident_node = Allocator()->New(util::StringView("FunctionalInterface"), Allocator()); - auto interface_ctx = varbinder::LexicalScope(VarBinder()); + auto interface_ctx = binder::LexicalScope(Binder()); auto *interface_scope = interface_ctx.GetScope(); ArenaVector members(Allocator()->Adapter()); ir::MethodDefinition *invoke_func = CreateInvokeFunction(func_type); members.push_back(invoke_func); - auto method_ctx = - varbinder::LexicalScope::Enter(VarBinder(), interface_scope->InstanceMethodScope()); - auto [_, var] = VarBinder()->NewVarDecl(invoke_func->Start(), Allocator(), - invoke_func->Id()->Name(), invoke_func); + auto method_ctx = binder::LexicalScope::Enter(Binder(), interface_scope->InstanceMethodScope()); + auto [_, var] = Binder()->NewVarDecl(invoke_func->Start(), Allocator(), + invoke_func->Id()->Name(), invoke_func); (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); invoke_func->Function()->Id()->SetVariable(var); if (func_type->IsThrowing()) { @@ -1158,7 +1307,7 @@ void ETSChecker::CreateFunctionalInterfaceForFunctionType(ir::ETSFunctionType *f func_type->SetFunctionalInterface(interface_decl); invoke_func->SetParent(interface_decl); - VarBinder()->AsETSBinder()->BuildFunctionType(func_type); + Binder()->AsETSBinder()->BuildFunctionType(func_type); } ir::MethodDefinition *ETSChecker::CreateInvokeFunction(ir::ETSFunctionType *func_type) @@ -1168,9 +1317,8 @@ ir::MethodDefinition *ETSChecker::CreateInvokeFunction(ir::ETSFunctionType *func ArenaVector params(Allocator()->Adapter()); auto *func_param_scope = CopyParams(func_type->Params(), params); - auto param_ctx = - varbinder::LexicalScope::Enter(VarBinder(), func_param_scope, false); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope::Enter(Binder(), func_param_scope, false); + auto function_ctx = binder::LexicalScope(Binder()); auto *function_scope = function_ctx.GetScope(); function_scope->BindParamScope(func_param_scope); func_param_scope->BindFunctionScope(function_scope); @@ -1200,7 +1348,7 @@ ir::MethodDefinition *ETSChecker::CreateInvokeFunction(ir::ETSFunctionType *func void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpression *lambda, ETSObjectType *functional_interface) { - if (VarBinder()->AsETSBinder()->LambdaObjects().count(lambda) != 0) { + if (Binder()->AsETSBinder()->LambdaObjects().count(lambda) != 0) { return; } @@ -1210,16 +1358,16 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio auto *current_class_def = Context().ContainingClass()->GetDeclNode()->AsClassDefinition(); // Create the class scope for the synthetic lambda class node - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); auto *class_scope = class_ctx.GetScope(); // Create the synthetic class property nodes for the captured variables ArenaVector properties(Allocator()->Adapter()); for (const auto *it : captured_vars) { - if (it->HasFlag(varbinder::VariableFlags::LOCAL)) { + if (it->HasFlag(binder::VariableFlags::LOCAL)) { properties.push_back(CreateLambdaCapturedField(it, class_scope, idx, lambda->Start())); idx++; - } else if (!it->HasFlag(varbinder::VariableFlags::STATIC) && + } else if (!it->HasFlag(binder::VariableFlags::STATIC) && !Context().ContainingClass()->HasObjectFlag(ETSObjectFlags::GLOBAL)) { save_this = true; } @@ -1270,7 +1418,7 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio class_scope->BindNode(lambda_object); // Build the lambda object in the binder - VarBinder()->AsETSBinder()->BuildLambdaObject(lambda, lambda_object, proxy_method->Function()->Signature()); + Binder()->AsETSBinder()->BuildLambdaObject(lambda, lambda_object, proxy_method->Function()->Signature()); // Resolve the proxy method ResolveProxyMethod(proxy_method, lambda); @@ -1283,7 +1431,7 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio Signature *impl_sig = CreateSignature(proxy_method->Function()->Signature()->GetSignatureInfo(), GlobalETSObjectType(), async_impl_func); async_impl_func->SetSignature(impl_sig); - VarBinder()->AsETSBinder()->BuildFunctionName(async_impl->Function()); + Binder()->AsETSBinder()->BuildFunctionName(async_impl->Function()); } // Resolve the lambda object @@ -1315,7 +1463,7 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambda_object, ETSObje lambda_object_type->AddProperty( prop->Key()->AsIdentifier()->Variable()->AsLocalVariable()); } - VarBinder()->AsETSBinder()->BuildLambdaObjectName(lambda); + Binder()->AsETSBinder()->BuildLambdaObjectName(lambda); // Resolve the constructor ResolveLambdaObjectCtor(lambda_object); @@ -1341,11 +1489,11 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambda_object, i // Create the parameters for the invoke function, based on the lambda function's parameters for (auto *it : lambda->Function()->Params()) { - auto param_ctx = varbinder::LexicalScope::Enter( - VarBinder(), invoke_func->Scope()->ParamScope(), false); + auto param_ctx = binder::LexicalScope::Enter( + Binder(), invoke_func->Scope()->ParamScope(), false); auto *const param = it->AsETSParameterExpression(); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; var->SetTsType(param->Variable()->TsType()); param->Ident()->SetVariable(var); @@ -1363,7 +1511,7 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambda_object, i auto *invoke_type = CreateETSFunctionType(invoke_signature); invoke_func->SetSignature(invoke_signature); invoke_func->Id()->Variable()->SetTsType(invoke_type); - VarBinder()->AsETSBinder()->BuildFunctionName(invoke_func); + Binder()->AsETSBinder()->BuildFunctionName(invoke_func); lambda_object_type->AddProperty( invoke_func->Id()->Variable()->AsLocalVariable()); @@ -1393,8 +1541,9 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition field_prop_type = proxy_signature->Owner(); field_ident->SetVariable(proxy_signature->Owner()->Variable()); field_ident->SetTsType(field_prop_type); - } else { - // Otherwise, we call the proxy method through the saved 'this' field + } + // Otherwise, we call the proxy method through the saved 'this' field + else { auto *saved_this = lambda_body[lambda_body.size() - 3]->AsClassProperty(); auto *field_prop = saved_this->Key()->AsIdentifier()->Variable(); field_prop_type = field_prop->TsType()->AsETSObjectType(); @@ -1476,7 +1625,7 @@ void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambda_object) auto *ctor_type = CreateETSFunctionType(ctor_signature); ctor_func->SetSignature(ctor_signature); ctor_func->Id()->Variable()->SetTsType(ctor_type); - VarBinder()->AsETSBinder()->BuildFunctionName(ctor_func); + Binder()->AsETSBinder()->BuildFunctionName(ctor_func); // Add the type information for the lambda field initializers in the constructor auto &initializers = ctor_func->Body()->AsBlockStatement()->Statements(); @@ -1502,7 +1651,7 @@ void ETSChecker::ResolveProxyMethod(ir::MethodDefinition *proxy_method, ir::Arro auto *current_class_type = Context().ContainingClass(); // Build the proxy method in the binder - VarBinder()->AsETSBinder()->BuildProxyMethod( + Binder()->AsETSBinder()->BuildProxyMethod( func, current_class_type->GetDeclNode()->AsClassDefinition()->InternalName(), is_static); // If the proxy method is not static, set the implicit 'this' parameters type to the current class @@ -1532,10 +1681,12 @@ void ETSChecker::ResolveProxyMethod(ir::MethodDefinition *proxy_method, ir::Arro current_class_type->AddProperty( func->Id()->Variable()->AsLocalVariable()); } - VarBinder()->AsETSBinder()->BuildFunctionName(func); + Binder()->AsETSBinder()->BuildFunctionName(func); } -size_t ETSChecker::ComputeProxyMethods(ir::ClassDefinition *klass) +ir::MethodDefinition *ETSChecker::CreateProxyMethodForLambda(ir::ClassDefinition *klass, + ir::ArrowFunctionExpression *lambda, + ArenaVector &captured, bool is_static) { // Compute how many proxy methods are present in the current class, to be able to create a name for the proxy // method which doesn't conflict with any of the other ones @@ -1549,11 +1700,15 @@ size_t ETSChecker::ComputeProxyMethods(ir::ClassDefinition *klass) idx++; } } - return idx; -} -ir::ModifierFlags ETSChecker::GetFlagsForProxyLambda(bool is_static) -{ + // Create the synthetic parameters for the proxy method + ArenaVector params(Allocator()->Adapter()); + auto *func_param_scope = CreateProxyMethodParams(lambda, params, captured, is_static); + + // Create the scopes for the proxy method + auto param_ctx = binder::LexicalScope::Enter(Binder(), func_param_scope, false); + auto *scope = Binder()->Allocator()->New(Allocator(), func_param_scope); + // If every captured variable in the lambda is local variable, the proxy method can be 'static' since it doesn't // use any of the classes properties ir::ModifierFlags flags = ir::ModifierFlags::PUBLIC; @@ -1562,11 +1717,6 @@ ir::ModifierFlags ETSChecker::GetFlagsForProxyLambda(bool is_static) flags |= ir::ModifierFlags::STATIC; } - return flags; -} - -ir::AstNode *ETSChecker::GetProxyMethodBody(ir::ArrowFunctionExpression *lambda, varbinder::FunctionScope *scope) -{ // Copy the lambda function body for the proxy method and replace the bodies scope to the proxy function auto *body = lambda->Function()->Body(); @@ -1589,30 +1739,13 @@ ir::AstNode *ETSChecker::GetProxyMethodBody(ir::ArrowFunctionExpression *lambda, body = AllocNode(Allocator(), scope, std::move(lambda_block_statements)); } - return body; -} - -ir::ScriptFunction *ETSChecker::CreateProxyFunc(ir::ArrowFunctionExpression *lambda, - ArenaVector &captured, bool is_static) -{ - // Create the synthetic parameters for the proxy method - ArenaVector params(Allocator()->Adapter()); - auto *func_param_scope = CreateProxyMethodParams(lambda, params, captured, is_static); - - // Create the scopes for the proxy method - auto param_ctx = - varbinder::LexicalScope::Enter(VarBinder(), func_param_scope, false); - auto *scope = VarBinder()->Allocator()->New(Allocator(), func_param_scope); - - auto *body = GetProxyMethodBody(lambda, scope); - ir::ScriptFunctionFlags func_flags = ir::ScriptFunctionFlags::METHOD | ir::ScriptFunctionFlags::PROXY; if (lambda->Function()->IsAsyncFunc()) { func_flags |= ir::ScriptFunctionFlags::ASYNC; } - auto *func = Allocator()->New( - scope, std::move(params), nullptr, body, lambda->Function()->ReturnTypeAnnotation(), func_flags, - GetFlagsForProxyLambda(is_static), false, Language(Language::Id::ETS)); + auto *func = Allocator()->New(scope, std::move(params), nullptr, body, + lambda->Function()->ReturnTypeAnnotation(), func_flags, flags, + false, Language(Language::Id::ETS)); if (!func->IsAsyncFunc()) { // Replace the variable binding in the lambda body where an identifier refers to a lambda parameter or a @@ -1633,23 +1766,15 @@ ir::ScriptFunction *ETSChecker::CreateProxyFunc(ir::ArrowFunctionExpression *lam } ReplaceScope(body, lambda->Function(), scope); - return func; -} - -ir::MethodDefinition *ETSChecker::CreateProxyMethodForLambda(ir::ClassDefinition *klass, - ir::ArrowFunctionExpression *lambda, - ArenaVector &captured, bool is_static) -{ - auto *func = CreateProxyFunc(lambda, captured, is_static); // Create the synthetic proxy method auto *func_expr = Allocator()->New(func); util::UString func_name(util::StringView("lambda$invoke$"), Allocator()); - func_name.Append(std::to_string(ComputeProxyMethods(klass))); + func_name.Append(std::to_string(idx)); auto *ident_node = Allocator()->New(func_name.View(), Allocator()); func->SetIdent(ident_node); - auto *proxy = Allocator()->New(ir::MethodDefinitionKind::METHOD, ident_node, func_expr, - GetFlagsForProxyLambda(is_static), Allocator(), false); + auto *proxy = Allocator()->New(ir::MethodDefinitionKind::METHOD, ident_node, func_expr, flags, + Allocator(), false); klass->Body().push_back(proxy); proxy->SetParent(klass); @@ -1682,7 +1807,7 @@ ir::MethodDefinition *ETSChecker::CreateProxyMethodForLambda(ir::ClassDefinition void ETSChecker::ReplaceIdentifierReferencesInProxyMethod(ir::AstNode *body, ArenaVector &proxy_params, ArenaVector &lambda_params, - ArenaVector &captured) + ArenaVector &captured) { if (proxy_params.empty()) { return; @@ -1693,11 +1818,11 @@ void ETSChecker::ReplaceIdentifierReferencesInProxyMethod(ir::AstNode *body, // expression body. The order is crucial, thats why we save the index, because in the synthetic proxy method, // the first n number of parameters are which came from the lambda expression parameter list, and the last // parameters are which came from the captured variables - std::unordered_map merged_target_references; + std::unordered_map merged_target_references; size_t idx = 0; for (auto *it : captured) { - if (it->HasFlag(varbinder::VariableFlags::LOCAL)) { + if (it->HasFlag(binder::VariableFlags::LOCAL)) { merged_target_references.insert({it, idx}); idx++; } @@ -1713,7 +1838,7 @@ void ETSChecker::ReplaceIdentifierReferencesInProxyMethod(ir::AstNode *body, void ETSChecker::ReplaceIdentifierReferencesInProxyMethod( ir::AstNode *node, ArenaVector &proxy_params, - std::unordered_map &merged_target_references) + std::unordered_map &merged_target_references) { if (node->IsMemberExpression()) { auto *member_expr = node->AsMemberExpression(); @@ -1728,7 +1853,7 @@ void ETSChecker::ReplaceIdentifierReferencesInProxyMethod( void ETSChecker::ReplaceIdentifierReferenceInProxyMethod( ir::AstNode *node, ArenaVector &proxy_params, - std::unordered_map &merged_target_references) + std::unordered_map &merged_target_references) { // If we see an identifier reference if (node->IsIdentifier()) { @@ -1746,13 +1871,13 @@ void ETSChecker::ReplaceIdentifierReferenceInProxyMethod( ReplaceIdentifierReferencesInProxyMethod(node, proxy_params, merged_target_references); } -varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunctionExpression *lambda, - ArenaVector &proxy_params, - ArenaVector &captured, bool is_static) +binder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunctionExpression *lambda, + ArenaVector &proxy_params, + ArenaVector &captured, bool is_static) { const auto ¶ms = lambda->Function()->Params(); // Create a param scope for the proxy method parameters - auto param_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope(Binder()); // First add the parameters to the proxy method, based on how many variables have been captured, if this // is NOT a static method, we doesn't need the last captured parameter, which is the 'this' reference, because @@ -1766,18 +1891,18 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc // When a lambda is defined inside an instance extension function, if "this" is captured inside the lambda, // "this" should be binded with the parameter of the proxy method if (this->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD) && - lambda->CapturedVars()[i]->Name() == varbinder::VarBinder::MANDATORY_PARAM_THIS) { - param_ident = Allocator()->New(varbinder::VarBinder::MANDATORY_PARAM_THIS, Allocator()); + lambda->CapturedVars()[i]->Name() == binder::Binder::MANDATORY_PARAM_THIS) { + param_ident = Allocator()->New(binder::Binder::MANDATORY_PARAM_THIS, Allocator()); } else { param_ident = Allocator()->New(captured_var->Name(), Allocator()); } auto *param = Allocator()->New(param_ident, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; var->SetTsType(captured_var->TsType()); - if (captured_var->HasFlag(varbinder::VariableFlags::BOXED)) { - var->AddFlag(varbinder::VariableFlags::BOXED); + if (captured_var->HasFlag(binder::VariableFlags::BOXED)) { + var->AddFlag(binder::VariableFlags::BOXED); } param->SetTsType(captured_var->TsType()); param->SetVariable(var); @@ -1791,7 +1916,7 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc auto *const old_param_expr_ident = it->AsETSParameterExpression()->Ident(); auto *const param_ident = Allocator()->New(old_param_expr_ident->Name(), Allocator()); auto *param = Allocator()->New(param_ident, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; var->SetTsType(old_param_expr_ident->Variable()->TsType()); param->SetVariable(var); @@ -1802,11 +1927,11 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc return param_ctx.GetScope(); } -ir::ClassProperty *ETSChecker::CreateLambdaCapturedThis(varbinder::ClassScope *scope, size_t &idx, +ir::ClassProperty *ETSChecker::CreateLambdaCapturedThis(binder::ClassScope *scope, size_t &idx, const lexer::SourcePosition &pos) { // Enter the lambda class instance field scope, every property will be bound to the lambda instance itself - auto field_ctx = varbinder::LexicalScope::Enter(VarBinder(), scope->InstanceFieldScope()); + auto field_ctx = binder::LexicalScope::Enter(Binder(), scope->InstanceFieldScope()); // Create the name for the synthetic property node util::UString field_name(util::StringView("field"), Allocator()); @@ -1819,8 +1944,8 @@ ir::ClassProperty *ETSChecker::CreateLambdaCapturedThis(varbinder::ClassScope *s // Add the declaration to the scope, and set the type based on the current class type, to be able to store the // 'this' reference - auto [decl, var] = VarBinder()->NewVarDecl(pos, field_ident->Name()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + auto [decl, var] = Binder()->NewVarDecl(pos, field_ident->Name()); + var->AddFlag(binder::VariableFlags::PROPERTY); var->SetTsType(Context().ContainingClass()); field_ident->SetVariable(var); field->SetTsType(Context().ContainingClass()); @@ -1828,12 +1953,12 @@ ir::ClassProperty *ETSChecker::CreateLambdaCapturedThis(varbinder::ClassScope *s return field; } -ir::ClassProperty *ETSChecker::CreateLambdaCapturedField(const varbinder::Variable *captured_var, - varbinder::ClassScope *scope, size_t &idx, +ir::ClassProperty *ETSChecker::CreateLambdaCapturedField(const binder::Variable *captured_var, + binder::ClassScope *scope, size_t &idx, const lexer::SourcePosition &pos) { // Enter the lambda class instance field scope, every property will be bound to the lambda instance itself - auto field_ctx = varbinder::LexicalScope::Enter(VarBinder(), scope->InstanceFieldScope()); + auto field_ctx = binder::LexicalScope::Enter(Binder(), scope->InstanceFieldScope()); // Create the name for the synthetic property node util::UString field_name(util::StringView("field"), Allocator()); @@ -1845,11 +1970,11 @@ ir::ClassProperty *ETSChecker::CreateLambdaCapturedField(const varbinder::Variab Allocator()->New(field_ident, nullptr, nullptr, ir::ModifierFlags::NONE, Allocator(), false); // Add the declaration to the scope, and set the type based on the captured variable's scope - auto [decl, var] = VarBinder()->NewVarDecl(pos, field_ident->Name()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + auto [decl, var] = Binder()->NewVarDecl(pos, field_ident->Name()); + var->AddFlag(binder::VariableFlags::PROPERTY); var->SetTsType(captured_var->TsType()); - if (captured_var->HasFlag(varbinder::VariableFlags::BOXED)) { - var->AddFlag(varbinder::VariableFlags::BOXED); + if (captured_var->HasFlag(binder::VariableFlags::BOXED)) { + var->AddFlag(binder::VariableFlags::BOXED); } field_ident->SetVariable(var); field->SetTsType(MaybeBoxedType(captured_var)); @@ -1864,9 +1989,8 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVector::Enter(VarBinder(), func_param_scope, false); - auto *scope = VarBinder()->Allocator()->New(Allocator(), func_param_scope); + auto param_ctx = binder::LexicalScope::Enter(Binder(), func_param_scope, false); + auto *scope = Binder()->Allocator()->New(Allocator(), func_param_scope); // Complete the synthetic constructor node's body, to be able to initialize every field by copying every // captured variables value @@ -1902,11 +2026,11 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVector ¶ms, - ArenaVector &properties) +binder::FunctionParamScope *ETSChecker::CreateLambdaCtorImplicitParams(ArenaVector ¶ms, + ArenaVector &properties) { // Create the scope for the synthetic constructor parameters - auto param_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope(Binder()); // Create every parameter based on the synthetic field which was created for the lambda class to store the // captured variables @@ -1914,7 +2038,7 @@ varbinder::FunctionParamScope *ETSChecker::CreateLambdaCtorImplicitParams(ArenaV auto *field = it->AsClassProperty()->Key()->AsIdentifier(); auto *param_field = Allocator()->New(field->Name(), Allocator()); auto *param = Allocator()->New(param_field, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; auto *type = MaybeBoxedType(field->Variable()); var->SetTsType(type); @@ -1926,7 +2050,7 @@ varbinder::FunctionParamScope *ETSChecker::CreateLambdaCtorImplicitParams(ArenaV return param_ctx.GetScope(); } -ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varbinder::Variable *var) +ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, binder::Variable *var) { // Create synthetic field initializers for the lambda class fields // The node structure is the following: this.field0 = field0, where the left hand side refers to the lambda @@ -1947,12 +2071,12 @@ ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varb void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *ref_node, Signature *signature, ETSObjectType *functional_interface) { - if (VarBinder()->AsETSBinder()->LambdaObjects().count(ref_node) != 0) { + if (Binder()->AsETSBinder()->LambdaObjects().count(ref_node) != 0) { return; } // Create the class scope for the synthetic lambda class node - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); auto *class_scope = class_ctx.GetScope(); bool is_static_reference = signature->HasSignatureFlag(SignatureFlags::STATIC); @@ -1990,16 +2114,16 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *ref_node, S class_scope->BindNode(lambda_object); // Build the lambda object in the binder - VarBinder()->AsETSBinder()->BuildLambdaObject(ref_node, lambda_object, signature); + Binder()->AsETSBinder()->BuildLambdaObject(ref_node, lambda_object, signature); // Resolve the lambda object ResolveLambdaObject(lambda_object, signature, functional_interface, ref_node); } -ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, const lexer::SourcePosition &pos) +ir::AstNode *ETSChecker::CreateLambdaImplicitField(binder::ClassScope *scope, const lexer::SourcePosition &pos) { // Enter the lambda class instance field scope, every property will be bound to the lambda instance itself - auto field_ctx = varbinder::LexicalScope::Enter(VarBinder(), scope->InstanceFieldScope()); + auto field_ctx = binder::LexicalScope::Enter(Binder(), scope->InstanceFieldScope()); // Create the synthetic class property node auto *field_ident = Allocator()->New("field0", Allocator()); @@ -2007,8 +2131,8 @@ ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, Allocator()->New(field_ident, nullptr, nullptr, ir::ModifierFlags::NONE, Allocator(), false); // Add the declaration to the scope - auto [decl, var] = VarBinder()->NewVarDecl(pos, field_ident->Name()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); + auto [decl, var] = Binder()->NewVarDecl(pos, field_ident->Name()); + var->AddFlag(binder::VariableFlags::PROPERTY); field_ident->SetVariable(var); decl->BindNode(field); return field; @@ -2023,8 +2147,8 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa auto [funcParamScope, var] = CreateLambdaCtorImplicitParam(params, pos, is_static_reference); // Create the scopes - auto param_ctx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); - auto *scope = VarBinder()->Allocator()->New(Allocator(), funcParamScope); + auto param_ctx = binder::LexicalScope::Enter(Binder(), funcParamScope, false); + auto *scope = Binder()->Allocator()->New(Allocator(), funcParamScope); // If the reference refers to a static function, the constructor will be empty, otherwise, we have to make a // synthetic initializer to initialize the lambda class field @@ -2057,11 +2181,11 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa return ctor; } -std::tuple ETSChecker::CreateLambdaCtorImplicitParam( +std::tuple ETSChecker::CreateLambdaCtorImplicitParam( ArenaVector ¶ms, const lexer::SourceRange &pos, bool is_static_reference) { // Create the function parameter scope - auto param_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope(Binder()); // Create the synthetic constructors parameter, if this is a static reference, we don't need any parameter, // since when initializing the lambda class, we don't need to save the instance object which we tried to get the @@ -2070,7 +2194,7 @@ std::tuple ETSChecker::C auto *param_ident = Allocator()->New("field0", Allocator()); auto *param = Allocator()->New(param_ident, nullptr); param_ident->SetRange(pos); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; param_ident->SetVariable(var); params.push_back(param); @@ -2085,9 +2209,8 @@ ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto() // Create the template for the synthetic 'invoke' method, which will be used when the function type will be // called auto *name = Allocator()->New("invoke", Allocator()); - auto *param_scope = - VarBinder()->Allocator()->New(Allocator(), VarBinder()->GetScope()); - auto *scope = VarBinder()->Allocator()->New(Allocator(), param_scope); + auto *param_scope = Binder()->Allocator()->New(Allocator(), Binder()->GetScope()); + auto *scope = Binder()->Allocator()->New(Allocator(), param_scope); ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); @@ -2113,14 +2236,13 @@ ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto() return method; } -void ETSChecker::CreateLambdaFuncDecl(ir::MethodDefinition *func, varbinder::LocalScope *scope) +void ETSChecker::CreateLambdaFuncDecl(ir::MethodDefinition *func, binder::LocalScope *scope) { // Add the function declarations to the lambda class scope - auto ctx = varbinder::LexicalScope::Enter(VarBinder(), scope); - auto [_, var] = - VarBinder()->NewVarDecl(func->Start(), Allocator(), func->Id()->Name(), func); + auto ctx = binder::LexicalScope::Enter(Binder(), scope); + auto [_, var] = Binder()->NewVarDecl(func->Start(), Allocator(), func->Id()->Name(), func); (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); func->Function()->Id()->SetVariable(var); } @@ -2130,7 +2252,7 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambda_object, Signatu // Set the type information for the lambda class, which will be required by the compiler Type *target_type = signature->Owner(); bool is_static_reference = signature->HasSignatureFlag(SignatureFlags::STATIC); - varbinder::Variable *field_var {}; + binder::Variable *field_var {}; // If this is NOT a static function reference, we have to set the field's type to the referenced signatures // owner type, because that will be the type of the instance object which will be saved in that field @@ -2158,7 +2280,7 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambda_object, Signatu if (!is_static_reference) { lambda_object_type->AddProperty(field_var->AsLocalVariable()); } - VarBinder()->AsETSBinder()->BuildLambdaObjectName(ref_node); + Binder()->AsETSBinder()->BuildLambdaObjectName(ref_node); // Resolve the constructor ResolveLambdaObjectCtor(lambda_object, is_static_reference); @@ -2172,7 +2294,7 @@ void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambda_object, boo const auto &lambda_body = lambda_object->Body(); auto *ctor_func = lambda_body[lambda_body.size() - 2]->AsMethodDefinition()->Function(); ETSObjectType *lambda_object_type = lambda_object->TsType()->AsETSObjectType(); - varbinder::Variable *field_var {}; + binder::Variable *field_var {}; if (!is_static_reference) { auto *field = lambda_body[0]->AsClassProperty(); @@ -2204,7 +2326,7 @@ void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambda_object, boo auto *ctor_type = CreateETSFunctionType(ctor_signature); ctor_func->SetSignature(ctor_signature); ctor_func->Id()->Variable()->SetTsType(ctor_type); - VarBinder()->AsETSBinder()->BuildFunctionName(ctor_func); + Binder()->AsETSBinder()->BuildFunctionName(ctor_func); // If this is a static function reference, we are done, since the constructor body is empty if (is_static_reference) { @@ -2244,12 +2366,12 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambda_object, S // Create the parameters for the invoke function, based on the referenced function's signature for (auto *it : signature_ref->Params()) { - auto param_ctx = varbinder::LexicalScope::Enter( - VarBinder(), invoke_func->Scope()->ParamScope(), false); + auto param_ctx = binder::LexicalScope::Enter( + Binder(), invoke_func->Scope()->ParamScope(), false); auto *param_ident = Allocator()->New(it->Name(), Allocator()); auto *param = Allocator()->New(param_ident, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto [_, var] = Binder()->AddParamDecl(param); (void)_; var->SetTsType(it->TsType()); param_ident->SetVariable(var); @@ -2266,7 +2388,7 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambda_object, S auto *invoke_type = CreateETSFunctionType(invoke_signature); invoke_func->SetSignature(invoke_signature); invoke_func->Id()->Variable()->SetTsType(invoke_type); - VarBinder()->AsETSBinder()->BuildFunctionName(invoke_func); + Binder()->AsETSBinder()->BuildFunctionName(invoke_func); lambda_object_type->AddProperty( invoke_func->Id()->Variable()->AsLocalVariable()); @@ -2294,9 +2416,10 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition field_prop_type = signature_ref->Owner(); field_ident->SetVariable(signature_ref->Owner()->Variable()); field_ident->SetTsType(field_prop_type); - } else { - // Otherwise, we should call the referenced function through the saved field, which hold the object instance - // reference + } + // Otherwise, we should call the referenced function through the saved field, which hold the object instance + // reference + else { auto *field_prop = lambda_body[0]->AsClassProperty()->Key()->AsIdentifier()->Variable(); field_prop_type = field_prop->TsType()->AsETSObjectType(); field_ident = Allocator()->New("field0", Allocator()); @@ -2371,17 +2494,13 @@ std::string ETSChecker::GetAsyncImplName(const util::StringView &name) return impl_name; } -std::string ETSChecker::GetAsyncImplName(ir::MethodDefinition *async_method) +ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *async_method, ir::ClassDefinition *class_def, + bool create_decl) { ir::Identifier *async_name = async_method->Function()->Id(); ASSERT(async_name != nullptr); - return GetAsyncImplName(async_name->Name()); -} + util::UString impl_name(GetAsyncImplName(async_name->Name()), Allocator()); -ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *async_method, - ir::ClassDefinition *class_def) -{ - util::UString impl_name(GetAsyncImplName(async_method), Allocator()); ir::ModifierFlags modifiers = async_method->Modifiers(); // clear ASYNC flag for implementation modifiers &= ~ir::ModifierFlags::ASYNC; @@ -2392,17 +2511,18 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as } async_method->AddModifier(ir::ModifierFlags::NATIVE); async_func->AddModifier(ir::ModifierFlags::NATIVE); + Binder()->AsETSBinder()->GetRecordTable()->Signatures().push_back(async_func->Scope()); + // Create async_impl method copied from CreateInvokeFunction - auto scope_ctx = - varbinder::LexicalScope::Enter(VarBinder(), class_def->Scope()->AsClassScope()); + auto scope_ctx = binder::LexicalScope::Enter(Binder(), class_def->Scope()->AsClassScope()); auto *body = async_func->Body(); ArenaVector params(Allocator()->Adapter()); - varbinder::FunctionParamScope *param_scope = CopyParams(async_func->Params(), params); + binder::FunctionParamScope *param_scope = CopyParams(async_func->Params(), params); // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type auto *object_id = Allocator()->New(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); object_id->SetReference(); - VarBinder()->AsETSBinder()->LookupTypeReference(object_id, false); + Binder()->AsETSBinder()->LookupTypeReference(object_id, false); auto *return_type_ann = Allocator()->New(Allocator()->New(object_id, nullptr, nullptr)); object_id->SetParent(return_type_ann->Part()); @@ -2419,17 +2539,7 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as impl_method->SetParent(async_method->Parent()); std::for_each(impl_method->Function()->Params().begin(), impl_method->Function()->Params().end(), [impl_method](ir::Expression *param) { param->SetParent(impl_method->Function()); }); - return impl_method; -} - -ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *async_method, ir::ClassDefinition *class_def, - bool create_decl) -{ - ir::ScriptFunction *async_func = async_method->Function(); - VarBinder()->AsETSBinder()->GetRecordTable()->Signatures().push_back(async_func->Scope()); - - ir::MethodDefinition *impl_method = CreateAsyncImplMethod(async_method, class_def); - varbinder::FunctionScope *impl_func_scope = impl_method->Function()->Scope(); + binder::FunctionScope *impl_func_scope = impl_method->Function()->Scope(); for (auto *decl : async_func->Scope()->Decls()) { auto res = async_func->Scope()->Bindings().find(decl->Name()); ASSERT(res != async_func->Scope()->Bindings().end()); @@ -2445,7 +2555,7 @@ ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *async_m } ReplaceScope(impl_method->Function()->Body(), async_func, impl_func_scope); - ArenaVector captured(Allocator()->Adapter()); + ArenaVector captured(Allocator()->Adapter()); bool is_static = async_method->IsStatic(); if (create_decl) { @@ -2455,7 +2565,7 @@ ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *async_m CreateLambdaFuncDecl(impl_method, class_def->Scope()->AsClassScope()->InstanceMethodScope()); } } - VarBinder()->AsETSBinder()->BuildProxyMethod(impl_method->Function(), class_def->InternalName(), is_static); + Binder()->AsETSBinder()->BuildProxyMethod(impl_method->Function(), class_def->InternalName(), is_static); impl_method->SetParent(async_method->Parent()); return impl_method; @@ -2463,11 +2573,11 @@ ir::MethodDefinition *ETSChecker::CreateAsyncProxy(ir::MethodDefinition *async_m ir::MethodDefinition *ETSChecker::CreateMethod(const util::StringView &name, ir::ModifierFlags modifiers, ir::ScriptFunctionFlags flags, ArenaVector &¶ms, - varbinder::FunctionParamScope *param_scope, ir::TypeNode *return_type, + binder::FunctionParamScope *param_scope, ir::TypeNode *return_type, ir::AstNode *body) { auto *name_id = Allocator()->New(name, Allocator()); - auto *scope = VarBinder()->Allocator()->New(Allocator(), param_scope); + auto *scope = Binder()->Allocator()->New(Allocator(), param_scope); ir::ScriptFunction *func = Allocator()->New( scope, std::move(params), nullptr, body, return_type, flags, modifiers, false, Language(Language::Id::ETS)); func->SetIdent(name_id); @@ -2489,16 +2599,16 @@ ir::MethodDefinition *ETSChecker::CreateMethod(const util::StringView &name, ir: return method; } -varbinder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVector ¶ms, - ArenaVector &out_params) +binder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVector ¶ms, + ArenaVector &out_params) { - auto param_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope(Binder()); for (auto *const it : params) { auto *const param_expr_ident = it->AsETSParameterExpression()->Ident(); auto *const param_ident = Allocator()->New(param_expr_ident->Name(), Allocator()); auto *const param = Allocator()->New(param_ident, nullptr); - auto *const var = std::get<1>(VarBinder()->AddParamDecl(param)); + auto *const var = std::get<1>(Binder()->AddParamDecl(param)); var->SetTsType(param_expr_ident->Variable()->TsType()); var->SetScope(param_ctx.GetScope()); param->SetVariable(var); @@ -2511,7 +2621,42 @@ varbinder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVectorIsBlockStatement()) { + return ast->AsBlockStatement()->Scope(); + } + if (ast->IsDoWhileStatement()) { + return ast->AsDoWhileStatement()->Scope(); + } + if (ast->IsForInStatement()) { + return ast->AsForInStatement()->Scope(); + } + if (ast->IsForOfStatement()) { + return ast->AsForOfStatement()->Scope(); + } + if (ast->IsForUpdateStatement()) { + return ast->AsForUpdateStatement()->Scope(); + } + if (ast->IsSwitchStatement()) { + return ast->AsSwitchStatement()->Scope(); + } + if (ast->IsWhileStatement()) { + return ast->AsWhileStatement()->Scope(); + } + if (ast->IsCatchClause()) { + return ast->AsCatchClause()->Scope(); + } + if (ast->IsClassDefinition()) { + return ast->AsClassDefinition()->Scope(); + } + if (ast->IsScriptFunction()) { + return ast->AsScriptFunction()->Scope()->ParamScope(); + } + return nullptr; +} + +void ETSChecker::ReplaceScope(ir::AstNode *root, ir::AstNode *old_node, binder::Scope *new_scope) { root->Iterate([this, old_node, new_scope](ir::AstNode *child) { auto *scope = NodeScope(child); @@ -2553,11 +2698,10 @@ void ETSChecker::TransformTraillingLambda(ir::CallExpression *call_expr) auto *trailing_block = call_expr->TrailingBlock(); ASSERT(trailing_block != nullptr); - auto *func_param_scope = varbinder::LexicalScope(VarBinder()).GetScope(); - auto param_ctx = - varbinder::LexicalScope::Enter(VarBinder(), func_param_scope, false); + auto *func_param_scope = binder::LexicalScope(Binder()).GetScope(); + auto param_ctx = binder::LexicalScope::Enter(Binder(), func_param_scope, false); - auto func_ctx = varbinder::LexicalScope(VarBinder()); + auto func_ctx = binder::LexicalScope(Binder()); auto *func_scope = func_ctx.GetScope(); func_scope->BindParamScope(func_param_scope); func_param_scope->BindFunctionScope(func_scope); @@ -2590,7 +2734,7 @@ void ETSChecker::TransformTraillingLambda(ir::CallExpression *call_expr) ArenaVector ETSChecker::ExtendArgumentsWithFakeLamda(ir::CallExpression *call_expr) { - auto func_ctx = varbinder::LexicalScope(VarBinder()); + auto func_ctx = binder::LexicalScope(Binder()); auto *func_scope = func_ctx.GetScope(); ArenaVector params(Allocator()->Adapter()); diff --git a/ets2panda/checker/ets/function_helpers.h b/ets2panda/checker/ets/function_helpers.h deleted file mode 100644 index 0ac3267d1a87ce97316ba904af40eab751985e9b..0000000000000000000000000000000000000000 --- a/ets2panda/checker/ets/function_helpers.h +++ /dev/null @@ -1,247 +0,0 @@ -/** - * 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_COMPILER_CHECKER_ETS_FUNCTION_HELPERS_H -#define ES2PANDA_COMPILER_CHECKER_ETS_FUNCTION_HELPERS_H - -#include "varbinder/varbinder.h" -#include "varbinder/declaration.h" -#include "varbinder/ETSBinder.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" -#include "varbinder/variableFlags.h" -#include "checker/ETSchecker.h" -#include "checker/ets/typeRelationContext.h" -#include "checker/types/ets/etsAsyncFuncReturnType.h" -#include "checker/types/ets/etsObjectType.h" -#include "checker/types/type.h" -#include "checker/types/typeFlag.h" -#include "ir/astNode.h" -#include "ir/typeNode.h" -#include "ir/base/catchClause.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classProperty.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/thisExpression.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/doWhileStatement.h" -#include "ir/statements/expressionStatement.h" -#include "ir/statements/forInStatement.h" -#include "ir/statements/forOfStatement.h" -#include "ir/statements/forUpdateStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/statements/switchStatement.h" -#include "ir/statements/whileStatement.h" -#include "ir/ts/tsArrayType.h" -#include "ir/ts/tsInterfaceBody.h" -#include "ir/ts/tsTypeAliasDeclaration.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "parser/program/program.h" -#include "util/helpers.h" -#include "util/language.h" - -namespace panda::es2panda::checker { - -static Type *MaybeBoxedType(ETSChecker *checker, Type *type, ir::Expression *expr) -{ - if (!type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { - return type; - } - auto *relation = checker->Relation(); - auto *old_node = relation->GetNode(); - relation->SetNode(expr); - auto *res = checker->PrimitiveTypeAsETSBuiltinType(type); - relation->SetNode(old_node); - return res; -} - -static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *checker, Signature *signature, - const ArenaVector &arguments) -{ - Substitution *substitution = checker->NewSubstitution(); - auto *sig_info = signature->GetSignatureInfo(); - ArenaVector &type_params = sig_info->type_params; - for (size_t ix = 0; ix < arguments.size(); ix++) { - auto *arg = arguments[ix]; - if (arg->IsObjectExpression()) { - continue; - } - auto *arg_type = arg->Check(checker); - arg_type = MaybeBoxedType(checker, arg_type, arg); - auto *param_type = - (ix < signature->MinArgCount()) ? sig_info->params[ix]->TsType() : sig_info->rest_var->TsType(); - if (param_type == nullptr) { - continue; - } - checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution); - } - return substitution; -} - -static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *checker, Signature *signature, - const ir::TSTypeParameterInstantiation *type_arguments, - const lexer::SourcePosition &pos, - TypeRelationFlag flags) -{ - auto *substitution = checker->NewSubstitution(); - ArenaVector &type_params = signature->GetSignatureInfo()->type_params; - ArenaVector type_arg_types {checker->Allocator()->Adapter()}; - for (auto *ta_expr : type_arguments->Params()) { - auto *type_arg = ta_expr->GetType(checker); - type_arg = MaybeBoxedType(checker, type_arg, ta_expr); - type_arg_types.push_back(type_arg); - } - if (type_params.size() != type_arg_types.size()) { - if ((flags & TypeRelationFlag::NO_THROW) == 0) { - checker->ThrowTypeError( - {"Expected ", type_params.size(), " type arguments, got ", type_arg_types.size(), " ."}, pos); - } - return nullptr; - } - for (size_t ix = 0; ix < type_arg_types.size(); ix++) { - if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix])) { - return nullptr; - } - substitution->emplace(type_params[ix], type_arg_types[ix]); - } - return substitution; -} - -static Signature *MaybeSubstituteTypeParameters(ETSChecker *checker, Signature *signature, - const ir::TSTypeParameterInstantiation *type_arguments, - const ArenaVector &arguments, - const lexer::SourcePosition &pos, TypeRelationFlag flags) -{ - if (type_arguments == nullptr && signature->GetSignatureInfo()->type_params.empty()) { - return signature; - } - const Substitution *substitution = - (type_arguments != nullptr) - ? BuildExplicitSubstitutionForArguments(checker, signature, type_arguments, pos, flags) - : BuildImplicitSubstitutionForArguments(checker, signature, arguments); - return (substitution == nullptr) ? nullptr : signature->Substitute(checker->Relation(), substitution); -} - -static bool CmpAssemblerTypesWithRank(Signature *sig1, Signature *sig2) -{ - for (size_t ix = 0; ix < sig1->MinArgCount(); ix++) { - std::stringstream s1; - std::stringstream s2; - sig1->Params()[ix]->TsType()->ToAssemblerTypeWithRank(s1); - sig2->Params()[ix]->TsType()->ToAssemblerTypeWithRank(s2); - if (s1.str() != s2.str()) { - return false; - break; - } - } - return true; -} - -static bool HasSameAssemblySignature(ETSFunctionType *func1, ETSFunctionType *func2) -{ - for (auto *sig1 : func1->CallSignatures()) { - for (auto *sig2 : func2->CallSignatures()) { - if (sig1->MinArgCount() != sig2->MinArgCount()) { - continue; - } - bool all_same = CmpAssemblerTypesWithRank(sig1, sig2); - if (!all_same) { - continue; - } - auto *rv1 = sig1->RestVar(); - auto *rv2 = sig2->RestVar(); - if (rv1 == nullptr && rv2 == nullptr) { - return true; - } - if (rv1 == nullptr || rv2 == nullptr) { // exactly one of them is null - return false; - } - std::stringstream s1; - std::stringstream s2; - rv1->TsType()->ToAssemblerTypeWithRank(s1); - rv2->TsType()->ToAssemblerTypeWithRank(s2); - if (s1.str() == s2.str()) { - return true; - } - } - } - return false; -} - -static bool CheckInterfaceOverride(ETSChecker *const checker, ETSObjectType *const interface, - Signature *const signature) -{ - bool is_overriding = checker->CheckOverride(signature, interface); - - for (auto *const super_interface : interface->Interfaces()) { - is_overriding |= CheckInterfaceOverride(checker, super_interface, signature); - } - - return is_overriding; -} - -static varbinder::Scope *NodeScope(ir::AstNode *ast) -{ - if (ast->IsBlockStatement()) { - return ast->AsBlockStatement()->Scope(); - } - if (ast->IsDoWhileStatement()) { - return ast->AsDoWhileStatement()->Scope(); - } - if (ast->IsForInStatement()) { - return ast->AsForInStatement()->Scope(); - } - if (ast->IsForOfStatement()) { - return ast->AsForOfStatement()->Scope(); - } - if (ast->IsForUpdateStatement()) { - return ast->AsForUpdateStatement()->Scope(); - } - if (ast->IsSwitchStatement()) { - return ast->AsSwitchStatement()->Scope(); - } - if (ast->IsWhileStatement()) { - return ast->AsWhileStatement()->Scope(); - } - if (ast->IsCatchClause()) { - return ast->AsCatchClause()->Scope(); - } - if (ast->IsClassDefinition()) { - return ast->AsClassDefinition()->Scope(); - } - if (ast->IsScriptFunction()) { - return ast->AsScriptFunction()->Scope()->ParamScope(); - } - return nullptr; -} - -} // namespace panda::es2panda::checker - -#endif \ No newline at end of file diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index ad63b2360822238f38256dcdc5ae876ed9b93474..d8417228b46d5ae5a1133b84f46a5fd42e16d848 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "checker/checker.h" #include "checker/checkerContext.h" #include "checker/ets/narrowingWideningConverter.h" @@ -55,13 +55,13 @@ #include "ir/ets/etsTypeReferencePart.h" #include "ir/ets/etsPrimitiveType.h" #include "ir/ts/tsQualifiedName.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" #include "parser/ETSparser.h" #include "parser/program/program.h" #include "checker/ETSchecker.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "checker/ets/typeRelationContext.h" #include "checker/ets/boxingConverter.h" #include "checker/ets/unboxingConverter.h" @@ -72,15 +72,13 @@ namespace panda::es2panda::checker { void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) { checker::Type *type = expr->Check(this); - auto *unboxed_type = ETSBuiltinTypeAsConditionalType(type); + auto *unboxed_type = ETSBuiltinTypeAsPrimitiveType(type); - if (unboxed_type != nullptr && !unboxed_type->IsConditionalExprType()) { - ThrowTypeError("Condition must be of possible condition type", expr->Start()); + if (unboxed_type == nullptr || !unboxed_type->IsETSBooleanType()) { + ThrowTypeError("Condition must be of type boolean", expr->Start()); } - if (unboxed_type != nullptr && unboxed_type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { - FlagExpressionWithUnboxing(type, unboxed_type, expr); - } + FlagExpressionWithUnboxing(type, unboxed_type, expr); expr->SetTsType(unboxed_type); } @@ -133,7 +131,7 @@ Type *ETSChecker::GetNonConstantTypeFromPrimitiveType(Type *type) return type; } -Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) +Type *ETSChecker::GetTypeOfVariable(binder::Variable *const var) { if (IsVariableGetterSetter(var)) { auto *prop_type = var->TsType()->AsETSFunctionType(); @@ -147,15 +145,15 @@ Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) return var->TsType(); } - // NOTE: kbaladurin. forbid usage of imported entities as types without declarations - if (VarBinder()->AsETSBinder()->IsDynamicModuleVariable(var)) { - auto *import_data = VarBinder()->AsETSBinder()->DynamicImportDataForVar(var); + // TODO(kbaladurin): forbid usage of imported entities as types without declarations + if (Binder()->AsETSBinder()->IsDynamicModuleVariable(var)) { + auto *import_data = Binder()->AsETSBinder()->DynamicImportDataForVar(var); if (import_data->import->IsPureDynamic()) { return GlobalBuiltinDynamicType(import_data->import->Language()); } } - varbinder::Decl *decl = var->Declaration(); + binder::Decl *decl = var->Declaration(); // Before computing the given variables type, we have to make a new checker context frame so that the checking is // done in the proper context, and have to enter the scope where the given variable is declared, so reference @@ -188,15 +186,15 @@ Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) } switch (decl->Type()) { - case varbinder::DeclType::CLASS: { + case binder::DeclType::CLASS: { auto *class_def = decl->Node()->AsClassDefinition(); BuildClassProperties(class_def); return class_def->TsType(); } - case varbinder::DeclType::ENUM_LITERAL: - case varbinder::DeclType::CONST: - case varbinder::DeclType::LET: - case varbinder::DeclType::VAR: { + case binder::DeclType::ENUM_LITERAL: + case binder::DeclType::CONST: + case binder::DeclType::LET: + case binder::DeclType::VAR: { auto *decl_node = decl->Node(); if (decl->Node()->IsIdentifier()) { @@ -205,16 +203,16 @@ Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) return decl_node->Check(this); } - case varbinder::DeclType::FUNC: { + case binder::DeclType::FUNC: { return decl->Node()->Check(this); } - case varbinder::DeclType::IMPORT: { + case binder::DeclType::IMPORT: { return decl->Node()->Check(this); } - case varbinder::DeclType::TYPE_ALIAS: { + case binder::DeclType::TYPE_ALIAS: { return GetTypeFromTypeAliasReference(var); } - case varbinder::DeclType::INTERFACE: { + case binder::DeclType::INTERFACE: { return BuildInterfaceProperties(decl->Node()->AsTSInterfaceDeclaration()); } default: { @@ -225,21 +223,21 @@ Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) return var->TsType(); } -void ETSChecker::ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos) +void ETSChecker::ValidatePropertyAccess(binder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos) { if ((Context().Status() & CheckerStatus::IGNORE_VISIBILITY) != 0U) { return; } - if (var->HasFlag(varbinder::VariableFlags::METHOD)) { + if (var->HasFlag(binder::VariableFlags::METHOD)) { return; } - if (var->HasFlag(varbinder::VariableFlags::PRIVATE) || var->HasFlag(varbinder::VariableFlags::PROTECTED)) { + if (var->HasFlag(binder::VariableFlags::PRIVATE) || var->HasFlag(binder::VariableFlags::PROTECTED)) { if (Context().ContainingClass() == obj && obj->IsPropertyInherited(var)) { return; } - if (var->HasFlag(varbinder::VariableFlags::PROTECTED) && Context().ContainingClass()->IsDescendantOf(obj) && + if (var->HasFlag(binder::VariableFlags::PROTECTED) && Context().ContainingClass()->IsDescendantOf(obj) && obj->IsPropertyInherited(var)) { return; } @@ -256,12 +254,12 @@ void ETSChecker::ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType } } -varbinder::Variable *ETSChecker::FindVariableInFunctionScope(const util::StringView name) +binder::Variable *ETSChecker::FindVariableInFunctionScope(const util::StringView name) { - return Scope()->FindInFunctionScope(name, varbinder::ResolveBindingOptions::ALL).variable; + return Scope()->FindInFunctionScope(name, binder::ResolveBindingOptions::ALL).variable; } -std::pair ETSChecker::FindVariableInClassOrEnclosing( +std::pair ETSChecker::FindVariableInClassOrEnclosing( const util::StringView name, const ETSObjectType *class_type) { const auto search_flags = PropertySearchFlags::SEARCH_ALL | PropertySearchFlags::SEARCH_IN_BASE | @@ -275,48 +273,30 @@ std::pair ETSChecker::FindVa return {resolved, class_type}; } -varbinder::Variable *ETSChecker::FindVariableInGlobal(const ir::Identifier *const identifier) +binder::Variable *ETSChecker::FindVariableInGlobal(const ir::Identifier *const identifier) { - return Scope()->FindInGlobal(identifier->Name(), varbinder::ResolveBindingOptions::ALL).variable; + return Scope()->FindInGlobal(identifier->Name(), binder::ResolveBindingOptions::ALL).variable; } -bool ETSChecker::IsVariableStatic(const varbinder::Variable *var) const +bool ETSChecker::IsVariableStatic(const binder::Variable *var) const { - if (var->HasFlag(varbinder::VariableFlags::METHOD)) { + if (var->HasFlag(binder::VariableFlags::METHOD)) { return var->TsType()->AsETSFunctionType()->CallSignatures()[0]->HasSignatureFlag(SignatureFlags::STATIC); } - return var->HasFlag(varbinder::VariableFlags::STATIC); + return var->HasFlag(binder::VariableFlags::STATIC); } -bool ETSChecker::IsVariableGetterSetter(const varbinder::Variable *var) const +bool ETSChecker::IsVariableGetterSetter(const binder::Variable *var) const { return var->TsType() != nullptr && var->TsType()->HasTypeFlag(TypeFlag::GETTER_SETTER); } -void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) +void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, binder::Variable *const resolved) { const auto throw_error = [this, ident]() { ThrowTypeError({"Unresolved reference ", ident->Name()}, ident->Start()); }; - // Just to avoid extra nested level - const auto check_ets_function_type = [this, &throw_error](ir::Identifier const *const id, - ir::TypeNode const *const annotation) -> void { - if (annotation == nullptr) { - ThrowTypeError( - {"Cannot infer type for ", id->Name(), " because method reference needs an explicit target type"}, - id->Start()); - } - - const auto *const target_type = GetTypeOfVariable(id->Variable()); - ASSERT(target_type != nullptr); - - if (!target_type->IsETSObjectType() || - !target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - throw_error(); - } - }; - if (resolved == nullptr) { const auto [class_var, class_type] = FindVariableInClassOrEnclosing(ident->Name(), Context().ContainingClass()); if (class_var == nullptr) { @@ -348,7 +328,7 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind } case ir::AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION: { if (ident->Parent()->AsETSNewClassInstanceExpression()->GetTypeRef() == ident && - !resolved->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + !resolved->HasFlag(binder::VariableFlags::CLASS_OR_INTERFACE)) { throw_error(); } @@ -364,8 +344,7 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind } if (!resolved_type->IsETSObjectType() && !resolved_type->IsETSArrayType() && - !resolved_type->IsETSEnumType() && !resolved_type->IsETSStringEnumType() && - !resolved_type->IsETSUnionType()) { + !resolved_type->IsETSEnumType() && !resolved_type->IsETSStringEnumType()) { throw_error(); } @@ -406,7 +385,20 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind }(); if (resolved->TsType()->IsETSFunctionType()) { - check_ets_function_type(target_ident, type_annotation); + if (type_annotation == nullptr) { + ThrowTypeError({"Cannot infer type for ", target_ident->Name(), + " because method reference needs an explicit target type"}, + target_ident->Start()); + } + + const auto *const target_type = GetTypeOfVariable(target_ident->Variable()); + ASSERT(target_type != nullptr); + + if (!target_type->IsETSObjectType() || + !target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + throw_error(); + } + break; } @@ -455,18 +447,18 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind } } -void ETSChecker::SaveCapturedVariable(varbinder::Variable *const var, const lexer::SourcePosition &pos) +void ETSChecker::SaveCapturedVariable(binder::Variable *const var, const lexer::SourcePosition &pos) { if (!HasStatus(CheckerStatus::IN_LAMBDA)) { return; } - if (var->HasFlag(varbinder::VariableFlags::PROPERTY)) { + if (var->HasFlag(binder::VariableFlags::PROPERTY)) { Context().AddCapturedVar(var, pos); return; } - if ((!var->HasFlag(varbinder::VariableFlags::LOCAL) && !var->HasFlag(varbinder::VariableFlags::METHOD)) || + if ((!var->HasFlag(binder::VariableFlags::LOCAL) && !var->HasFlag(binder::VariableFlags::METHOD)) || (var->GetScope()->Node()->IsScriptFunction() && var->GetScope()->Node()->AsScriptFunction()->IsArrow())) { return; } @@ -498,7 +490,7 @@ Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) ValidateResolvedIdentifier(ident, resolved); - if (resolved->HasFlag(varbinder::VariableFlags::METHOD)) { + if (resolved->HasFlag(binder::VariableFlags::METHOD)) { ASSERT(resolved->TsType()->IsETSFunctionType() && !resolved->TsType()->AsETSFunctionType()->CallSignatures().empty()); const auto *const func_type = resolved->TsType()->AsETSFunctionType(); @@ -506,7 +498,7 @@ Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) // In the case of function references, it is not enough to find the first method field and use it's function // type, because at the position of the call we should be able to work with every possible signature, even // with ones that came from base classes. - // NOTE: szd. find a better way than making a synthetic variable + // TODO(szd): find a better way than making a synthetic variable resolved = func_type->CallSignatures().front()->Owner()->CreateSyntheticVarFromEverySignature( ident->Name(), PropertySearchFlags::SEARCH_METHOD | PropertySearchFlags::SEARCH_IN_BASE); } @@ -519,7 +511,7 @@ Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) return resolved->TsType(); } -void ETSChecker::ValidateUnaryOperatorOperand(varbinder::Variable *variable) +void ETSChecker::ValidateUnaryOperatorOperand(binder::Variable *variable) { if (IsVariableGetterSetter(variable)) { return; @@ -527,12 +519,12 @@ void ETSChecker::ValidateUnaryOperatorOperand(varbinder::Variable *variable) if (variable->Declaration()->IsConstDecl()) { if (HasStatus(CheckerStatus::IN_CONSTRUCTOR | CheckerStatus::IN_STATIC_BLOCK) && - !variable->HasFlag(varbinder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { + !variable->HasFlag(binder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { ThrowTypeError({"Cannot reassign constant field ", variable->Name()}, variable->Declaration()->Node()->Start()); } if (!HasStatus(CheckerStatus::IN_CONSTRUCTOR | CheckerStatus::IN_STATIC_BLOCK) && - !variable->HasFlag(varbinder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { + !variable->HasFlag(binder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { ThrowTypeError({"Cannot assign to a constant variable ", variable->Name()}, variable->Declaration()->Node()->Start()); } @@ -634,10 +626,9 @@ checker::Type *ETSChecker::ApplyConditionalOperatorPromotion(checker::ETSChecker UNREACHABLE(); } -Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, const bool create_const, const bool do_promotion, - const bool is_cond_expr) +Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, bool create_const, bool do_promotion) { - Type *unboxed_type = is_cond_expr ? ETSBuiltinTypeAsConditionalType(type) : ETSBuiltinTypeAsPrimitiveType(type); + Type *unboxed_type = ETSBuiltinTypeAsPrimitiveType(type); if (unboxed_type == nullptr) { return nullptr; @@ -661,58 +652,6 @@ Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, const bool create_cons return unboxed_type; } -bool ETSChecker::IsNullOrVoidExpression(const ir::Expression *expr) const -{ - return (expr->IsLiteral() && expr->AsLiteral()->IsNullLiteral()) || - (expr->IsCallExpression() && - (expr->AsCallExpression()->Signature()->ReturnType() == GlobalBuiltinVoidType())); -} - -Type *ETSChecker::HandleBooleanLogicalOperatorsExtended(Type *left_type, Type *right_type, ir::BinaryExpression *expr) -{ - ASSERT(left_type->IsConditionalExprType() && right_type->IsConditionalExprType()); - - bool resolve_left = false; - bool left_value = false; - bool resolve_right = false; - bool right_value = false; - std::tie(resolve_left, left_value) = - IsNullOrVoidExpression(expr->Left()) ? std::make_tuple(true, false) : left_type->ResolveConditionExpr(); - std::tie(resolve_right, right_value) = - IsNullOrVoidExpression(expr->Right()) ? std::make_tuple(true, false) : right_type->ResolveConditionExpr(); - - if (!resolve_left) { - // return the UNION type when it is implemented - return IsTypeIdenticalTo(left_type, right_type) ? left_type : GlobalETSBooleanType(); - } - - switch (expr->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - if (left_value) { - expr->SetResult(expr->Left()); - return left_type->IsETSBooleanType() ? CreateETSBooleanType(true) : left_type; - } - - expr->SetResult(expr->Right()); - return right_type->IsETSBooleanType() && resolve_right ? CreateETSBooleanType(right_value) : right_type; - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - if (left_value) { - expr->SetResult(expr->Right()); - return right_type->IsETSBooleanType() && resolve_right ? CreateETSBooleanType(right_value) : right_type; - } - - expr->SetResult(expr->Left()); - return left_type->IsETSBooleanType() ? CreateETSBooleanType(false) : left_type; - } - default: { - break; - } - } - - UNREACHABLE(); -} - Type *ETSChecker::HandleBooleanLogicalOperators(Type *left_type, Type *right_type, lexer::TokenType token_type) { using UType = typename ETSBooleanType::UType; @@ -755,7 +694,7 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T { const util::StringView &var_name = ident->Name(); ASSERT(ident->Variable()); - varbinder::Variable *const binding_var = ident->Variable(); + binder::Variable *const binding_var = ident->Variable(); checker::Type *annotation_type = nullptr; const bool is_const = (flags & ir::ModifierFlags::CONST) != 0; @@ -794,7 +733,7 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T } else if (IsTypeIdenticalTo(type, e_type)) { continue; } else { - // NOTE: Create union type when implemented here + // TODO (): Create union type when implemented here ThrowTypeError({"Union type is not implemented yet!"}, ident->Start()); } } @@ -893,7 +832,7 @@ void ETSChecker::SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpre } } -Type *ETSChecker::GetTypeFromTypeAliasReference(varbinder::Variable *var) +Type *ETSChecker::GetTypeFromTypeAliasReference(binder::Variable *var) { if (var->TsType() != nullptr) { return var->TsType(); @@ -907,7 +846,7 @@ Type *ETSChecker::GetTypeFromTypeAliasReference(varbinder::Variable *var) return aliased_type; } -Type *ETSChecker::GetTypeFromInterfaceReference(varbinder::Variable *var) +Type *ETSChecker::GetTypeFromInterfaceReference(binder::Variable *var) { if (var->TsType() != nullptr) { return var->TsType(); @@ -918,7 +857,7 @@ Type *ETSChecker::GetTypeFromInterfaceReference(varbinder::Variable *var) return interface_type; } -Type *ETSChecker::GetTypeFromClassReference(varbinder::Variable *var) +Type *ETSChecker::GetTypeFromClassReference(binder::Variable *var) { if (var->TsType() != nullptr) { return var->TsType(); @@ -929,7 +868,7 @@ Type *ETSChecker::GetTypeFromClassReference(varbinder::Variable *var) return class_type; } -Type *ETSChecker::GetTypeFromEnumReference([[maybe_unused]] varbinder::Variable *var) +Type *ETSChecker::GetTypeFromEnumReference([[maybe_unused]] binder::Variable *var) { if (var->TsType() != nullptr) { return var->TsType(); @@ -945,7 +884,7 @@ Type *ETSChecker::GetTypeFromEnumReference([[maybe_unused]] varbinder::Variable } } -Type *ETSChecker::GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos) +Type *ETSChecker::GetTypeFromTypeParameterReference(binder::LocalVariable *var, const lexer::SourcePosition &pos) { ASSERT(var->Declaration()->Node()->IsTSTypeParameter()); if ((var->Declaration()->Node()->AsTSTypeParameter()->Parent()->Parent()->IsClassDefinition() || @@ -979,7 +918,7 @@ std::vector ETSChecker::GetNameForSynteticObjectType(const uti void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *module_obj_type, const util::StringView &import_path) { - auto *ets_binder = static_cast(VarBinder()); + auto *ets_binder = static_cast(Binder()); auto res = ets_binder->GetGlobalRecordTable()->Program()->ExternalSources().find(import_path); @@ -1009,7 +948,7 @@ void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *module_obj void ETSChecker::SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *module_obj_type) { - auto *ets_binder = static_cast(VarBinder()); + auto *ets_binder = static_cast(Binder()); for (auto [bindingName, var] : ets_binder->TopScope()->Bindings()) { if (bindingName.Is(local->Name().Mutf8())) { @@ -1020,6 +959,7 @@ void ETSChecker::SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjec Type *ETSChecker::GetReferencedTypeFromBase([[maybe_unused]] Type *base_type, [[maybe_unused]] ir::Expression *name) { + // TODO(user): return nullptr; } @@ -1032,8 +972,8 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) ASSERT(name->IsIdentifier() && name->AsIdentifier()->Variable() != nullptr); - // NOTE: kbaladurin. forbid usage imported entities as types without declarations - auto *import_data = VarBinder()->AsETSBinder()->DynamicImportDataForVar(name->AsIdentifier()->Variable()); + // TODO(kbaladurin): forbid usage imported entities as types without declarations + auto *import_data = Binder()->AsETSBinder()->DynamicImportDataForVar(name->AsIdentifier()->Variable()); if (import_data != nullptr && import_data->import->IsPureDynamic()) { return GlobalBuiltinDynamicType(import_data->import->Language()); } @@ -1276,10 +1216,15 @@ const ir::AstNode *ETSChecker::FindJumpTarget(ir::AstNodeType node_type, const i while (iter != nullptr) { switch (iter->Type()) { case ir::AstNodeType::LABELLED_STATEMENT: { - if (const auto *labelled = iter->AsLabelledStatement(); labelled->Ident()->Name() == target->Name()) { - return node_type == ir::AstNodeType::CONTINUE_STATEMENT ? labelled->GetReferencedStatement() - : labelled; + const auto *labelled = iter->AsLabelledStatement(); + if (labelled->Ident()->Name() == target->Name()) { + if (node_type == ir::AstNodeType::CONTINUE_STATEMENT) { + return labelled->GetReferencedStatement(); + } + + return labelled; } + break; } case ir::AstNodeType::DO_WHILE_STATEMENT: @@ -1304,17 +1249,17 @@ const ir::AstNode *ETSChecker::FindJumpTarget(ir::AstNodeType node_type, const i return nullptr; } -varbinder::VariableFlags ETSChecker::GetAccessFlagFromNode(const ir::AstNode *node) +binder::VariableFlags ETSChecker::GetAccessFlagFromNode(const ir::AstNode *node) { if (node->IsPrivate()) { - return varbinder::VariableFlags::PRIVATE; + return binder::VariableFlags::PRIVATE; } if (node->IsProtected()) { - return varbinder::VariableFlags::PROTECTED; + return binder::VariableFlags::PROTECTED; } - return varbinder::VariableFlags::PUBLIC; + return binder::VariableFlags::PUBLIC; } void ETSChecker::CheckSwitchDiscriminant(ir::Expression *discriminant) @@ -1364,27 +1309,6 @@ Type *ETSChecker::ETSBuiltinTypeAsPrimitiveType(Type *object_type) return converter.Result(); } -Type *ETSChecker::ETSBuiltinTypeAsConditionalType(Type *object_type) -{ - if ((object_type == nullptr) || !object_type->IsConditionalExprType()) { - return nullptr; - } - - if (object_type->IsETSObjectType()) { - if (!object_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { - return object_type; - } - auto saved_result = Relation()->IsTrue(); - Relation()->Result(false); - - UnboxingConverter converter = UnboxingConverter(AsETSChecker(), Relation(), object_type, object_type); - Relation()->Result(saved_result); - return converter.Result(); - } - - return object_type; -} - Type *ETSChecker::PrimitiveTypeAsETSBuiltinType(Type *object_type) { if (object_type == nullptr) { @@ -1484,10 +1408,10 @@ ir::BoxingUnboxingFlags ETSChecker::GetUnboxingFlag(Type *unboxing_type) } } -Type *ETSChecker::MaybeBoxedType(const varbinder::Variable *var, ArenaAllocator *allocator) const +Type *ETSChecker::MaybeBoxedType(const binder::Variable *var, ArenaAllocator *allocator) const { auto *var_type = var->TsType(); - if (var->HasFlag(varbinder::VariableFlags::BOXED)) { + if (var->HasFlag(binder::VariableFlags::BOXED)) { switch (TypeKind(var_type)) { case TypeFlag::ETS_BOOLEAN: return GetGlobalTypesHolder()->GlobalBooleanBoxBuiltinType(); @@ -1519,13 +1443,6 @@ Type *ETSChecker::MaybeBoxedType(const varbinder::Variable *var, ArenaAllocator void ETSChecker::CheckForSameSwitchCases(ArenaVector *cases) { - // Just to avoid extra nesting level - auto const check_enum_type = [this](ir::Expression const *const case_test, ETSEnumType const *const type) -> void { - if (case_test->TsType()->AsETSEnumType()->IsSameEnumLiteralType(type)) { - ThrowTypeError("Case duplicate", case_test->Start()); - } - }; - for (size_t case_num = 0; case_num < cases->size(); case_num++) { for (size_t compare_case = case_num + 1; compare_case < cases->size(); compare_case++) { auto *case_test = cases->at(case_num)->Test(); @@ -1536,8 +1453,12 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector } if (case_test->TsType()->IsETSEnumType()) { - check_enum_type(case_test, compare_case_test->TsType()->AsETSEnumType()); - continue; + if (!case_test->TsType()->AsETSEnumType()->IsSameEnumLiteralType( + compare_case_test->TsType()->AsETSEnumType())) { + continue; + } + + ThrowTypeError("Case duplicate", case_test->Start()); } if (case_test->IsIdentifier() || case_test->IsMemberExpression()) { @@ -1579,8 +1500,8 @@ std::string ETSChecker::GetStringFromIdentifierValue(checker::Type *case_type) c return std::to_string(case_type->AsLongType()->GetValue()); } case TypeFlag::ETS_OBJECT: { - VarBinder()->ThrowError(case_type->AsETSObjectType()->Variable()->Declaration()->Node()->Start(), - "not implemented"); + Binder()->ThrowError(case_type->AsETSObjectType()->Variable()->Declaration()->Node()->Start(), + "not implemented"); } default: { UNREACHABLE(); @@ -1644,16 +1565,16 @@ std::string ETSChecker::GetStringFromLiteral(ir::Expression *case_test) const } } -bool ETSChecker::IsSameDeclarationType(varbinder::LocalVariable *target, varbinder::LocalVariable *compare) +bool ETSChecker::IsSameDeclarationType(binder::LocalVariable *target, binder::LocalVariable *compare) { if (target->Declaration()->Type() != compare->Declaration()->Type()) { return false; } - if ((target->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE) && - !compare->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) || - (!target->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE) && - compare->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE))) { + if ((target->HasFlag(binder::VariableFlags::METHOD_REFERENCE) && + !compare->HasFlag(binder::VariableFlags::METHOD_REFERENCE)) || + (!target->HasFlag(binder::VariableFlags::METHOD_REFERENCE) && + compare->HasFlag(binder::VariableFlags::METHOD_REFERENCE))) { return false; } @@ -2194,7 +2115,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons if (instantiate_method != nullptr) { std::string implicit_instantiate_argument = "()=>{return new " + std::string(class_name) + "()}"; - parser::Program program(Allocator(), VarBinder()); + parser::Program program(Allocator(), Binder()); 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); @@ -2202,7 +2123,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons arg_expr->SetParent(call_expr); arg_expr->SetRange(ident->Range()); - VarBinder()->AsETSBinder()->HandleCustomNodes(arg_expr); + Binder()->AsETSBinder()->HandleCustomNodes(arg_expr); auto &arguments = call_expr->Arguments(); arguments.insert(arguments.begin(), arg_expr); diff --git a/ets2panda/checker/ets/narrowingConverter.cpp b/ets2panda/checker/ets/narrowingConverter.cpp index 2ad286385304b5a4e2f220bf3e11148535f92805..cb70ab143ed4efd4cf76405ee2732521525a7ac8 100644 --- a/ets2panda/checker/ets/narrowingConverter.cpp +++ b/ets2panda/checker/ets/narrowingConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/narrowingConverter.h b/ets2panda/checker/ets/narrowingConverter.h index 7c2edddfd6bf2838881a0b41a69c6ebf3d139875..baadfa9f3fc59c762ebfda0f0b3c993612e7b3e9 100644 --- a/ets2panda/checker/ets/narrowingConverter.h +++ b/ets2panda/checker/ets/narrowingConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/narrowingWideningConverter.cpp b/ets2panda/checker/ets/narrowingWideningConverter.cpp index 8a037b0301a3df3a550d2082816e5cbaf414ca68..f79174d7f9089fee948a549982ce448c75f9ce39 100644 --- a/ets2panda/checker/ets/narrowingWideningConverter.cpp +++ b/ets2panda/checker/ets/narrowingWideningConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/narrowingWideningConverter.h b/ets2panda/checker/ets/narrowingWideningConverter.h index c6e16aceabf884a57cccfec89e3875ebfd80679a..05b3134078d6e1b363c9b2b7543ea95634352f70 100644 --- a/ets2panda/checker/ets/narrowingWideningConverter.h +++ b/ets2panda/checker/ets/narrowingWideningConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9732a6e26681798d65e87d4991aedb58b783e33d..64a00e06397c3213ac3f995018a0df0d7a160e8d 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" #include "ir/typeNode.h" @@ -45,10 +45,10 @@ #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" #include "ir/ets/etsNewClassInstanceExpression.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" -#include "varbinder/ETSBinder.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" +#include "binder/ETSBinder.h" #include "checker/ETSchecker.h" #include "checker/types/typeFlag.h" #include "checker/types/ets/etsDynamicType.h" @@ -209,9 +209,7 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) param->Constraint()->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name(); const auto *const type_param_scope = param->Parent()->AsTSTypeParameterDeclaration()->Scope(); - if (auto *const found_param = - type_param_scope->FindLocal(constraint_name, varbinder::ResolveBindingOptions::BINDINGS); - found_param != nullptr) { + if (auto *const found_param = type_param_scope->FindLocal(constraint_name); found_param != nullptr) { CreateTypeParameterType(found_param->Declaration()->Node()->AsTSTypeParameter()); } } @@ -362,9 +360,9 @@ void ETSChecker::ResolveDeclaredMembersOfObject(ETSObjectType *type) } auto *decl_node = type->GetDeclNode(); - varbinder::ClassScope *scope = decl_node->IsTSInterfaceDeclaration() - ? decl_node->AsTSInterfaceDeclaration()->Scope()->AsClassScope() - : decl_node->AsClassDefinition()->Scope()->AsClassScope(); + binder::ClassScope *scope = decl_node->IsTSInterfaceDeclaration() + ? decl_node->AsTSInterfaceDeclaration()->Scope()->AsClassScope() + : decl_node->AsClassDefinition()->Scope()->AsClassScope(); for (auto &[_, it] : scope->InstanceFieldScope()->Bindings()) { (void)_; @@ -375,7 +373,7 @@ void ETSChecker::ResolveDeclaredMembersOfObject(ETSObjectType *type) if (class_prop->TypeAnnotation() != nullptr && class_prop->TypeAnnotation()->IsETSFunctionType()) { type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); + it->AddFlag(binder::VariableFlags::METHOD_REFERENCE); } } @@ -388,7 +386,7 @@ void ETSChecker::ResolveDeclaredMembersOfObject(ETSObjectType *type) if (class_prop->TypeAnnotation() != nullptr && class_prop->TypeAnnotation()->IsETSFunctionType()) { type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); + it->AddFlag(binder::VariableFlags::METHOD_REFERENCE); } } @@ -587,30 +585,26 @@ void ETSChecker::ValidateOverriding(ETSObjectType *class_type, const lexer::Sour bool found_signature = false; for (auto *const implemented : implemented_signatures) { Signature *subst_implemented = AdjustForTypeParameters(*abstract_signature, implemented); - if (subst_implemented == nullptr) { continue; } + if (AreOverrideEquivalent(*abstract_signature, subst_implemented) && + IsReturnTypeSubstitutable(subst_implemented, *abstract_signature)) { + if (!implemented->Function()->IsOverride() && (implemented->Owner() == class_type)) { + ThrowTypeError("Method overriding is only allowed with 'override' modifier", + implemented->Function()->Start()); + } - if (!AreOverrideEquivalent(*abstract_signature, subst_implemented) || - !IsReturnTypeSubstitutable(subst_implemented, *abstract_signature)) { - continue; - } - - if (!implemented->Function()->IsOverride() && (implemented->Owner() == class_type)) { - ThrowTypeError("Method overriding is only allowed with 'override' modifier", - implemented->Function()->Start()); - } + if ((*it)->CallSignatures().size() > 1) { + abstract_signature = (*it)->CallSignatures().erase(abstract_signature); + found_signature = true; + } else { + it = abstracts_to_be_implemented.erase(it); + function_overridden = true; + } - if ((*it)->CallSignatures().size() > 1) { - abstract_signature = (*it)->CallSignatures().erase(abstract_signature); - found_signature = true; - } else { - it = abstracts_to_be_implemented.erase(it); - function_overridden = true; + break; } - - break; } if (function_overridden) { @@ -639,7 +633,7 @@ void ETSChecker::ValidateOverriding(ETSObjectType *class_type, const lexer::Sour } void ETSChecker::AddImplementedSignature(std::vector *implemented_signatures, - varbinder::LocalVariable *function, ETSFunctionType *it) + binder::LocalVariable *function, ETSFunctionType *it) { if (!function->TsType()->IsETSFunctionType()) { return; @@ -785,14 +779,14 @@ void ETSChecker::CheckImplicitSuper(ETSObjectType *class_type, Signature *ctor_s void ETSChecker::CheckConstFields(const ETSObjectType *class_type) { for (const auto &prop : class_type->Fields()) { - if (!prop->Declaration()->IsConstDecl() || !prop->HasFlag(varbinder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { + if (!prop->Declaration()->IsConstDecl() || !prop->HasFlag(binder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { continue; } CheckConstFieldInitialized(class_type, prop); } } -void ETSChecker::CheckConstFieldInitialized(const ETSObjectType *class_type, varbinder::LocalVariable *class_var) +void ETSChecker::CheckConstFieldInitialized(const ETSObjectType *class_type, binder::LocalVariable *class_var) { const bool class_var_static = class_var->Declaration()->Node()->AsClassProperty()->IsStatic(); for (const auto &prop : class_type->Methods()) { @@ -806,7 +800,7 @@ void ETSChecker::CheckConstFieldInitialized(const ETSObjectType *class_type, var } } -void ETSChecker::FindAssignment(const ir::AstNode *node, const varbinder::LocalVariable *class_var, bool &initialized) +void ETSChecker::FindAssignment(const ir::AstNode *node, const binder::LocalVariable *class_var, bool &initialized) { if (node->IsAssignmentExpression() && node->AsAssignmentExpression()->Target() == class_var) { if (initialized) { @@ -821,14 +815,14 @@ void ETSChecker::FindAssignment(const ir::AstNode *node, const varbinder::LocalV FindAssignments(node, class_var, initialized); } -void ETSChecker::FindAssignments(const ir::AstNode *node, const varbinder::LocalVariable *class_var, bool &initialized) +void ETSChecker::FindAssignments(const ir::AstNode *node, const binder::LocalVariable *class_var, bool &initialized) { node->Iterate([this, class_var, &initialized](ir::AstNode *child_node) { FindAssignment(child_node, class_var, initialized); }); } -void ETSChecker::CheckConstFieldInitialized(const Signature *signature, varbinder::LocalVariable *class_var) +void ETSChecker::CheckConstFieldInitialized(const Signature *signature, binder::LocalVariable *class_var) { bool initialized = false; const auto &stmts = signature->Function()->Body()->AsBlockStatement()->Statements(); @@ -842,14 +836,14 @@ void ETSChecker::CheckConstFieldInitialized(const Signature *signature, varbinde } } - // NOTE: szd. control flow + // TODO(szd) control flow FindAssignments(signature->Function()->Body(), class_var, initialized); if (!initialized) { ThrowTypeError({"Variable '", class_var->Declaration()->Name(), "' might not have been initialized"}, signature->Function()->End()); } - class_var->RemoveFlag(varbinder::VariableFlags::EXPLICIT_INIT_REQUIRED); + class_var->RemoveFlag(binder::VariableFlags::EXPLICIT_INIT_REQUIRED); } void ETSChecker::CheckInnerClassMembers(const ETSObjectType *class_type) @@ -911,7 +905,7 @@ Type *ETSChecker::CheckArrayElementAccess(ir::MemberExpression *expr) expr->SetPropVar(var->AsLocalVariable()); } - // NOTE: apply capture conversion on this type + // TODO(user): apply capture conversion on this type if (array_type->IsETSArrayType()) { return array_type->AsETSArrayType()->ElementType(); } @@ -996,7 +990,7 @@ ETSObjectType *ETSChecker::CheckExceptionOrErrorType(checker::Type *type, const Type *ETSChecker::TryToInstantiate(Type *const type, ArenaAllocator *const allocator, TypeRelation *const relation, GlobalTypesHolder *const global_types) { - // NOTE: Handle generic functions + // TODO(user): Handle generic functions auto *return_type = type; const bool is_incomplete = type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::INCOMPLETE_INSTANTIATION); @@ -1007,7 +1001,7 @@ Type *ETSChecker::TryToInstantiate(Type *const type, ArenaAllocator *const alloc return return_type; } -void ETSChecker::ValidateResolvedProperty(const varbinder::LocalVariable *const property, +void ETSChecker::ValidateResolvedProperty(const binder::LocalVariable *const property, const ETSObjectType *const target, const ir::Identifier *const ident, const PropertySearchFlags flags) { @@ -1040,11 +1034,11 @@ void ETSChecker::ValidateResolvedProperty(const varbinder::LocalVariable *const } } -varbinder::Variable *ETSChecker::ResolveInstanceExtension(const ir::MemberExpression *const member_expr) +binder::Variable *ETSChecker::ResolveInstanceExtension(const ir::MemberExpression *const member_expr) { auto *global_function_var = Scope() ->FindInGlobal(member_expr->Property()->AsIdentifier()->Name(), - varbinder::ResolveBindingOptions::STATIC_METHODS) + binder::ResolveBindingOptions::STATIC_METHODS) .variable; if (global_function_var == nullptr || !ExtensionETSFunctionType(this->GetTypeOfVariable(global_function_var))) { @@ -1062,7 +1056,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member if (target->IsETSDynamicType() && !target->AsETSDynamicType()->HasDecl()) { auto prop_name = member_expr->Property()->AsIdentifier()->Name(); - varbinder::LocalVariable *prop_var = target->AsETSDynamicType()->GetPropertyDynamic(prop_name, this); + binder::LocalVariable *prop_var = target->AsETSDynamicType()->GetPropertyDynamic(prop_name, this); resolve_res.emplace_back(Allocator()->New(prop_var, ResolvedKind::PROPERTY)); return resolve_res; } @@ -1123,7 +1117,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member }(); search_flag |= PropertySearchFlags::SEARCH_IN_BASE | PropertySearchFlags::SEARCH_IN_INTERFACES; - const auto *const target_ref = [member_expr]() -> const varbinder::Variable * { + const auto *const target_ref = [member_expr]() -> const binder::Variable * { if (member_expr->Object()->IsIdentifier()) { return member_expr->Object()->AsIdentifier()->Variable(); } @@ -1133,7 +1127,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member return nullptr; }(); - if (target_ref != nullptr && target_ref->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + if (target_ref != nullptr && target_ref->HasFlag(binder::VariableFlags::CLASS_OR_INTERFACE)) { search_flag &= ~(PropertySearchFlags::SEARCH_INSTANCE); } else if (member_expr->Object()->IsThisExpression() || (member_expr->Object()->IsIdentifier() && member_expr->ObjType()->GetDeclNode() != nullptr && @@ -1146,7 +1140,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member } auto *const prop = target->GetProperty(member_expr->Property()->AsIdentifier()->Name(), search_flag); - varbinder::Variable *global_function_var = nullptr; + binder::Variable *global_function_var = nullptr; if (member_expr->Parent()->IsCallExpression() && member_expr->Parent()->AsCallExpression()->Callee() == member_expr) { @@ -1154,7 +1148,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member } if (global_function_var == nullptr || - (target_ref != nullptr && target_ref->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE))) { + (target_ref != nullptr && target_ref->HasFlag(binder::VariableFlags::CLASS_OR_INTERFACE))) { /* Instance extension function can only be called by class instance, if a property is accessed by CLASS or INTERFACE type, it couldn't be an instance extension function call @@ -1181,7 +1175,7 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member resolve_res.emplace_back(Allocator()->New(prop, ResolvedKind::PROPERTY)); - if (prop->HasFlag(varbinder::VariableFlags::METHOD) && !IsVariableGetterSetter(prop) && + if (prop->HasFlag(binder::VariableFlags::METHOD) && !IsVariableGetterSetter(prop) && (search_flag & PropertySearchFlags::IS_FUNCTIONAL) == 0) { ThrowTypeError("Method used in wrong context", member_expr->Property()->Start()); } @@ -1274,13 +1268,13 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *class_type, ir::ClassDefin if (!IsSameDeclarationType(it, found)) { const char *target_type {}; - if (it->HasFlag(varbinder::VariableFlags::PROPERTY)) { + if (it->HasFlag(binder::VariableFlags::PROPERTY)) { target_type = "field"; - } else if (it->HasFlag(varbinder::VariableFlags::METHOD)) { + } else if (it->HasFlag(binder::VariableFlags::METHOD)) { target_type = "method"; - } else if (it->HasFlag(varbinder::VariableFlags::CLASS)) { + } else if (it->HasFlag(binder::VariableFlags::CLASS)) { target_type = "class"; - } else if (it->HasFlag(varbinder::VariableFlags::INTERFACE)) { + } else if (it->HasFlag(binder::VariableFlags::INTERFACE)) { target_type = "interface"; } else { target_type = "enum"; @@ -1295,7 +1289,7 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *class_type, ir::ClassDefin void ETSChecker::CheckGetterSetterProperties(ETSObjectType *class_type) { - auto const check_getter_setter = [this](varbinder::LocalVariable *var, util::StringView name) { + auto const check_getter_setter = [this](binder::LocalVariable *var, util::StringView name) { auto const *type = var->TsType()->AsETSFunctionType(); auto const *sig_getter = type->FindGetter(); auto const *sig_setter = type->FindSetter(); @@ -1332,14 +1326,14 @@ void ETSChecker::CheckGetterSetterProperties(ETSObjectType *class_type) void ETSChecker::AddElementsToModuleObject(ETSObjectType *module_obj, const util::StringView &str) { - for (const auto &[name, var] : VarBinder()->GetScope()->Bindings()) { + for (const auto &[name, var] : Binder()->GetScope()->Bindings()) { if (name.Is(str.Mutf8()) || name.Is(compiler::Signatures::ETS_GLOBAL)) { continue; } - if (var->HasFlag(varbinder::VariableFlags::METHOD)) { + if (var->HasFlag(binder::VariableFlags::METHOD)) { module_obj->AddProperty(var->AsLocalVariable()); - } else if (var->HasFlag(varbinder::VariableFlags::PROPERTY)) { + } else if (var->HasFlag(binder::VariableFlags::PROPERTY)) { module_obj->AddProperty(var->AsLocalVariable()); } else { module_obj->AddProperty(var->AsLocalVariable()); @@ -1417,7 +1411,7 @@ ETSObjectType *ETSChecker::GetClosestCommonAncestor(ETSObjectType *source, ETSOb target_type->IsSupertypeOf(Relation(), source_type); if (Relation()->IsTrue()) { - // NOTE: TorokG. Extending the search to find intersection types + // TODO(TorokG): Extending the search to find intersection types return target_type; } diff --git a/ets2panda/checker/ets/primitiveWrappers.cpp b/ets2panda/checker/ets/primitiveWrappers.cpp index 4f9c6b68b015d750b861e429566be3eba68e5c57..fba7f28ccf9125aabd3b3f5e612a050e98bb5970 100644 --- a/ets2panda/checker/ets/primitiveWrappers.cpp +++ b/ets2panda/checker/ets/primitiveWrappers.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/checker/ets/typeConverter.cpp b/ets2panda/checker/ets/typeConverter.cpp index b648c168178fc42c6c6588bbc9cc330253207501..dc32dee4b15f784ac2b501e326b7574d312a6415 100644 --- a/ets2panda/checker/ets/typeConverter.cpp +++ b/ets2panda/checker/ets/typeConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/checker/ets/typeConverter.h b/ets2panda/checker/ets/typeConverter.h index 0c3289a85f4fbe5bd8a499482dbad4cb6aa8bc8b..2c750ae2ddc3346e87f8b6041b4f9e38b1c060cb 100644 --- a/ets2panda/checker/ets/typeConverter.h +++ b/ets2panda/checker/ets/typeConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 454e980ac232f2a443f7fbc6c6c1bb00b0ad4492..f4314b693181b0198cdb3b6ea0b98aa1e4a02387 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -16,8 +16,8 @@ #include "generated/signatures.h" #include "checker/ETSchecker.h" #include "checker/types/ets/etsDynamicFunctionType.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" +#include "binder/binder.h" +#include "binder/ETSBinder.h" #include "ir/ets/etsScript.h" #include "ir/base/classDefinition.h" #include "ir/base/scriptFunction.h" @@ -114,35 +114,6 @@ ETSArrayType *ETSChecker::CreateETSArrayType(Type *element_type) return array_type; } -Type *ETSChecker::CreateETSUnionType(ArenaVector &&constituent_types) -{ - if (constituent_types.empty()) { - return nullptr; - } - - ArenaVector new_constituent_types(Allocator()->Adapter()); - - for (auto *it : constituent_types) { - if (it->IsUnionType()) { - for (auto *type : it->AsETSUnionType()->ConstituentTypes()) { - new_constituent_types.push_back(type); - } - - continue; - } - - new_constituent_types.push_back(it); - } - - if (new_constituent_types.size() == 1) { - return new_constituent_types[0]; - } - - auto *new_union_type = Allocator()->New(std::move(new_constituent_types)); - - return ETSUnionType::HandleUnionType(new_union_type); -} - ETSFunctionType *ETSChecker::CreateETSFunctionType(ArenaVector &signatures) { auto *func_type = Allocator()->New(signatures[0]->Function()->Id()->Name(), Allocator()); @@ -325,7 +296,7 @@ ETSObjectType *ETSChecker::CreateETSObjectType(util::StringView name, ir::AstNod ETSEnumType *ETSChecker::CreateETSEnumType(ir::TSEnumDeclaration const *const enum_decl) { - varbinder::Variable *enum_var = enum_decl->Key()->Variable(); + binder::Variable *enum_var = enum_decl->Key()->Variable(); ASSERT(enum_var != nullptr); ETSEnumType::UType ordinal = -1; @@ -379,7 +350,7 @@ ETSEnumType *ETSChecker::CreateETSEnumType(ir::TSEnumDeclaration const *const en ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration const *const enum_decl) { - varbinder::Variable *enum_var = enum_decl->Key()->Variable(); + binder::Variable *enum_var = enum_decl->Key()->Variable(); ASSERT(enum_var != nullptr); ETSEnumType::UType ordinal = -1; @@ -438,7 +409,7 @@ ETSObjectType *ETSChecker::CreateNewETSObjectType(util::StringView name, ir::Ast if (containing_obj_type != nullptr) { prefix = containing_obj_type->AssemblerName(); } else if (decl_node->GetTopStatement()->Type() != - ir::AstNodeType::BLOCK_STATEMENT) { // NOTE: should not occur, fix for TS_INTERFACE_DECLARATION + ir::AstNodeType::BLOCK_STATEMENT) { // TODO(): should not occur, fix for TS_INTERFACE_DECLARATION ASSERT(decl_node->IsTSInterfaceDeclaration()); assembler_name = decl_node->AsTSInterfaceDeclaration()->InternalName(); } else { @@ -493,8 +464,7 @@ std::tuple ETSChecker::CreateBuiltinArraySign for (size_t i = 0; i < dim; i++) { util::UString param(std::to_string(i), Allocator()); - auto *param_var = - varbinder::Scope::CreateVar(Allocator(), param.View(), varbinder::VariableFlags::NONE, nullptr); + auto *param_var = binder::Scope::CreateVar(Allocator(), param.View(), binder::VariableFlags::NONE, nullptr); param_var->SetTsType(GlobalIntType()); info->params.push_back(param_var); diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index 2f56a4c41cca4cfd0fa88b458ea2f3c39eefd5a1..8ba09ba64645597e2665275b0d1bb908613cbe8d 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -14,9 +14,9 @@ */ #include "typeRelationContext.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" #include "ir/expressions/arrayExpression.h" #include "ir/expressions/identifier.h" #include "ir/ts/tsArrayType.h" @@ -69,46 +69,31 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType continue; } - 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(); - assignable = - std::all_of(constituent_types.begin(), constituent_types.end(), [this, constraint_type](Type *c_type) { - return c_type->IsETSObjectType() && - ValidateTypeArg(constraint_type->AsETSObjectType(), c_type->AsETSObjectType()); - }); - } + auto *constraint_type = type_param_constraint->GetType(checker_)->AsETSObjectType(); + auto *arg_ref_type = param_type->AsETSObjectType(); - if (!assignable) { - checker_->ThrowTypeError({"Type '", param_type->AsETSObjectType(), - "' is not assignable to constraint type '", constraint_type, "'."}, - type_args->Params().at(type_param_iter)->Start()); + if (const auto *const found = checker_->AsETSChecker()->Scope()->FindLocal( + constraint_type->Name(), binder::ResolveBindingOptions::TYPE_ALIASES); + found != nullptr) { + arg_ref_type = found->TsType()->AsETSObjectType(); } - } - return false; -} - -bool InstantiationContext::ValidateTypeArg(ETSObjectType *constraint_type, ETSObjectType *arg_ref_type) -{ - if (const auto *const found = checker_->AsETSChecker()->Scope()->FindLocal( - constraint_type->Name(), varbinder::ResolveBindingOptions::TYPE_ALIASES); - found != nullptr) { - arg_ref_type = found->TsType()->AsETSObjectType(); - } + auto assignable = checker_->Relation()->IsAssignableTo(arg_ref_type, constraint_type); + if (constraint_type->HasObjectFlag(ETSObjectFlags::INTERFACE)) { + for (const auto *const interface : arg_ref_type->Interfaces()) { + // TODO(mmartin): make correct check later for multiple bounds + assignable = (interface == constraint_type) || assignable; + } + } - auto assignable = checker_->Relation()->IsAssignableTo(arg_ref_type, constraint_type); - if (constraint_type->HasObjectFlag(ETSObjectFlags::INTERFACE)) { - for (const auto *const interface : arg_ref_type->Interfaces()) { - // NOTE: mmartin. make correct check later for multiple bounds - assignable = (interface == constraint_type) || assignable; + if (!assignable) { + checker_->ThrowTypeError( + {"Type '", arg_ref_type, "' is not assignable to constraint type '", constraint_type, "'."}, + type_args->Params().at(type_param_iter)->Start()); } } - return assignable; + return false; } void InstantiationContext::InstantiateType(ETSObjectType *type, ir::TSTypeParameterInstantiation *type_args) @@ -147,18 +132,7 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ArenaVectorNewSubstitution(); 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); - }); - } else { - is_compatible_type_arg = checker_->IsCompatibleTypeArgument(type_param, type_arg_types[ix]); - } - if (!is_compatible_type_arg) { + if (!checker_->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix])) { checker_->ThrowTypeError( {"Type ", type_arg_types[ix], " is not assignable to", " type parameter ", type_params[ix]}, pos); } diff --git a/ets2panda/checker/ets/typeRelationContext.h b/ets2panda/checker/ets/typeRelationContext.h index 2cedf02fa1f8248e5bfd0bc5653d5b73eef32d6a..c2d48bf63d70027b1397f0d7f8b48370dba13494 100644 --- a/ets2panda/checker/ets/typeRelationContext.h +++ b/ets2panda/checker/ets/typeRelationContext.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -173,9 +173,6 @@ public: private: bool ValidateTypeArguments(ETSObjectType *type, ir::TSTypeParameterDeclaration *type_param_decl, ir::TSTypeParameterInstantiation *type_args, const lexer::SourcePosition &pos); - - bool ValidateTypeArg(ETSObjectType *constraint_type, ETSObjectType *arg_ref_type); - void InstantiateType(ETSObjectType *type, ir::TSTypeParameterInstantiation *type_args); void InstantiateType(ETSObjectType *type, ArenaVector &type_arg_types, const lexer::SourcePosition &pos); diff --git a/ets2panda/checker/ets/unboxingConverter.cpp b/ets2panda/checker/ets/unboxingConverter.cpp index 4f378a6d96f28c24ebddbda23d75367de6082336..3ab5b7bf5bcf341432c0e2c51e29a102f12fe7c2 100644 --- a/ets2panda/checker/ets/unboxingConverter.cpp +++ b/ets2panda/checker/ets/unboxingConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/unboxingConverter.h b/ets2panda/checker/ets/unboxingConverter.h index f18fe678dd8f6e2f86184bd44a58111a62095c93..da5c365a4eaad337df7f673084b3a55701936298 100644 --- a/ets2panda/checker/ets/unboxingConverter.h +++ b/ets2panda/checker/ets/unboxingConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/wideningConverter.cpp b/ets2panda/checker/ets/wideningConverter.cpp index ac7ef8579e6c7cb50abf7098a57a6367c7189fa0..0c7e36c5d74c40f2a85a9cf1679ba847c909811a 100644 --- a/ets2panda/checker/ets/wideningConverter.cpp +++ b/ets2panda/checker/ets/wideningConverter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/ets/wideningConverter.h b/ets2panda/checker/ets/wideningConverter.h index aa254771ce567648ff67417293080655d0cab855..1121deb80a396fcc5d289b8d419bc17c27e6ef35 100644 --- a/ets2panda/checker/ets/wideningConverter.h +++ b/ets2panda/checker/ets/wideningConverter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/resolveResult.h b/ets2panda/checker/resolveResult.h deleted file mode 100644 index 84844d29197a87fc5b49fc46a304115fc0a8d10c..0000000000000000000000000000000000000000 --- a/ets2panda/checker/resolveResult.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2021 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_CHECKER_RESOLVE_RESULT_H -#define ES2PANDA_CHECKER_RESOLVE_RESULT_H - -namespace panda::es2panda::checker { -enum class OverrideErrorCode { - NO_ERROR, - OVERRIDING_STATIC, - OVERRIDDEN_STATIC, - OVERRIDDEN_FINAL, - INCOMPATIBLE_RETURN, - OVERRIDDEN_WEAKER, -}; - -enum class ResolvedKind { - PROPERTY, - INSTANCE_EXTENSION_FUNCTION, -}; - -class ResolveResult { -public: - explicit ResolveResult(varbinder::Variable *v, ResolvedKind kind) : variable_(v), kind_(kind) {} - - varbinder::Variable *Variable() - { - return variable_; - } - - ResolvedKind Kind() - { - return kind_; - } - -private: - varbinder::Variable *variable_ {}; - ResolvedKind kind_ {}; -}; - -} // namespace panda::es2panda::checker - -#endif /* ES2PANDA_CHECKER_RESOLVE_RESULT_H */ diff --git a/ets2panda/checker/ts/binaryLikeExpression.cpp b/ets2panda/checker/ts/binaryLikeExpression.cpp index 2141312b4ddc535120dde2d60378b0fe3036d103..e37138b45ff810c18011a3b584574fbf0ff2a540 100644 --- a/ets2panda/checker/ts/binaryLikeExpression.cpp +++ b/ets2panda/checker/ts/binaryLikeExpression.cpp @@ -157,7 +157,7 @@ Type *TSChecker::CheckOrOperator(Type *left_type, Type *right_type, ir::Expressi CheckTruthinessOfType(left_type, left_expr->Start()); if ((static_cast(left_type->GetTypeFacts()) & static_cast(TypeFacts::FALSY)) != 0U) { - // NOTE: aszilagyi. subtype reduction in the result union + // TODO(aszilagyi): subtype reduction in the result union Type *result_type = CreateUnionType({RemoveDefinitelyFalsyTypes(left_type), right_type}); return result_type; } @@ -180,7 +180,7 @@ Type *TSChecker::CheckInstanceofExpression(Type *left_type, Type *right_type, ir expr->Start()); } - // NOTE: aszilagyi. Check if right type is subtype of globalFunctionType + // TODO(aszilagyi): Check if right type is subtype of globalFunctionType if (right_type->TypeFlags() != TypeFlag::ANY && !TypeHasCallOrConstructSignatures(right_type)) { ThrowTypeError({"The right-hand side of an 'instanceof' expression must be of type 'any'", " or of a type assignable to the 'Function' interface type."}, @@ -196,14 +196,14 @@ Type *TSChecker::CheckInExpression(Type *left_type, Type *right_type, ir::Expres CheckNonNullType(left_type, left_expr->Start()); CheckNonNullType(right_type, right_expr->Start()); - // NOTE: aszilagyi. Check IsAllTypesAssignableTo with ESSymbol too + // TODO(aszilagyi): Check IsAllTypesAssignableTo with ESSymbol too if (left_type->TypeFlags() != TypeFlag::ANY && !IsAllTypesAssignableTo(left_type, GlobalStringOrNumberType())) { ThrowTypeError( {"The left-hand side of an 'in' expression must be of type 'any',", " 'string', 'number', or 'symbol'."}, expr->Start()); } - // NOTE: aszilagyi. Handle type parameters + // TODO(aszilagyi): Handle type parameters if (!IsAllTypesAssignableTo(right_type, GlobalNonPrimitiveType())) { ThrowTypeError("The right-hand side of an 'in' expression must not be a primitive.", right_expr->Start()); } diff --git a/ets2panda/checker/ts/destructuringContext.cpp b/ets2panda/checker/ts/destructuringContext.cpp index 9357aaf0781834d330ce9609daa5247ab9015c5e..2dfb91928b05958d7dbdcdc7161b00e9a1a63b41 100644 --- a/ets2panda/checker/ts/destructuringContext.cpp +++ b/ets2panda/checker/ts/destructuringContext.cpp @@ -16,7 +16,7 @@ #include "destructuringContext.h" #include "util/helpers.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/typeNode.h" #include "ir/expressions/identifier.h" #include "ir/expressions/objectExpression.h" @@ -58,7 +58,7 @@ void DestructuringContext::HandleDestructuringAssignment(ir::Identifier *ident, checker_->ThrowTypeError({"Cannot find name '", ident->Name(), "'."}, ident->Start()); } - varbinder::Variable *variable = ident->Variable(); + binder::Variable *variable = ident->Variable(); ASSERT(variable->TsType()); if (default_type != nullptr && !checker_->IsTypeAssignableTo(default_type, variable->TsType())) { @@ -70,7 +70,7 @@ void DestructuringContext::HandleDestructuringAssignment(ir::Identifier *ident, } } -void DestructuringContext::SetInferredTypeForVariable(varbinder::Variable *var, Type *inferred_type, +void DestructuringContext::SetInferredTypeForVariable(binder::Variable *var, Type *inferred_type, const lexer::SourcePosition &loc) { ASSERT(var); @@ -212,7 +212,7 @@ void ArrayDestructuringContext::ValidateInferredType() Type *ArrayDestructuringContext::GetTypeFromTupleByIndex(TupleType *tuple) { util::StringView member_index = util::Helpers::ToStringView(checker_->Allocator(), index_); - varbinder::Variable *member_var = tuple->GetProperty(member_index, false); + binder::Variable *member_var = tuple->GetProperty(member_index, false); if (member_var == nullptr) { return nullptr; @@ -317,8 +317,8 @@ Type *ArrayDestructuringContext::CreateTupleTypeForRest(TupleType *tuple) while (tuple_element_type != nullptr) { ElementFlags member_flag = ElementFlags::REQUIRED; util::StringView member_index = util::Helpers::ToStringView(checker_->Allocator(), iter_index); - auto *member_var = varbinder::Scope::CreateVar(checker_->Allocator(), member_index, - varbinder::VariableFlags::PROPERTY, nullptr); + auto *member_var = + binder::Scope::CreateVar(checker_->Allocator(), member_index, binder::VariableFlags::PROPERTY, nullptr); member_var->SetTsType(tuple_element_type); element_flags.push_back(member_flag); desc->properties.push_back(member_var); @@ -466,7 +466,7 @@ void ArrayDestructuringContext::Start() if (convert_tuple_to_array_ && next_inferred_type != nullptr && inferred_type_->IsObjectType()) { ASSERT(inferred_type_->AsObjectType()->IsTupleType()); - varbinder::Variable *current_tuple_element = inferred_type_->AsObjectType()->Properties()[index_]; + binder::Variable *current_tuple_element = inferred_type_->AsObjectType()->Properties()[index_]; if (current_tuple_element != nullptr) { current_tuple_element->SetTsType(next_inferred_type); @@ -540,9 +540,9 @@ Type *ObjectDestructuringContext::CreateObjectTypeForRest(ObjectType *obj_type) ObjectDescriptor *desc = checker_->Allocator()->New(checker_->Allocator()); for (auto *it : obj_type->AsObjectType()->Properties()) { - if (!it->HasFlag(varbinder::VariableFlags::INFERRED_IN_PATTERN)) { + if (!it->HasFlag(binder::VariableFlags::INFERRED_IN_PATTERN)) { auto *member_var = - varbinder::Scope::CreateVar(checker_->Allocator(), it->Name(), varbinder::VariableFlags::NONE, nullptr); + binder::Scope::CreateVar(checker_->Allocator(), it->Name(), binder::VariableFlags::NONE, nullptr); member_var->SetTsType(it->TsType()); member_var->AddFlag(it->Flags()); desc->properties.push_back(member_var); @@ -611,11 +611,11 @@ Type *ObjectDestructuringContext::ConvertTupleTypeToArrayTypeIfNecessary(ir::Ast Type *ObjectDestructuringContext::NextInferredType([[maybe_unused]] const util::StringView &search_name, bool throw_error) { - varbinder::Variable *prop = checker_->GetPropertyOfType(inferred_type_, search_name, !throw_error, - varbinder::VariableFlags::INFERRED_IN_PATTERN); + binder::Variable *prop = checker_->GetPropertyOfType(inferred_type_, search_name, !throw_error, + binder::VariableFlags::INFERRED_IN_PATTERN); if (prop != nullptr) { - prop->AddFlag(varbinder::VariableFlags::INFERRED_IN_PATTERN); + prop->AddFlag(binder::VariableFlags::INFERRED_IN_PATTERN); return prop->TsType(); } @@ -649,7 +649,7 @@ void ObjectDestructuringContext::Start() ir::Property *property = it->AsProperty(); if (property->IsComputed()) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return; } diff --git a/ets2panda/checker/ts/destructuringContext.h b/ets2panda/checker/ts/destructuringContext.h index 8bcfa0115ce02d0f5f2362e6fde41b1cd26dd299..88d52d8d0c16deead617c529a24b8ca40d053849 100644 --- a/ets2panda/checker/ts/destructuringContext.h +++ b/ets2panda/checker/ts/destructuringContext.h @@ -57,7 +57,7 @@ public: void HandleDestructuringAssignment(ir::Identifier *ident, Type *inferred_type, Type *default_type); void HandleAssignmentPattern(ir::AssignmentExpression *assignment_pattern, Type *inferred_type, bool validate_default); - void SetInferredTypeForVariable(varbinder::Variable *var, Type *inferred_type, const lexer::SourcePosition &loc); + void SetInferredTypeForVariable(binder::Variable *var, Type *inferred_type, const lexer::SourcePosition &loc); void Prepare(ir::TypeNode *type_annotation, ir::Expression *initializer, const lexer::SourcePosition &loc); DEFAULT_COPY_SEMANTIC(DestructuringContext); diff --git a/ets2panda/checker/ts/function.cpp b/ets2panda/checker/ts/function.cpp index 4c6dbd932c6a66a003385792ca8ebf6359a1bc75..73d5040c8722696fe94264cc3a01dc403c0e9f35 100644 --- a/ets2panda/checker/ts/function.cpp +++ b/ets2panda/checker/ts/function.cpp @@ -29,9 +29,9 @@ #include "ir/statements/returnStatement.h" #include "ir/statements/functionDeclaration.h" #include "util/helpers.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/scope.h" +#include "binder/declaration.h" #include "checker/TSchecker.h" #include "checker/ts/destructuringContext.h" @@ -116,11 +116,11 @@ void TSChecker::ThrowReturnTypeCircularityError(ir::ScriptFunction *func) func->Start()); } -std::tuple TSChecker::CheckFunctionIdentifierParameter( +std::tuple TSChecker::CheckFunctionIdentifierParameter( ir::Identifier *param) { ASSERT(param->Variable()); - varbinder::Variable *param_var = param->Variable(); + binder::Variable *param_var = param->Variable(); bool is_optional = param->IsOptional(); if (param->TypeAnnotation() == nullptr) { @@ -128,7 +128,7 @@ std::tuple TSCheck } if (is_optional) { - param_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + param_var->AddFlag(binder::VariableFlags::OPTIONAL); } param->TypeAnnotation()->Check(this); @@ -154,9 +154,8 @@ Type *TSChecker::CreateParameterTypeForArrayAssignmentPattern(ir::ArrayExpressio for (uint32_t index = inferred_tuple->FixedLength(); index < array_pattern->Elements().size(); index++) { util::StringView member_index = util::Helpers::ToStringView(Allocator(), index); - varbinder::LocalVariable *new_member = varbinder::Scope::CreateVar( - Allocator(), member_index, varbinder::VariableFlags::PROPERTY | varbinder::VariableFlags::OPTIONAL, - nullptr); + binder::LocalVariable *new_member = binder::Scope::CreateVar( + Allocator(), member_index, binder::VariableFlags::PROPERTY | binder::VariableFlags::OPTIONAL, nullptr); new_member->SetTsType(GlobalAnyType()); new_tuple->AddProperty(new_member); } @@ -180,11 +179,11 @@ Type *TSChecker::CreateParameterTypeForObjectAssignmentPattern(ir::ObjectExpress } ir::Property *prop = it->AsProperty(); - varbinder::LocalVariable *found_var = new_object->GetProperty(prop->Key()->AsIdentifier()->Name(), true); + binder::LocalVariable *found_var = new_object->GetProperty(prop->Key()->AsIdentifier()->Name(), true); if (found_var != nullptr) { if (prop->Value()->IsAssignmentPattern()) { - found_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + found_var->AddFlag(binder::VariableFlags::OPTIONAL); } continue; @@ -193,9 +192,9 @@ Type *TSChecker::CreateParameterTypeForObjectAssignmentPattern(ir::ObjectExpress ASSERT(prop->Value()->IsAssignmentPattern()); ir::AssignmentExpression *assignment_pattern = prop->Value()->AsAssignmentPattern(); - varbinder::LocalVariable *new_prop = varbinder::Scope::CreateVar( - Allocator(), prop->Key()->AsIdentifier()->Name(), - varbinder::VariableFlags::PROPERTY | varbinder::VariableFlags::OPTIONAL, nullptr); + binder::LocalVariable *new_prop = + binder::Scope::CreateVar(Allocator(), prop->Key()->AsIdentifier()->Name(), + binder::VariableFlags::PROPERTY | binder::VariableFlags::OPTIONAL, nullptr); new_prop->SetTsType(GetBaseTypeOfLiteralType(CheckTypeCached(assignment_pattern->Right()))); new_object->AddProperty(new_prop); } @@ -204,12 +203,12 @@ Type *TSChecker::CreateParameterTypeForObjectAssignmentPattern(ir::ObjectExpress return new_object; } -using ReturnedVariable = std::tuple; -ReturnedVariable TSChecker::CheckFunctionAssignmentPatternParameter(ir::AssignmentExpression *param) +std::tuple TSChecker::CheckFunctionAssignmentPatternParameter( + ir::AssignmentExpression *param) { if (param->Left()->IsIdentifier()) { ir::Identifier *param_ident = param->Left()->AsIdentifier(); - varbinder::Variable *param_var = param_ident->Variable(); + binder::Variable *param_var = param_ident->Variable(); ASSERT(param_var); if (param_ident->TypeAnnotation() != nullptr) { @@ -221,7 +220,7 @@ ReturnedVariable TSChecker::CheckFunctionAssignmentPatternParameter(ir::Assignme } param_var->SetTsType(GetBaseTypeOfLiteralType(param->Right()->Check(this))); - param_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + param_var->AddFlag(binder::VariableFlags::OPTIONAL); return {param_var->AsLocalVariable(), nullptr, true}; } @@ -247,14 +246,14 @@ ReturnedVariable TSChecker::CheckFunctionAssignmentPatternParameter(ir::Assignme } util::UString pn(ss.str(), Allocator()); - varbinder::LocalVariable *pattern_var = - varbinder::Scope::CreateVar(Allocator(), pn.View(), varbinder::VariableFlags::NONE, param); + binder::LocalVariable *pattern_var = + binder::Scope::CreateVar(Allocator(), pn.View(), binder::VariableFlags::NONE, param); pattern_var->SetTsType(param_type); - pattern_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + pattern_var->AddFlag(binder::VariableFlags::OPTIONAL); return {pattern_var->AsLocalVariable(), nullptr, true}; } -std::tuple TSChecker::CheckFunctionRestParameter( +std::tuple TSChecker::CheckFunctionRestParameter( ir::SpreadElement *param, SignatureInfo *signature_info) { ir::TypeNode *type_annotation = nullptr; @@ -304,14 +303,14 @@ std::tuple TSCheck } } -std::tuple TSChecker::CheckFunctionArrayPatternParameter( +std::tuple TSChecker::CheckFunctionArrayPatternParameter( ir::ArrayExpression *param) { std::stringstream ss; CreatePatternParameterName(param, ss); util::UString pn(ss.str(), Allocator()); - varbinder::LocalVariable *pattern_var = - varbinder::Scope::CreateVar(Allocator(), pn.View(), varbinder::VariableFlags::NONE, param); + binder::LocalVariable *pattern_var = + binder::Scope::CreateVar(Allocator(), pn.View(), binder::VariableFlags::NONE, param); if (param->TypeAnnotation() != nullptr) { auto saved_context = SavedCheckerContext(this, CheckerStatus::FORCE_TUPLE); @@ -326,14 +325,14 @@ std::tuple TSCheck return {pattern_var->AsLocalVariable(), nullptr, false}; } -std::tuple TSChecker::CheckFunctionObjectPatternParameter( +std::tuple TSChecker::CheckFunctionObjectPatternParameter( ir::ObjectExpression *param) { std::stringstream ss; CreatePatternParameterName(param, ss); util::UString pn(ss.str(), Allocator()); - varbinder::LocalVariable *pattern_var = - varbinder::Scope::CreateVar(Allocator(), pn.View(), varbinder::VariableFlags::NONE, param); + binder::LocalVariable *pattern_var = + binder::Scope::CreateVar(Allocator(), pn.View(), binder::VariableFlags::NONE, param); if (param->TypeAnnotation() != nullptr) { auto saved_context = SavedCheckerContext(this, CheckerStatus::FORCE_TUPLE); @@ -348,16 +347,16 @@ std::tuple TSCheck return {pattern_var->AsLocalVariable(), nullptr, false}; } -std::tuple TSChecker::CheckFunctionParameter( +std::tuple TSChecker::CheckFunctionParameter( ir::Expression *param, SignatureInfo *signature_info) { if (param->TsType() != nullptr) { ASSERT(param->TsType()->Variable()); - varbinder::Variable *var = param->TsType()->Variable(); - return {var->AsLocalVariable(), nullptr, var->HasFlag(varbinder::VariableFlags::OPTIONAL)}; + binder::Variable *var = param->TsType()->Variable(); + return {var->AsLocalVariable(), nullptr, var->HasFlag(binder::VariableFlags::OPTIONAL)}; } - std::tuple result; + std::tuple result; bool cache = true; switch (param->Type()) { @@ -527,7 +526,7 @@ ir::Statement *FindSubsequentFunctionNode(ir::BlockStatement *block, ir::ScriptF return nullptr; } -void TSChecker::InferFunctionDeclarationType(const varbinder::FunctionDecl *decl, varbinder::Variable *func_var) +void TSChecker::InferFunctionDeclarationType(const binder::FunctionDecl *decl, binder::Variable *func_var) { ir::ScriptFunction *body_declaration = decl->Decls().back(); @@ -663,7 +662,7 @@ void TSChecker::CheckAllCodePathsInNonVoidFunctionReturnOrThrow(ir::ScriptFuncti if (!SearchForReturnOrThrow(func->Body())) { ThrowTypeError(err_msg, line_info); } - // NOTE: aszilagyi. this function is not fully implement the TSC one, in the future if we will have a + // TODO(aszilagyi): this function is not fully implement the TSC one, in the future if we will have a // noImplicitReturn compiler option for TypeScript we should update this function } @@ -712,16 +711,17 @@ bool TSChecker::CallMatchesSignature(const ArenaVector &args, if (validate_rest_arg || !throw_error) { checker::Type *call_arg_type = GetBaseTypeOfLiteralType(args[index]->Check(this)); - if (IsTypeAssignableTo(call_arg_type, sig_arg_type)) { - continue; - } + if (!IsTypeAssignableTo(call_arg_type, sig_arg_type)) { + if (throw_error) { + ThrowTypeError({"Argument of type '", call_arg_type, "' is not assignable to parameter of type '", + sig_arg_type, "'."}, + args[index]->Start()); + } - if (throw_error) { - ThrowTypeError({"Argument of type '", call_arg_type, "' is not assignable to parameter of type '", - sig_arg_type, "'."}, - args[index]->Start()); + return false; } - return false; + + continue; } ElaborateElementwise(sig_arg_type, args[index], args[index]->Start()); diff --git a/ets2panda/checker/ts/helpers.cpp b/ets2panda/checker/ts/helpers.cpp index 5432a39ef08f8596c945a8ec0abad897afe21d49..41ab10bc3fe633fd80ec155b24df57dfef918838 100644 --- a/ets2panda/checker/ts/helpers.cpp +++ b/ets2panda/checker/ts/helpers.cpp @@ -26,8 +26,8 @@ #include "ir/ts/tsTypeReference.h" #include "ir/ts/tsTypeParameterDeclaration.h" #include "ir/ts/tsTypeParameter.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" +#include "binder/variable.h" +#include "binder/scope.h" #include "util/helpers.h" #include "checker/ts/typeElaborationContext.h" @@ -99,7 +99,7 @@ void TSChecker::CheckReferenceExpression(ir::Expression *expr, const char *inval auto result = Scope()->Find(name); ASSERT(result.variable); - if (result.variable->HasFlag(varbinder::VariableFlags::ENUM_LITERAL)) { + if (result.variable->HasFlag(binder::VariableFlags::ENUM_LITERAL)) { ThrowTypeError({"Cannot assign to '", name, "' because it is not a variable."}, expr->Start()); } } else if (!expr->IsMemberExpression()) { @@ -115,7 +115,7 @@ void TSChecker::CheckTestingKnownTruthyCallableOrAwaitableType([[maybe_unused]] [[maybe_unused]] Type *type, [[maybe_unused]] ir::AstNode *body) { - // NOTE: aszilagyi. rework this + // TODO(aszilagyi) rework this } Type *TSChecker::ExtractDefinitelyFalsyTypes(Type *type) @@ -218,12 +218,12 @@ TypeFlag TSChecker::GetFalsyFlags(Type *type) return static_cast(type->TypeFlags() & TypeFlag::POSSIBLY_FALSY); } -bool TSChecker::IsVariableUsedInConditionBody(ir::AstNode *parent, varbinder::Variable *search_var) +bool TSChecker::IsVariableUsedInConditionBody(ir::AstNode *parent, binder::Variable *search_var) { bool found = false; parent->Iterate([this, search_var, &found](ir::AstNode *child_node) -> void { - varbinder::Variable *result_var = nullptr; + binder::Variable *result_var = nullptr; if (child_node->IsIdentifier()) { auto result = Scope()->Find(child_node->AsIdentifier()->Name()); ASSERT(result.variable); @@ -243,7 +243,7 @@ bool TSChecker::IsVariableUsedInConditionBody(ir::AstNode *parent, varbinder::Va return found; } -bool TSChecker::FindVariableInBinaryExpressionChain(ir::AstNode *parent, varbinder::Variable *search_var) +bool TSChecker::FindVariableInBinaryExpressionChain(ir::AstNode *parent, binder::Variable *search_var) { bool found = false; @@ -263,7 +263,7 @@ bool TSChecker::FindVariableInBinaryExpressionChain(ir::AstNode *parent, varbind return found; } -bool TSChecker::IsVariableUsedInBinaryExpressionChain(ir::AstNode *parent, varbinder::Variable *search_var) +bool TSChecker::IsVariableUsedInBinaryExpressionChain(ir::AstNode *parent, binder::Variable *search_var) { while (parent->IsBinaryExpression() && parent->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { @@ -339,7 +339,7 @@ void TSChecker::InferSimpleVariableDeclaratorType(ir::VariableDeclarator *declar { ASSERT(declarator->Id()->IsIdentifier()); - varbinder::Variable *var = declarator->Id()->AsIdentifier()->Variable(); + binder::Variable *var = declarator->Id()->AsIdentifier()->Variable(); ASSERT(var); if (declarator->Id()->AsIdentifier()->TypeAnnotation() != nullptr) { @@ -356,13 +356,13 @@ void TSChecker::InferSimpleVariableDeclaratorType(ir::VariableDeclarator *declar declarator->Id()->Start()); } -Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) +Type *TSChecker::GetTypeOfVariable(binder::Variable *var) { if (var->TsType() != nullptr) { return var->TsType(); } - varbinder::Decl *decl = var->Declaration(); + binder::Decl *decl = var->Declaration(); TypeStackElement tse(this, decl->Node(), {"'", var->Name(), @@ -371,8 +371,8 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) decl->Node()->Start()); switch (decl->Type()) { - case varbinder::DeclType::CONST: - case varbinder::DeclType::LET: { + case binder::DeclType::CONST: + case binder::DeclType::LET: { if (!decl->Node()->Parent()->IsTSTypeQuery()) { ThrowTypeError({"Block-scoped variable '", var->Name(), "' used before its declaration"}, decl->Node()->Start()); @@ -381,7 +381,7 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) [[fallthrough]]; } - case varbinder::DeclType::VAR: { + case binder::DeclType::VAR: { ir::AstNode *declarator = util::Helpers::FindAncestorGivenByType(decl->Node(), ir::AstNodeType::VARIABLE_DECLARATOR); ASSERT(declarator); @@ -394,22 +394,22 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) declarator->Check(this); break; } - case varbinder::DeclType::PROPERTY: { + case binder::DeclType::PROPERTY: { var->SetTsType(decl->Node()->AsTSPropertySignature()->TypeAnnotation()->GetType(this)); break; } - case varbinder::DeclType::METHOD: { + case binder::DeclType::METHOD: { auto *signature_info = Allocator()->New(Allocator()); auto *call_signature = Allocator()->New(signature_info, GlobalAnyType()); var->SetTsType(CreateFunctionTypeWithSignature(call_signature)); break; } - case varbinder::DeclType::FUNC: { + case binder::DeclType::FUNC: { checker::ScopeContext scope_ctx(this, decl->Node()->AsScriptFunction()->Scope()); InferFunctionDeclarationType(decl->AsFunctionDecl(), var); break; } - case varbinder::DeclType::PARAM: { + case binder::DeclType::PARAM: { ir::AstNode *declaration = FindAncestorUntilGivenType(decl->Node(), ir::AstNodeType::SCRIPT_FUNCTION); if (declaration->IsIdentifier()) { @@ -438,9 +438,9 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) CheckFunctionParameter(declaration->AsExpression(), nullptr); break; } - case varbinder::DeclType::ENUM: { + case binder::DeclType::ENUM: { ASSERT(var->IsEnumVariable()); - varbinder::EnumVariable *enum_var = var->AsEnumVariable(); + binder::EnumVariable *enum_var = var->AsEnumVariable(); if (std::holds_alternative(enum_var->Value())) { ThrowTypeError( @@ -453,8 +453,8 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) var->SetTsType(std::holds_alternative(enum_var->Value()) ? GlobalNumberType() : GlobalStringType()); break; } - case varbinder::DeclType::ENUM_LITERAL: { - UNREACHABLE(); // NOTE: aszilagyi. + case binder::DeclType::ENUM_LITERAL: { + UNREACHABLE(); // TODO(aszilagyi) } default: { break; @@ -464,8 +464,7 @@ Type *TSChecker::GetTypeOfVariable(varbinder::Variable *var) return var->TsType(); } -Type *TSChecker::GetTypeFromClassOrInterfaceReference([[maybe_unused]] ir::TSTypeReference *node, - varbinder::Variable *var) +Type *TSChecker::GetTypeFromClassOrInterfaceReference([[maybe_unused]] ir::TSTypeReference *node, binder::Variable *var) { Type *resolved_type = var->TsType(); @@ -479,7 +478,7 @@ Type *TSChecker::GetTypeFromClassOrInterfaceReference([[maybe_unused]] ir::TSTyp return resolved_type; } -Type *TSChecker::GetTypeFromTypeAliasReference(ir::TSTypeReference *node, varbinder::Variable *var) +Type *TSChecker::GetTypeFromTypeAliasReference(ir::TSTypeReference *node, binder::Variable *var) { Type *resolved_type = var->TsType(); @@ -497,10 +496,10 @@ Type *TSChecker::GetTypeFromTypeAliasReference(ir::TSTypeReference *node, varbin return resolved_type; } -Type *TSChecker::GetTypeReferenceType(ir::TSTypeReference *node, varbinder::Variable *var) +Type *TSChecker::GetTypeReferenceType(ir::TSTypeReference *node, binder::Variable *var) { ASSERT(var->Declaration()); - varbinder::Decl *decl = var->Declaration(); + binder::Decl *decl = var->Declaration(); if (decl->IsInterfaceDecl()) { return GetTypeFromClassOrInterfaceReference(node, var); diff --git a/ets2panda/checker/ts/object.cpp b/ets2panda/checker/ts/object.cpp index e67b035a36b08821ef777cc87d9a8edfbd18c95e..c8f40f77004990e504f10b585b0767c4d87bec8a 100644 --- a/ets2panda/checker/ts/object.cpp +++ b/ets2panda/checker/ts/object.cpp @@ -31,8 +31,8 @@ #include "ir/ts/tsInterfaceHeritage.h" #include "ir/ts/tsInterfaceBody.h" #include "util/helpers.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" +#include "binder/variable.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/types/ts/indexInfo.h" @@ -49,11 +49,11 @@ void TSChecker::CheckIndexConstraints(Type *type) IndexInfo *number_info = obj_type->NumberIndexInfo(); IndexInfo *string_info = obj_type->StringIndexInfo(); - const ArenaVector &properties = obj_type->Properties(); + const ArenaVector &properties = obj_type->Properties(); if (number_info != nullptr) { for (auto *it : properties) { - if (it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME)) { + if (it->HasFlag(binder::VariableFlags::NUMERIC_NAME)) { Type *prop_type = GetTypeOfVariable(it); IsTypeAssignableTo(prop_type, number_info->GetType(), {"Property '", it->Name(), "' of type '", prop_type, @@ -200,7 +200,7 @@ void TSChecker::ResolvePropertiesOfObjectType(ObjectType *type, ir::AstNode *mem bool is_interface) { if (member->IsTSPropertySignature()) { - varbinder::Variable *prop = member->AsTSPropertySignature()->Variable(); + binder::Variable *prop = member->AsTSPropertySignature()->Variable(); if (!is_interface || ValidateInterfaceMemberRedeclaration(type, prop, member->AsTSPropertySignature()->Key()->Start())) { @@ -211,7 +211,7 @@ void TSChecker::ResolvePropertiesOfObjectType(ObjectType *type, ir::AstNode *mem } if (member->IsTSMethodSignature()) { - varbinder::Variable *method = member->AsTSMethodSignature()->Variable(); + binder::Variable *method = member->AsTSMethodSignature()->Variable(); if (!is_interface || ValidateInterfaceMemberRedeclaration(type, method, member->AsTSMethodSignature()->Key()->Start())) { @@ -271,8 +271,8 @@ void TSChecker::ResolveIndexInfosOfObjectType(ObjectType *type, ArenaVectorIsObjectType()) { ResolveObjectTypeMembers(type->AsObjectType()); @@ -286,8 +286,8 @@ varbinder::Variable *TSChecker::GetPropertyOfType(Type *type, const util::String return nullptr; } -varbinder::Variable *TSChecker::GetPropertyOfUnionType(UnionType *type, const util::StringView &name, bool get_partial, - varbinder::VariableFlags propagate_flags) +binder::Variable *TSChecker::GetPropertyOfUnionType(UnionType *type, const util::StringView &name, bool get_partial, + binder::VariableFlags propagate_flags) { auto found = type->CachedSyntheticProperties().find(name); @@ -295,11 +295,11 @@ varbinder::Variable *TSChecker::GetPropertyOfUnionType(UnionType *type, const ut return found->second; } - varbinder::VariableFlags flags = varbinder::VariableFlags::PROPERTY; + binder::VariableFlags flags = binder::VariableFlags::PROPERTY; ArenaVector collected_types(Allocator()->Adapter()); for (auto *it : type->ConstituentTypes()) { - varbinder::Variable *prop = GetPropertyOfType(it, name); + binder::Variable *prop = GetPropertyOfType(it, name); if (prop == nullptr) { if (it->IsArrayType()) { @@ -331,8 +331,8 @@ varbinder::Variable *TSChecker::GetPropertyOfUnionType(UnionType *type, const ut prop->AddFlag(propagate_flags); - if (prop->HasFlag(varbinder::VariableFlags::OPTIONAL)) { - flags |= varbinder::VariableFlags::OPTIONAL; + if (prop->HasFlag(binder::VariableFlags::OPTIONAL)) { + flags |= binder::VariableFlags::OPTIONAL; } collected_types.push_back(GetTypeOfVariable(prop)); @@ -342,7 +342,7 @@ varbinder::Variable *TSChecker::GetPropertyOfUnionType(UnionType *type, const ut return nullptr; } - varbinder::Variable *synthetic_prop = varbinder::Scope::CreateVar(Allocator(), name, flags, nullptr); + binder::Variable *synthetic_prop = binder::Scope::CreateVar(Allocator(), name, flags, nullptr); synthetic_prop->SetTsType(CreateUnionType(std::move(collected_types))); type->CachedSyntheticProperties().insert({name, synthetic_prop}); return synthetic_prop; @@ -401,7 +401,7 @@ Type *TSChecker::GetPropertyTypeForIndexType(Type *type, Type *index_type) } if (index_type->HasTypeFlag(TypeFlag::STRING_LITERAL | TypeFlag::NUMBER_LITERAL)) { - varbinder::Variable *prop = nullptr; + binder::Variable *prop = nullptr; if (index_type->IsStringLiteralType()) { prop = GetPropertyOfType(type, index_type->AsStringLiteralType()->Value()); @@ -414,7 +414,7 @@ Type *TSChecker::GetPropertyTypeForIndexType(Type *type, Type *index_type) if (prop != nullptr) { Type *prop_type = GetTypeOfVariable(prop); - if (prop->HasFlag(varbinder::VariableFlags::READONLY)) { + if (prop->HasFlag(binder::VariableFlags::READONLY)) { prop_type->AddTypeFlag(TypeFlag::READONLY); } @@ -446,7 +446,7 @@ ArenaVector TSChecker::GetBaseTypes(InterfaceType *type) } ASSERT(type->Variable() && type->Variable()->Declaration()->IsInterfaceDecl()); - varbinder::InterfaceDecl *decl = type->Variable()->Declaration()->AsInterfaceDecl(); + binder::InterfaceDecl *decl = type->Variable()->Declaration()->AsInterfaceDecl(); TypeStackElement tse(this, type, {"Type ", type->Name(), " recursively references itself as a base type."}, decl->Node()->AsTSInterfaceDeclaration()->Id()->Start()); @@ -505,7 +505,7 @@ void TSChecker::ResolveDeclaredMembers(InterfaceType *type) } ASSERT(type->Variable() && type->Variable()->Declaration()->IsInterfaceDecl()); - varbinder::InterfaceDecl *decl = type->Variable()->Declaration()->AsInterfaceDecl(); + binder::InterfaceDecl *decl = type->Variable()->Declaration()->AsInterfaceDecl(); ArenaVector signature_declarations(Allocator()->Adapter()); ArenaVector index_declarations(Allocator()->Adapter()); @@ -522,14 +522,14 @@ void TSChecker::ResolveDeclaredMembers(InterfaceType *type) } } -bool TSChecker::ValidateInterfaceMemberRedeclaration(ObjectType *type, varbinder::Variable *prop, +bool TSChecker::ValidateInterfaceMemberRedeclaration(ObjectType *type, binder::Variable *prop, const lexer::SourcePosition &loc_info) { - if (prop->HasFlag(varbinder::VariableFlags::COMPUTED)) { + if (prop->HasFlag(binder::VariableFlags::COMPUTED)) { return true; } - varbinder::Variable *found = type->GetProperty(prop->Name(), false); + binder::Variable *found = type->GetProperty(prop->Name(), false); if (found == nullptr) { return true; diff --git a/ets2panda/checker/ts/typeElaborationContext.cpp b/ets2panda/checker/ts/typeElaborationContext.cpp index 8fe8fb6b91ae12c55e04d90ac56800ebcab99eab..e7fc27ef12db870c24ac46e679b2c8611e63cab6 100644 --- a/ets2panda/checker/ts/typeElaborationContext.cpp +++ b/ets2panda/checker/ts/typeElaborationContext.cpp @@ -16,7 +16,7 @@ #include "typeElaborationContext.h" #include "util/helpers.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/expressions/identifier.h" #include "ir/expressions/objectExpression.h" #include "ir/expressions/arrayExpression.h" diff --git a/ets2panda/checker/types/ets/byteType.cpp b/ets2panda/checker/types/ets/byteType.cpp index d662c6e0a02a89c415f3a43be75e85cac2257612..5c05455108965532d6f2c915fac5811e362b543a 100644 --- a/ets2panda/checker/types/ets/byteType.cpp +++ b/ets2panda/checker/types/ets/byteType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -82,11 +82,6 @@ void ByteType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/byteType.h b/ets2panda/checker/types/ets/byteType.h index 88cfce4304cba440c42cbc6ef00dad6a3464618e..ecbf47d8850307a8d1fd941769787baae269fdca 100644 --- a/ets2panda/checker/types/ets/byteType.h +++ b/ets2panda/checker/types/ets/byteType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_BYTE; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0}; }; diff --git a/ets2panda/checker/types/ets/charType.cpp b/ets2panda/checker/types/ets/charType.cpp index d12017b54aac6204de6efdc4c2a2276e92249a7f..aba253d3397dea3f635ecd99b118f12310192977 100644 --- a/ets2panda/checker/types/ets/charType.cpp +++ b/ets2panda/checker/types/ets/charType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -82,11 +82,6 @@ void CharType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/charType.h b/ets2panda/checker/types/ets/charType.h index 12878a3aff5b12c17c87f6079987bb7bef3df35f..6f7dc11b828ee2b971499876bb838aa3063b6a8b 100644 --- a/ets2panda/checker/types/ets/charType.h +++ b/ets2panda/checker/types/ets/charType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_CHAR; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != '\0'}; - } - private: UType value_ {'\0'}; }; diff --git a/ets2panda/checker/types/ets/doubleType.cpp b/ets2panda/checker/types/ets/doubleType.cpp index 0b1bf0f592fa85b9095e8d1ca9acd4ce42a0b0d2..99e3d5e0d11c66b58e56619e1820c31a31191b57 100644 --- a/ets2panda/checker/types/ets/doubleType.cpp +++ b/ets2panda/checker/types/ets/doubleType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -77,11 +77,6 @@ void DoubleType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/doubleType.h b/ets2panda/checker/types/ets/doubleType.h index 2377f4244318a3017525e95355e0a5bc60b2d5cf..07365fa67043ffd611697251a14b99b0e3fb2d9a 100644 --- a/ets2panda/checker/types/ets/doubleType.h +++ b/ets2panda/checker/types/ets/doubleType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_DOUBLE; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0.0}; }; diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index e6ea36913ce4b12478652d57ed0810532b5d145d..06e49c1bef1f84811ed3e7d06cc2719e6e4fcf56 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,7 +15,7 @@ #include "etsArrayType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" #include "checker/types/typeRelation.h" diff --git a/ets2panda/checker/types/ets/etsArrayType.h b/ets2panda/checker/types/ets/etsArrayType.h index f1cb2f1bada6ea7ea76e0e32896c38c015cdb99d..323f3df4006d9a62f55d4735c5cc1cd439accf51 100644 --- a/ets2panda/checker/types/ets/etsArrayType.h +++ b/ets2panda/checker/types/ets/etsArrayType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -33,11 +33,6 @@ public: return element_; } - std::tuple ResolveConditionExpr() const override - { - return {false, false}; - } - void ToString(std::stringstream &ss) const override; void ToAssemblerType(std::stringstream &ss) const override; void ToAssemblerTypeWithRank(std::stringstream &ss) const override; diff --git a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp index d949edc1788949a1093d41aabc1e01cfec3d8bc5..b0e5545e8c99b4269f3475ac3db403bd995f7ce7 100644 --- a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp +++ b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h index c5ed7d523b16deda70cb9903fdf505124fda0114..bff8035cfb5cb2363916ec47d012398bfeacde08 100644 --- a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h +++ b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/types/ets/etsBooleanType.cpp b/ets2panda/checker/types/ets/etsBooleanType.cpp index a6d5dd49daeb8106873f4de82d4761031e302f4f..52dbbfdad44d6ff9bd7664fd628e694dc9998589 100644 --- a/ets2panda/checker/types/ets/etsBooleanType.cpp +++ b/ets2panda/checker/types/ets/etsBooleanType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -64,11 +64,6 @@ void ETSBooleanType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/etsBooleanType.h b/ets2panda/checker/types/ets/etsBooleanType.h index c48b766bc21b4297c6f5d34816d91c3ba508e9ff..f842f762fed55effd52d8be4e1b41c6b0edb1969 100644 --- a/ets2panda/checker/types/ets/etsBooleanType.h +++ b/ets2panda/checker/types/ets/etsBooleanType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -51,11 +51,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_BOOLEAN; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_}; - } - private: UType value_ {false}; }; diff --git a/ets2panda/checker/types/ets/etsDynamicFunctionType.h b/ets2panda/checker/types/ets/etsDynamicFunctionType.h index 638601655721afd2b513c4bbc64a2071e3536bb2..06d452b7e3c8a20e169d3b103344176d3b99eac7 100644 --- a/ets2panda/checker/types/ets/etsDynamicFunctionType.h +++ b/ets2panda/checker/types/ets/etsDynamicFunctionType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsDynamicType.cpp b/ets2panda/checker/types/ets/etsDynamicType.cpp index 4c07a3bd086ca84055f346038c60f27227132a1a..7b252e8a03350fe710cb5f7a54f52914fc7bd693 100644 --- a/ets2panda/checker/types/ets/etsDynamicType.cpp +++ b/ets2panda/checker/types/ets/etsDynamicType.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -19,16 +19,15 @@ namespace panda::es2panda::checker { -varbinder::LocalVariable *ETSDynamicType::GetPropertyDynamic(const util::StringView &name, - const ETSChecker *checker) const +binder::LocalVariable *ETSDynamicType::GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const { auto it = properties_cache_.find(name); if (it != properties_cache_.end()) { return it->second; } - varbinder::LocalVariable *var = varbinder::Scope::CreateVar( - Allocator(), name, varbinder::VariableFlags::BUILTIN_TYPE, nullptr); + binder::LocalVariable *var = + binder::Scope::CreateVar(Allocator(), name, binder::VariableFlags::BUILTIN_TYPE, nullptr); var->SetTsType(checker->GlobalBuiltinDynamicType(lang_)); properties_cache_.emplace(name, var); diff --git a/ets2panda/checker/types/ets/etsDynamicType.h b/ets2panda/checker/types/ets/etsDynamicType.h index 66169a10ef49aa88aacb760f6d00564a29d10215..b13e439249fe2ed0d529b60df29fa128ee874d4f 100644 --- a/ets2panda/checker/types/ets/etsDynamicType.h +++ b/ets2panda/checker/types/ets/etsDynamicType.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -33,7 +33,7 @@ public: static bool IsDynamicType(util::StringView assembler_name); - varbinder::LocalVariable *GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const; + binder::LocalVariable *GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; void Cast(TypeRelation *relation, Type *target) override; diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index f102cd217775d13d7eb6e510f434cecc246ffea7..c5b08819f327f74a654c15436e906b01d810ec2c 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -103,7 +103,7 @@ const ArenaVector &ETSEnumInterface::GetMembers() const noexcept return decl_->Members(); } -varbinder::LocalVariable *ETSEnumInterface::GetMemberVar() const noexcept +binder::LocalVariable *ETSEnumInterface::GetMemberVar() const noexcept { ASSERT(IsLiteralType()); return member_->Key()->AsIdentifier()->Variable()->AsLocalVariable(); @@ -227,7 +227,7 @@ bool ETSEnumInterface::IsEnumTypeExpression(const ir::Expression *const expressi return false; } - const auto *const local_var = [expression]() -> const varbinder::LocalVariable * { + const auto *const local_var = [expression]() -> const binder::LocalVariable * { if (expression->IsMemberExpression()) { const auto *const member_expr = expression->AsMemberExpression(); return member_expr->PropVar() != nullptr @@ -238,8 +238,9 @@ bool ETSEnumInterface::IsEnumTypeExpression(const ir::Expression *const expressi }(); ASSERT(local_var->Declaration() == decl_->Key()->AsIdentifier()->Variable()->Declaration() || - !local_var->HasFlag(varbinder::VariableFlags::ENUM_LITERAL)); - return local_var->HasFlag(varbinder::VariableFlags::ENUM_LITERAL); + !local_var->HasFlag(binder::VariableFlags::ENUM_LITERAL)); + + return local_var->HasFlag(binder::VariableFlags::ENUM_LITERAL); } ETSEnumInterface::Method ETSEnumInterface::FromIntMethod() const noexcept diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index b926a304d93ed005f597326366ae5071388a12ba..3bfae61aae983a9242e894e3d645a31d600170de 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -24,9 +24,9 @@ template // NOLINTNEXTLINE(readability-identifier-naming) inline constexpr bool dependent_false_v = false; -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LocalVariable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { template @@ -66,7 +66,7 @@ public: [[nodiscard]] const ArenaVector &GetMembers() const noexcept; - [[nodiscard]] varbinder::LocalVariable *GetMemberVar() const noexcept; + [[nodiscard]] binder::LocalVariable *GetMemberVar() const noexcept; [[nodiscard]] util::StringView GetName() const noexcept; diff --git a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp index e24ee3e6deaffbca233a26dc239cf7301680965b..6dc1b76764cd2c58ef1d1d5da796c10155328a05 100644 --- a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp +++ b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h index d57bf7944004bb9cb300658be9ad682e2893d27f..7aa4fd43bbb45408504dc93e772512e8d6854064 100644 --- a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h +++ b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 6e34f6ea2576605bab9d8f44a2b40adaa93c1617..b87aa27c119f948cfefb3648b01ed83b80ccfcdd 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsFunctionType.h b/ets2panda/checker/types/ets/etsFunctionType.h index 815055f2e089ee00af9d38af309b16f90c0302a9..d09f77fcfee4b38f316d8deb0d956681b823be17 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.h +++ b/ets2panda/checker/types/ets/etsFunctionType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 9ce2ac03017becbc56a88267ed339c1290e1a998..c04684c5be39fde5c97a8c5cbc9e53008fbb2c96 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,7 +15,7 @@ #include "etsObjectType.h" -#include "varbinder/declaration.h" +#include "binder/declaration.h" #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" #include "checker/types/typeFlag.h" @@ -41,9 +41,9 @@ void ETSObjectType::Iterate(const PropertyTraverser &cb) const } } -varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &name, PropertySearchFlags flags) const +binder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &name, PropertySearchFlags flags) const { - varbinder::LocalVariable *res {}; + binder::LocalVariable *res {}; if ((flags & PropertySearchFlags::SEARCH_INSTANCE_FIELD) != 0) { res = GetOwnProperty(name); } @@ -90,6 +90,7 @@ varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &nam if ((flags & PropertySearchFlags::SEARCH_IN_INTERFACES) != 0) { for (auto *interface : interfaces_) { res = interface->GetProperty(name, flags); + if (res != nullptr) { return res; } @@ -103,15 +104,15 @@ varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &nam return res; } -varbinder::LocalVariable *ETSObjectType::CreateSyntheticVarFromEverySignature(const util::StringView &name, - PropertySearchFlags flags) const +binder::LocalVariable *ETSObjectType::CreateSyntheticVarFromEverySignature(const util::StringView &name, + PropertySearchFlags flags) const { - varbinder::LocalVariable *res = allocator_->New(varbinder::VariableFlags::SYNTHETIC | - varbinder::VariableFlags::METHOD); + binder::LocalVariable *res = + allocator_->New(binder::VariableFlags::SYNTHETIC | binder::VariableFlags::METHOD); ETSFunctionType *func_type = CreateETSFunctionType(name); func_type->AddTypeFlag(TypeFlag::SYNTHETIC); - varbinder::LocalVariable *functional_interface = CollectSignaturesForSyntheticType(func_type, name, flags); + binder::LocalVariable *functional_interface = CollectSignaturesForSyntheticType(func_type, name, flags); if (functional_interface != nullptr) { return functional_interface; @@ -131,47 +132,52 @@ ETSFunctionType *ETSObjectType::CreateETSFunctionType(const util::StringView &na return allocator_->New(name, allocator_); } -varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(ETSFunctionType *func_type, - const util::StringView &name, - PropertySearchFlags flags) const +binder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(ETSFunctionType *func_type, + const util::StringView &name, + PropertySearchFlags flags) const { - auto const add_signature = [func_type, flags](varbinder::LocalVariable *found) -> void { - for (auto *it : found->TsType()->AsETSFunctionType()->CallSignatures()) { - if (((flags & PropertySearchFlags::IGNORE_ABSTRACT) != 0) && - it->HasSignatureFlag(SignatureFlags::ABSTRACT)) { - continue; - } - - func_type->AddCallSignature(it); - } - }; - // During function reference resolution, if the found properties type is not a function type, then it is a // functional interface, because no other property can be found in the methods of the class. We have to // return the found property, because we doesn't need to create a synthetic variable for functional // interfaces due to the fact, that by nature they behave as fields, and can't have overloads, and they are // subjected to hiding if ((flags & PropertySearchFlags::SEARCH_STATIC_METHOD) != 0) { - if (auto *found = GetOwnProperty(name); found != nullptr) { - if (found->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) { + auto *found = GetOwnProperty(name); + if (found != nullptr) { + if (found->HasFlag(binder::VariableFlags::METHOD_REFERENCE)) { // Functional interface found return found; } ASSERT(found->TsType()->IsETSFunctionType()); - add_signature(found); + for (auto *it : found->TsType()->AsETSFunctionType()->CallSignatures()) { + if (((flags & PropertySearchFlags::IGNORE_ABSTRACT) != 0) && + it->HasSignatureFlag(SignatureFlags::ABSTRACT)) { + continue; + } + + func_type->AddCallSignature(it); + } } } if ((flags & PropertySearchFlags::SEARCH_INSTANCE_METHOD) != 0) { - if (auto *found = GetOwnProperty(name); found != nullptr) { - if (found->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) { + auto *found = GetOwnProperty(name); + if (found != nullptr) { + if (found->HasFlag(binder::VariableFlags::METHOD_REFERENCE)) { // Functional interface found return found; } ASSERT(found->TsType()->IsETSFunctionType()); - add_signature(found); + for (auto *it : found->TsType()->AsETSFunctionType()->CallSignatures()) { + if (((flags & PropertySearchFlags::IGNORE_ABSTRACT) != 0) && + it->HasSignatureFlag(SignatureFlags::ABSTRACT)) { + continue; + } + + func_type->AddCallSignature(it); + } } } @@ -182,9 +188,9 @@ varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(ETSFu return nullptr; } -std::vector ETSObjectType::GetAllProperties() const +std::vector ETSObjectType::GetAllProperties() const { - std::vector all_properties; + std::vector all_properties; for (const auto &[_, prop] : InstanceFields()) { (void)_; all_properties.push_back(prop); @@ -218,9 +224,9 @@ std::vector ETSObjectType::GetAllProperties() const return all_properties; } -std::vector ETSObjectType::Methods() const +std::vector ETSObjectType::Methods() const { - std::vector methods; + std::vector methods; for (const auto &[_, prop] : InstanceMethods()) { (void)_; methods.push_back(prop); @@ -234,9 +240,9 @@ std::vector ETSObjectType::Methods() const return methods; } -std::vector ETSObjectType::Fields() const +std::vector ETSObjectType::Fields() const { - std::vector fields; + std::vector fields; for (const auto &[_, prop] : InstanceFields()) { (void)_; fields.push_back(prop); @@ -250,9 +256,9 @@ std::vector ETSObjectType::Fields() const return fields; } -std::vector ETSObjectType::ForeignProperties() const +std::vector ETSObjectType::ForeignProperties() const { - std::vector foreign_props; + std::vector foreign_props; std::unordered_set own_props; EnsurePropertiesInstantiated(); @@ -272,12 +278,12 @@ std::vector ETSObjectType::ForeignProperties() return foreign_props; } -std::unordered_map ETSObjectType::CollectAllProperties() const +std::unordered_map ETSObjectType::CollectAllProperties() const { - std::unordered_map prop_map; + std::unordered_map prop_map; EnsurePropertiesInstantiated(); prop_map.reserve(properties_.size()); - Iterate([&prop_map](const varbinder::LocalVariable *var) { prop_map.insert({var->Name(), var}); }); + Iterate([&prop_map](const binder::LocalVariable *var) { prop_map.insert({var->Name(), var}); }); return prop_map; } @@ -335,26 +341,22 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other if (type_arguments_.empty() != other_type_arguments.empty()) { return; } + ASSERT(type_arguments_.size() == other_type_arguments.size()); + for (size_t idx = 0; idx < type_arguments_.size(); idx++) { + if (!(type_arguments_[idx]->IsWildcardType() || other_type_arguments[idx]->IsWildcardType())) { + const auto get_original_base_type_or_type = [&relation](Type *const original_type) { + auto *const base_type = relation->GetChecker()->AsETSChecker()->GetOriginalBaseType(original_type); + return base_type == nullptr ? original_type : base_type; + }; - auto const args_number = type_arguments_.size(); - ASSERT(args_number == other_type_arguments.size()); + auto *const type_arg_type = get_original_base_type_or_type(type_arguments_[idx]); + auto *const other_type_arg_type = get_original_base_type_or_type(other_type_arguments[idx]); - for (size_t idx = 0U; idx < args_number; ++idx) { - if (type_arguments_[idx]->IsWildcardType() || other_type_arguments[idx]->IsWildcardType()) { - continue; - } - - const auto get_original_base_type_or_type = [&relation](Type *const original_type) { - auto *const base_type = relation->GetChecker()->AsETSChecker()->GetOriginalBaseType(original_type); - return base_type == nullptr ? original_type : base_type; - }; + type_arg_type->Identical(relation, other_type_arg_type); - auto *const type_arg_type = get_original_base_type_or_type(type_arguments_[idx]); - auto *const other_type_arg_type = get_original_base_type_or_type(other_type_arguments[idx]); - - type_arg_type->Identical(relation, other_type_arg_type); - if (!relation->IsTrue()) { - return; + if (!relation->IsTrue()) { + return; + } } } } else { @@ -427,161 +429,181 @@ void ETSObjectType::AssignmentTarget(TypeRelation *const relation, Type *source) IsSupertypeOf(relation, source); } -bool ETSObjectType::CastNumericObject(TypeRelation *const relation, Type *const target) +void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) { - if (this->IsNullableType()) { - return false; + conversion::Identity(relation, this, target); + if (relation->IsTrue()) { + return; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BYTE)) { - if (target->HasTypeFlag(TypeFlag::BYTE)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::SHORT | TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | - TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; - } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; - } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_SHORT)) { - if (target->HasTypeFlag(TypeFlag::SHORT)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; - } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; - } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_CHAR)) { - if (target->HasTypeFlag(TypeFlag::CHAR)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; - } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; - } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_INT)) { - if (target->HasTypeFlag(TypeFlag::INT)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; - } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; - } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_LONG)) { - if (target->HasTypeFlag(TypeFlag::LONG)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::FLOAT | TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::NULL_TYPE)) { if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; + relation->GetNode()->SetTsType(target); + relation->Result(true); + return; } + conversion::Forbidden(relation); - return true; + return; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_FLOAT)) { - if (target->HasTypeFlag(TypeFlag::FLOAT)) { - conversion::Unboxing(relation, this); - return true; - } - if (target->HasTypeFlag(TypeFlag::DOUBLE)) { - conversion::UnboxingWideningPrimitive(relation, this, target); - return true; + + if (!this->IsNullableType()) { + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BYTE)) { + if (target->HasTypeFlag(TypeFlag::BYTE)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::SHORT | TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | + TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; + + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_SHORT)) { + if (target->HasTypeFlag(TypeFlag::SHORT)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE)) { - if (target->HasTypeFlag(TypeFlag::DOUBLE)) { - conversion::Unboxing(relation, this); - return true; + + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_CHAR)) { + if (target->HasTypeFlag(TypeFlag::CHAR)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; + + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_INT)) { + if (target->HasTypeFlag(TypeFlag::INT)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - conversion::Forbidden(relation); - return true; - } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BOOLEAN)) { - if (target->HasTypeFlag(TypeFlag::ETS_BOOLEAN)) { - conversion::Unboxing(relation, this); - return true; + + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_LONG)) { + if (target->HasTypeFlag(TypeFlag::LONG)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::FLOAT | TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - conversion::WideningReference(relation, this, target->AsETSObjectType()); - return true; + + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_FLOAT)) { + if (target->HasTypeFlag(TypeFlag::FLOAT)) { + conversion::Unboxing(relation, this); + return; + } + + if (target->HasTypeFlag(TypeFlag::DOUBLE)) { + conversion::UnboxingWideningPrimitive(relation, this, target); + return; + } + + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; } - conversion::Forbidden(relation); - return true; - } - if (target->HasTypeFlag(TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG | - TypeFlag::FLOAT | TypeFlag::DOUBLE | TypeFlag::ETS_BOOLEAN)) { - conversion::NarrowingReferenceUnboxing(relation, this, target); - return true; - } - return false; -} -void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) -{ - conversion::Identity(relation, this, target); - if (relation->IsTrue()) { - return; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE)) { + if (target->HasTypeFlag(TypeFlag::DOUBLE)) { + conversion::Unboxing(relation, this); + return; + } - if (this->HasObjectFlag(ETSObjectFlags::NULL_TYPE)) { - if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { - relation->GetNode()->SetTsType(target); - relation->Result(true); + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); return; } - conversion::Forbidden(relation); - return; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BOOLEAN)) { + if (target->HasTypeFlag(TypeFlag::ETS_BOOLEAN)) { + conversion::Unboxing(relation, this); + return; + } - if (CastNumericObject(relation, target)) { - return; + if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { + conversion::WideningReference(relation, this, target->AsETSObjectType()); + return; + } + + conversion::Forbidden(relation); + return; + } + + if (target->HasTypeFlag(TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG | + TypeFlag::FLOAT | TypeFlag::DOUBLE | TypeFlag::ETS_BOOLEAN)) { + conversion::NarrowingReferenceUnboxing(relation, this, target); + return; + } } if (target->HasTypeFlag(TypeFlag::ETS_ARRAY)) { @@ -601,11 +623,6 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) } } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } @@ -622,8 +639,7 @@ void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) } if (!source->IsETSObjectType() || - !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE | - ETSObjectFlags::NULL_TYPE)) { + !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE)) { return; } @@ -660,7 +676,7 @@ void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) } } -Type *ETSObjectType::AsSuper(Checker *checker, varbinder::Variable *source_var) +Type *ETSObjectType::AsSuper(Checker *checker, binder::Variable *source_var) { if (source_var == nullptr) { return nullptr; @@ -712,8 +728,8 @@ Type *ETSObjectType::AsSuper(Checker *checker, varbinder::Variable *source_var) return nullptr; } -varbinder::LocalVariable *ETSObjectType::CopyProperty(varbinder::LocalVariable *prop, ArenaAllocator *allocator, - TypeRelation *relation, GlobalTypesHolder *global_types) +binder::LocalVariable *ETSObjectType::CopyProperty(binder::LocalVariable *prop, ArenaAllocator *allocator, + TypeRelation *relation, GlobalTypesHolder *global_types) { auto *const copied_prop = prop->Copy(allocator, prop->Declaration()); auto *const copied_prop_type = ETSChecker::TryToInstantiate( @@ -764,8 +780,8 @@ Type *ETSObjectType::Instantiate(ArenaAllocator *const allocator, TypeRelation * return copied_type; } -static varbinder::LocalVariable *CopyPropertyWithTypeArguments(varbinder::LocalVariable *prop, TypeRelation *relation, - const Substitution *substitution) +static binder::LocalVariable *CopyPropertyWithTypeArguments(binder::LocalVariable *prop, TypeRelation *relation, + const Substitution *substitution) { auto *const checker = relation->GetChecker()->AsETSChecker(); auto *const copied_prop_type = checker->GetTypeOfVariable(prop)->Substitute(relation, substitution); @@ -825,7 +841,7 @@ Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *subs } // Lambda types can capture type params in their bodies, normal classes cannot. - // NOTE: gogabr. determine precise conditions where we do not need to copy. + // TODO(gogabr): determine precise conditions where we do not need to copy. // Perhaps keep track of captured type parameters for each type. if (!any_change && !HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { return this; diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 8a5d052c309142fbfc9c3b2693a25ce5a0318305..45232d5c8fcdd9bae7b0364f03e730a91698e600 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -20,7 +20,7 @@ #include "checker/types/signature.h" #include "ir/ts/tsInterfaceDeclaration.h" #include "ir/ts/tsTypeParameterDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/base/classDefinition.h" namespace panda::es2panda::checker { @@ -113,9 +113,9 @@ enum class PropertyType { class ETSObjectType : public Type { public: - using PropertyMap = ArenaUnorderedMap; + using PropertyMap = ArenaUnorderedMap; using InstantiationMap = ArenaUnorderedMap; - using PropertyTraverser = std::function; + using PropertyTraverser = std::function; using PropertyHolder = std::array(PropertyType::COUNT)>; explicit ETSObjectType(ArenaAllocator *allocator) : ETSObjectType(allocator, ETSObjectFlags::NO_OPTS) {} @@ -292,14 +292,14 @@ public: return const_cast(GetConstOriginalBaseType()); } - bool IsPropertyInherited(const varbinder::Variable *var) + bool IsPropertyInherited(const binder::Variable *var) { - if (var->HasFlag(varbinder::VariableFlags::PRIVATE)) { + if (var->HasFlag(binder::VariableFlags::PRIVATE)) { return GetProperty(var->Name(), PropertySearchFlags::SEARCH_FIELD | PropertySearchFlags::SEARCH_DECL) == var; } - if (var->HasFlag(varbinder::VariableFlags::PROTECTED)) { + if (var->HasFlag(binder::VariableFlags::PROTECTED)) { return (GetProperty(var->Name(), PropertySearchFlags::SEARCH_FIELD | PropertySearchFlags::SEARCH_DECL) == var) || this->IsPropertyOfAscendant(var); @@ -308,7 +308,7 @@ public: return true; } - bool IsPropertyOfAscendant(const varbinder::Variable *var) + bool IsPropertyOfAscendant(const binder::Variable *var) { if (this->SuperType() == nullptr) { return false; @@ -404,6 +404,7 @@ public: ETSObjectType *GetInstantiatedType(util::StringView hash) { auto found = instantiation_map_.find(hash); + if (found != instantiation_map_.end()) { return found->second; } @@ -411,7 +412,7 @@ public: return nullptr; } - varbinder::Scope *GetTypeArgumentScope() const + binder::Scope *GetTypeArgumentScope() const { if (HasObjectFlag(ETSObjectFlags::ENUM) || !HasTypeFlag(TypeFlag::GENERIC)) { return nullptr; @@ -432,7 +433,7 @@ public: } template - varbinder::LocalVariable *GetOwnProperty(const util::StringView &name) const + binder::LocalVariable *GetOwnProperty(const util::StringView &name) const { EnsurePropertiesInstantiated(); auto found = properties_[static_cast(TYPE)].find(name); @@ -443,7 +444,7 @@ public: } template - void AddProperty(varbinder::LocalVariable *prop) + void AddProperty(binder::LocalVariable *prop) { properties_[static_cast(TYPE)].emplace(prop->Name(), prop); properties_instantiated_ = true; @@ -454,21 +455,20 @@ public: return !type_arguments_.empty(); } - std::vector ForeignProperties() const; - varbinder::LocalVariable *GetProperty(const util::StringView &name, PropertySearchFlags flags) const; - std::vector GetAllProperties() const; + std::vector ForeignProperties() const; + binder::LocalVariable *GetProperty(const util::StringView &name, PropertySearchFlags flags) const; + std::vector GetAllProperties() const; void CreatePropertyMap(ArenaAllocator *allocator); - varbinder::LocalVariable *CopyProperty(varbinder::LocalVariable *prop, ArenaAllocator *allocator, - TypeRelation *relation, GlobalTypesHolder *global_types); - std::vector Methods() const; - std::vector Fields() const; - varbinder::LocalVariable *CreateSyntheticVarFromEverySignature(const util::StringView &name, - PropertySearchFlags flags) const; - varbinder::LocalVariable *CollectSignaturesForSyntheticType(ETSFunctionType *func_type, - const util::StringView &name, + binder::LocalVariable *CopyProperty(binder::LocalVariable *prop, ArenaAllocator *allocator, TypeRelation *relation, + GlobalTypesHolder *global_types); + std::vector Methods() const; + std::vector Fields() const; + binder::LocalVariable *CreateSyntheticVarFromEverySignature(const util::StringView &name, PropertySearchFlags flags) const; + binder::LocalVariable *CollectSignaturesForSyntheticType(ETSFunctionType *func_type, const util::StringView &name, + PropertySearchFlags flags) const; bool CheckIdenticalFlags(ETSObjectFlags target) const; - bool CheckIdenticalVariable(varbinder::Variable *other_var) const; + bool CheckIdenticalVariable(binder::Variable *other_var) const; void Iterate(const PropertyTraverser &cb) const; void ToString(std::stringstream &ss) const override; @@ -478,9 +478,8 @@ public: Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; - bool CastNumericObject(TypeRelation *relation, Type *target); void IsSupertypeOf(TypeRelation *relation, Type *source) override; - Type *AsSuper(Checker *checker, varbinder::Variable *source_var) override; + Type *AsSuper(Checker *checker, binder::Variable *source_var) override; void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override { @@ -509,15 +508,6 @@ public: return allocator_; } - std::tuple ResolveConditionExpr() const override - { - if (IsNullableType() || IsETSStringType()) { - return {false, false}; - } - - return {true, true}; - } - protected: virtual ETSFunctionType *CreateETSFunctionType(const util::StringView &name) const; @@ -548,7 +538,7 @@ private: properties_instantiated_ = true; } } - std::unordered_map CollectAllProperties() const; + std::unordered_map CollectAllProperties() const; void IdenticalUptoNullability(TypeRelation *relation, Type *other); ArenaAllocator *allocator_; diff --git a/ets2panda/checker/types/ets/etsStringType.cpp b/ets2panda/checker/types/ets/etsStringType.cpp index 9f0a1aacae6e0aa087e793172bdc1c63de9a7f13..bd7be06726579198335731b25b56305b64714e5d 100644 --- a/ets2panda/checker/types/ets/etsStringType.cpp +++ b/ets2panda/checker/types/ets/etsStringType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,7 +15,7 @@ #include "etsStringType.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" namespace panda::es2panda::checker { void ETSStringType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/etsStringType.h b/ets2panda/checker/types/ets/etsStringType.h index 5ee82f4377effcd6d811eeb0aa3cce56ed0363af..4a516db40d6a9328261d3aaaaaa64d78953247b3 100644 --- a/ets2panda/checker/types/ets/etsStringType.h +++ b/ets2panda/checker/types/ets/etsStringType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -55,15 +55,6 @@ public: return value_; } - std::tuple ResolveConditionExpr() const override - { - if (IsNullableType()) { - return {false, false}; - } - - return {IsConstantType(), IsConstantType() ? (GetValue().Length() != 0) : false}; - } - private: util::StringView value_ {}; }; diff --git a/ets2panda/checker/types/ets/etsTypeParameter.cpp b/ets2panda/checker/types/ets/etsTypeParameter.cpp index 3c4c2ced73fae5c68ddfa757437ccf2b610b1c40..4a98ab157c2bb1e85ab5c5f7ef8fda84a4fcb060 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsTypeParameter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsTypeParameter.h b/ets2panda/checker/types/ets/etsTypeParameter.h index dcdeb5fae1874f7492152aabcb6bf32e9a231a83..da85393c2baf386866c4cde95f0867635cccc920 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.h +++ b/ets2panda/checker/types/ets/etsTypeParameter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp deleted file mode 100644 index b0addc81fd54c38f60c346cb3057321476d39d3c..0000000000000000000000000000000000000000 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Copyright (c) 2021 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 "etsUnionType.h" -#include "checker/ets/conversion.h" -#include "checker/types/globalTypesHolder.h" -#include "checker/ETSchecker.h" - -namespace panda::es2panda::checker { -void ETSUnionType::ToString(std::stringstream &ss) const -{ - for (auto it = constituent_types_.begin(); it != constituent_types_.end(); it++) { - (*it)->ToString(ss); - if (std::next(it) != constituent_types_.end()) { - ss << " | "; - } - } -} - -bool ETSUnionType::EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target) -{ - return std::all_of(source->constituent_types_.begin(), source->constituent_types_.end(), - [relation, target](auto *s) { return TypeRelatedToSomeType(relation, s, target); }); -} - -bool ETSUnionType::TypeRelatedToSomeType(TypeRelation *relation, Type *source, ETSUnionType *target) -{ - return std::any_of(target->constituent_types_.begin(), target->constituent_types_.end(), - [relation, source](auto *t) { return relation->IsIdenticalTo(source, t); }); -} - -Type *ETSUnionType::GetLeastUpperBoundType(ETSChecker *checker) -{ - ASSERT(constituent_types_.size() > 1); - if (lub_type_ == nullptr) { - lub_type_ = constituent_types_.front(); - for (auto *t : constituent_types_) { - if (!t->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { - lub_type_ = checker->GetGlobalTypesHolder()->GlobalETSObjectType(); - return lub_type_; - } - lub_type_ = checker->FindLeastUpperBound(lub_type_, t); - } - } - return lub_type_; -} - -void ETSUnionType::Identical(TypeRelation *relation, Type *other) -{ - if (other->IsETSUnionType()) { - if (EachTypeRelatedToSomeType(relation, this, other->AsETSUnionType()) && - EachTypeRelatedToSomeType(relation, other->AsETSUnionType(), this)) { - relation->Result(true); - return; - } - } - - relation->Result(false); -} - -bool ETSUnionType::AssignmentSource(TypeRelation *relation, Type *target) -{ - for (auto *it : constituent_types_) { - if (!relation->IsAssignableTo(it, target)) { - return false; - } - } - - relation->Result(true); - return true; -} - -void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) -{ - // For an unsorted constituent_types_, a less suitable type may first come across than it could be - // if the entire array of constituent types was analyzed. - for (auto *it : constituent_types_) { - if (!source->IsETSObjectType() && (source->HasTypeFlag(it->TypeFlags()) || it == source)) { - relation->IsAssignableTo(source, it); - return; - } - } - for (auto *it : constituent_types_) { - if (relation->IsAssignableTo(source, it)) { - return; - } - } -} - -Type *ETSUnionType::HandleUnionType(ETSUnionType *union_type) -{ - if (union_type->ConstituentTypes().size() == 1) { - return union_type->ConstituentTypes()[0]; - } - - return union_type; -} - -Type *ETSUnionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) -{ - ArenaVector copied_constituents(constituent_types_.size(), allocator->Adapter()); - - for (auto *it : constituent_types_) { - copied_constituents.push_back(it->Instantiate(allocator, relation, global_types)); - } - - if (copied_constituents.size() == 1) { - return copied_constituents[0]; - } - - Type *new_union_type = allocator->New(std::move(copied_constituents)); - - lub_type_ = global_types->GlobalETSObjectType(); - return HandleUnionType(new_union_type->AsETSUnionType()); -} - -void ETSUnionType::Cast(TypeRelation *relation, Type *target) -{ - bool is_cast_to_obj = target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT); - for (auto *source : constituent_types_) { - relation->IsCastableTo(source, target); - if (relation->IsTrue()) { - if (is_cast_to_obj && source->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { - GetLeastUpperBoundType(relation->GetChecker()->AsETSChecker())->Cast(relation, target); - return; - } - if (!is_cast_to_obj) { - source->Cast(relation, target); - return; - } - } - } - - conversion::Forbidden(relation); -} - -void ETSUnionType::CastToThis(TypeRelation *relation, Type *source) -{ - Type *target_type = FindTypeIsCastableToThis(relation->GetNode(), relation, source); - if (target_type != nullptr) { - source->Cast(relation, target_type); - return; - } - - conversion::Forbidden(relation); -} - -Type *ETSUnionType::FindTypeIsCastableToThis(ir::Expression *node, TypeRelation *relation, Type *source) const -{ - ASSERT(node); - bool node_was_set = false; - if (relation->GetNode() == nullptr) { - node_was_set = true; - relation->SetNode(node); - } - // Prioritize object to object conversion - auto it = std::find_if(constituent_types_.begin(), constituent_types_.end(), [relation, source](Type *target) { - relation->IsCastableTo(source, target); - return relation->IsTrue() && source->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT) && - target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT); - }); - if (it != constituent_types_.end()) { - if (node_was_set) { - relation->SetNode(nullptr); - } - return *it; - } - it = std::find_if(constituent_types_.begin(), constituent_types_.end(), [relation, source](Type *target) { - relation->IsCastableTo(source, target); - return relation->IsTrue(); - }); - if (node_was_set) { - relation->SetNode(nullptr); - } - if (it != constituent_types_.end()) { - return *it; - } - return nullptr; -} - -Type *ETSUnionType::FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelation *relation, Type *target) const -{ - ASSERT(node); - bool node_was_set = false; - if (relation->GetNode() == nullptr) { - node_was_set = true; - relation->SetNode(node); - relation->SetFlags(TypeRelationFlag::CASTING_CONTEXT); - } - auto is_castable_pred = [](TypeRelation *r, Type *source_type, Type *target_type) { - if (target_type->IsETSUnionType()) { - auto *found_target_type = - target_type->AsETSUnionType()->FindTypeIsCastableToThis(r->GetNode(), r, source_type); - r->Result(found_target_type != nullptr); - } else { - r->IsCastableTo(source_type, target_type); - } - return r->IsTrue(); - }; - // Prioritize object to object conversion - auto it = std::find_if( - constituent_types_.begin(), constituent_types_.end(), [relation, target, &is_castable_pred](Type *source) { - return is_castable_pred(relation, source, target) && source->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT) && - target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT); - }); - if (it != constituent_types_.end()) { - if (node_was_set) { - relation->SetNode(nullptr); - relation->RemoveFlags(TypeRelationFlag::CASTING_CONTEXT); - } - return *it; - } - it = std::find_if( - constituent_types_.begin(), constituent_types_.end(), - [relation, target, &is_castable_pred](Type *source) { return is_castable_pred(relation, source, target); }); - if (node_was_set) { - relation->SetNode(nullptr); - relation->RemoveFlags(TypeRelationFlag::CASTING_CONTEXT); - } - if (it != constituent_types_.end()) { - return *it; - } - return nullptr; -} - -} // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsUnionType.h b/ets2panda/checker/types/ets/etsUnionType.h deleted file mode 100644 index 26760592334537e7e0d073ad612bcb6f01181ca7..0000000000000000000000000000000000000000 --- a/ets2panda/checker/types/ets/etsUnionType.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (c) 2021-2022 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_COMPILER_CHECKER_TYPES_ETS_UNION_TYPE_H -#define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_UNION_TYPE_H - -#include "checker/types/type.h" - -namespace panda::es2panda::checker { -class GlobalTypesHolder; - -class ETSUnionType : public Type { -public: - explicit ETSUnionType(ArenaAllocator *allocator) - : Type(TypeFlag::ETS_UNION), constituent_types_(allocator->Adapter()) - { - } - - explicit ETSUnionType(ArenaVector &&constituent_types) - : Type(TypeFlag::ETS_UNION), constituent_types_(std::move(constituent_types)) - { - } - - explicit ETSUnionType(ArenaVector &constituent_types) - : Type(TypeFlag::ETS_UNION), constituent_types_(constituent_types) - { - } - - const ArenaVector &ConstituentTypes() const - { - return constituent_types_; - } - - ArenaVector &ConstituentTypes() - { - return constituent_types_; - } - - void AddConstituentType(Type *type, TypeRelation *relation) - { - for (auto *it : constituent_types_) { - if (relation->IsIdenticalTo(it, type)) { - return; - } - } - - constituent_types_.push_back(type); - } - - void ToString(std::stringstream &ss) const override; - void Identical(TypeRelation *relation, Type *other) override; - void AssignmentTarget(TypeRelation *relation, Type *source) override; - bool AssignmentSource(TypeRelation *relation, Type *target) override; - Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; - void Cast(TypeRelation *relation, Type *target) override; - void CastToThis(TypeRelation *relation, Type *source); - Type *FindTypeIsCastableToThis(ir::Expression *node, TypeRelation *relation, Type *source) const; - Type *FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelation *relation, Type *target) const; - - Type *GetLeastUpperBoundType(ETSChecker *checker); - - Type *GetLeastUpperBoundType() const - { - ASSERT(lub_type_ != nullptr); - return lub_type_; - } - - static Type *HandleUnionType(ETSUnionType *union_type); - -private: - static bool EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target); - static bool TypeRelatedToSomeType(TypeRelation *relation, Type *source, ETSUnionType *target); - - ArenaVector constituent_types_; - Type *lub_type_ {nullptr}; -}; -} // namespace panda::es2panda::checker - -#endif /* ETS_TYPES_ETS_UNION_TYPE_H */ diff --git a/ets2panda/checker/types/ets/etsVoidType.cpp b/ets2panda/checker/types/ets/etsVoidType.cpp index b25e85b491fe59a62387bb69ae0f7872121024c7..6089cc26b705154683e8277522c5dcb270942006 100644 --- a/ets2panda/checker/types/ets/etsVoidType.cpp +++ b/ets2panda/checker/types/ets/etsVoidType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/etsVoidType.h b/ets2panda/checker/types/ets/etsVoidType.h index 684a85410571db40af3911de69a8da1df46e8ecc..1d68486329860636c0cc8655536458f7b8b50012 100644 --- a/ets2panda/checker/types/ets/etsVoidType.h +++ b/ets2panda/checker/types/ets/etsVoidType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/floatType.cpp b/ets2panda/checker/types/ets/floatType.cpp index 7276907fc2f70f3aa7b3342aa2e4c73c26534d45..d40efa8f09c0f687af01c1abe96895c4a7753755 100644 --- a/ets2panda/checker/types/ets/floatType.cpp +++ b/ets2panda/checker/types/ets/floatType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -82,11 +82,6 @@ void FloatType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/floatType.h b/ets2panda/checker/types/ets/floatType.h index 055fb37fd521a77228d467ac556960290b9b1ba5..513c9b325da92a3c0a48c7596b43a9ae83c302b6 100644 --- a/ets2panda/checker/types/ets/floatType.h +++ b/ets2panda/checker/types/ets/floatType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_FLOAT; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0.0}; }; diff --git a/ets2panda/checker/types/ets/intType.cpp b/ets2panda/checker/types/ets/intType.cpp index 15f93bcbb3bf9c40a9620e572f4facd9bb4bd533..2f4cac76c3f375a99438dcfa1f9a85bf699b7668 100644 --- a/ets2panda/checker/types/ets/intType.cpp +++ b/ets2panda/checker/types/ets/intType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -43,7 +43,7 @@ bool IntType::AssignmentSource([[maybe_unused]] TypeRelation *relation, [[maybe_ } } - if (relation->ApplyBoxing() && (target->IsETSObjectType())) { + if (relation->ApplyBoxing() && target->IsETSObjectType()) { relation->GetChecker()->AsETSChecker()->CheckBoxedSourceTypeAssignable(relation, this, target); } @@ -87,11 +87,6 @@ void IntType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/intType.h b/ets2panda/checker/types/ets/intType.h index fe0e02ee3b2ea4b648e7b1d3c0c408822ee303d7..df8f6af99a43d79d9a9db910540848d94f7e03ed 100644 --- a/ets2panda/checker/types/ets/intType.h +++ b/ets2panda/checker/types/ets/intType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_INT; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0}; }; diff --git a/ets2panda/checker/types/ets/longType.cpp b/ets2panda/checker/types/ets/longType.cpp index 565a22bc1542d7cd2db7a57b46f3a0dcb1cb0ab4..4246b89ccd8132492d15022b85945a346b7b0e20 100644 --- a/ets2panda/checker/types/ets/longType.cpp +++ b/ets2panda/checker/types/ets/longType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -82,11 +82,6 @@ void LongType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/longType.h b/ets2panda/checker/types/ets/longType.h index 8a3546718da96d3a8f9fe6948f190978a271249f..27a2deca699ce7dc662970de1a834dc77bb3e77f 100644 --- a/ets2panda/checker/types/ets/longType.h +++ b/ets2panda/checker/types/ets/longType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_LONG; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0}; }; diff --git a/ets2panda/checker/types/ets/shortType.cpp b/ets2panda/checker/types/ets/shortType.cpp index 69f2d0014cc12d534ce2d23a5f1efecd662e3f4a..8cd1be7202dde5d5a64436f3263c3b7618c838b1 100644 --- a/ets2panda/checker/types/ets/shortType.cpp +++ b/ets2panda/checker/types/ets/shortType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -82,11 +82,6 @@ void ShortType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->IsETSUnionType()) { - target->AsETSUnionType()->CastToThis(relation, this); - return; - } - conversion::Forbidden(relation); } diff --git a/ets2panda/checker/types/ets/shortType.h b/ets2panda/checker/types/ets/shortType.h index b5ab753ebc5c3388ea594ac2dd7bbf1cf4f8597b..287c0424247afe07b9a2e6a1acdc916202044808 100644 --- a/ets2panda/checker/types/ets/shortType.h +++ b/ets2panda/checker/types/ets/shortType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -52,11 +52,6 @@ public: ss << compiler::Signatures::TYPE_DESCRIPTOR_SHORT; } - std::tuple ResolveConditionExpr() const override - { - return {IsConstantType(), value_ != 0}; - } - private: UType value_ {0}; }; diff --git a/ets2panda/checker/types/ets/types.h b/ets2panda/checker/types/ets/types.h index 1f798ee532f0073398218b8c14b9eb951315b8fc..24bd24e69a5c5be2033028e4c37926b357f957e5 100644 --- a/ets2panda/checker/types/ets/types.h +++ b/ets2panda/checker/types/ets/types.h @@ -27,7 +27,6 @@ #include "etsEnumType.h" #include "etsExtensionFuncHelperType.h" #include "etsFunctionType.h" -#include "etsUnionType.h" #include "etsVoidType.h" #include "etsStringType.h" #include "etsObjectType.h" diff --git a/ets2panda/checker/types/ets/wildcardType.cpp b/ets2panda/checker/types/ets/wildcardType.cpp index 1b71b48b8588fa79b2caccde795108d6cd66f537..fd5af24b962fd948dc2d68b754d1917d073f4a14 100644 --- a/ets2panda/checker/types/ets/wildcardType.cpp +++ b/ets2panda/checker/types/ets/wildcardType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/ets/wildcardType.h b/ets2panda/checker/types/ets/wildcardType.h index 4c627d523e5cdf45173809a011dd8f63b486513a..910c8bfa54f803d54f59078aa4cf8b7e9f65da48 100644 --- a/ets2panda/checker/types/ets/wildcardType.h +++ b/ets2panda/checker/types/ets/wildcardType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/checker/types/signature.cpp b/ets2panda/checker/types/signature.cpp index ab2188c6c0b438324f968af76af314a0ccda0cf7..b07db6030e7135a327a64880f17d32ccd9159c58 100644 --- a/ets2panda/checker/types/signature.cpp +++ b/ets2panda/checker/types/signature.cpp @@ -15,7 +15,7 @@ #include "signature.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/base/scriptFunction.h" #include "ir/ts/tsTypeParameter.h" #include "checker/ETSchecker.h" @@ -118,7 +118,7 @@ Signature *Signature::Copy(ArenaAllocator *allocator, TypeRelation *relation, Gl return copied_signature; } -void Signature::ToString(std::stringstream &ss, const varbinder::Variable *variable, bool print_as_method) const +void Signature::ToString(std::stringstream &ss, const binder::Variable *variable, bool print_as_method) const { if (!signature_info_->type_params.empty()) { ss << "<"; @@ -136,7 +136,7 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia for (auto it = signature_info_->params.begin(); it != signature_info_->params.end(); it++) { ss << (*it)->Name(); - if ((*it)->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if ((*it)->HasFlag(binder::VariableFlags::OPTIONAL)) { ss << "?"; } @@ -163,7 +163,7 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia ss << ")"; - if (print_as_method || (variable != nullptr && variable->HasFlag(varbinder::VariableFlags::METHOD))) { + if (print_as_method || (variable != nullptr && variable->HasFlag(binder::VariableFlags::METHOD))) { ss << ": "; } else { ss << " => "; @@ -210,10 +210,10 @@ void Signature::Identical(TypeRelation *relation, Signature *other) } // Lambda to check the rest parameters - auto const identical_rest_parameters = - [&i, &identical_parameters, relation](std::size_t const parameter_number, - ArenaVector const ¶meters, - varbinder::LocalVariable const *const rest_parameter) -> void { + auto const identical_rest_parameters = [&i, &identical_parameters, + relation](std::size_t const parameter_number, + ArenaVector const ¶meters, + binder::LocalVariable const *const rest_parameter) -> void { if (rest_parameter != nullptr) { auto *const other_sig_param_type = rest_parameter->TsType()->AsETSArrayType()->ElementType(); diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index 2341dd57456f0972044b51d5a2a87dba7cce9f97..ac683bdc90f7928b665e1de65bc2fec99eca43d3 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -18,12 +18,12 @@ #include "type.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/core/compilerContext.h" namespace panda::es2panda::checker { // For use in Signature::ToAssemblerType -Type const *MaybeBoxedType(Checker *checker, varbinder::Variable const *var); +Type const *MaybeBoxedType(Checker *checker, binder::Variable const *var); class SignatureInfo { public: @@ -57,8 +57,8 @@ public: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) ArenaVector type_params; uint32_t min_arg_count {}; - varbinder::LocalVariable *rest_var {}; - ArenaVector params; + binder::LocalVariable *rest_var {}; + ArenaVector params; // NOLINTEND(misc-non-private-member-variables-in-classes) }; @@ -118,12 +118,12 @@ public: return signature_info_; } - const ArenaVector &Params() const + const ArenaVector &Params() const { return signature_info_->params; } - ArenaVector &Params() + ArenaVector &Params() { return signature_info_->params; } @@ -158,7 +158,7 @@ public: owner_obj_ = owner; } - void SetOwnerVar(varbinder::Variable *owner) + void SetOwnerVar(binder::Variable *owner) { owner_var_ = owner; } @@ -178,7 +178,7 @@ public: return owner_obj_; } - varbinder::Variable *OwnerVar() + binder::Variable *OwnerVar() { return owner_var_; } @@ -188,7 +188,7 @@ public: return func_; } - const varbinder::LocalVariable *RestVar() const + const binder::LocalVariable *RestVar() const { return signature_info_->rest_var; } @@ -196,11 +196,11 @@ public: uint8_t ProtectionFlag() const { if ((flags_ & SignatureFlags::PRIVATE) != 0) { - return 2U; + return 2; } if ((flags_ & SignatureFlags::PROTECTED) != 0) { - return 1U; + return 1; } return 0; @@ -244,7 +244,7 @@ public: Signature *Copy(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types); Signature *Substitute(TypeRelation *relation, const Substitution *substitution); - void ToString(std::stringstream &ss, const varbinder::Variable *variable, bool print_as_method = false) const; + void ToString(std::stringstream &ss, const binder::Variable *variable, bool print_as_method = false) const; void Identical(TypeRelation *relation, Signature *other); bool CheckFunctionalInterfaces(TypeRelation *relation, Type *source, Type *target); void AssignmentTarget(TypeRelation *relation, Signature *source); @@ -256,7 +256,7 @@ private: SignatureFlags flags_ {SignatureFlags::NO_OPTS}; util::StringView internal_name_ {}; ETSObjectType *owner_obj_ {}; - varbinder::Variable *owner_var_ {}; + binder::Variable *owner_var_ {}; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ts/arrayType.cpp b/ets2panda/checker/types/ts/arrayType.cpp index 78e642178da7c4eaa66aa0fd9f3096ee2d8a8119..7aa4b9eabfa145e6987c7a51a366bf025cf460d5 100644 --- a/ets2panda/checker/types/ts/arrayType.cpp +++ b/ets2panda/checker/types/ts/arrayType.cpp @@ -15,7 +15,7 @@ #include "arrayType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/objectType.h" namespace panda::es2panda::checker { diff --git a/ets2panda/checker/types/ts/enumLiteralType.cpp b/ets2panda/checker/types/ts/enumLiteralType.cpp index f0d097f4831dd00567ab30ad2e65696e8d18a936..f89b9745eaa4d4649c5a2bbed47f00140b7ecc9d 100644 --- a/ets2panda/checker/types/ts/enumLiteralType.cpp +++ b/ets2panda/checker/types/ts/enumLiteralType.cpp @@ -15,7 +15,7 @@ #include "enumLiteralType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { diff --git a/ets2panda/checker/types/ts/enumLiteralType.h b/ets2panda/checker/types/ts/enumLiteralType.h index 5c0d92a92df46a42f49cdeb533606ed5cea5335d..596f79fc0e111fab5b4e9443491c2501a44060f8 100644 --- a/ets2panda/checker/types/ts/enumLiteralType.h +++ b/ets2panda/checker/types/ts/enumLiteralType.h @@ -18,26 +18,26 @@ #include "checker/types/type.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Scope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class EnumLiteralType : public Type { public: enum class EnumLiteralTypeKind { NUMERIC, LITERAL }; - EnumLiteralType(util::StringView name, varbinder::Scope *scope, EnumLiteralTypeKind kind) + EnumLiteralType(util::StringView name, binder::Scope *scope, EnumLiteralTypeKind kind) : Type(TypeFlag::ENUM_LITERAL), name_(name), scope_(scope), kind_(kind) { } - varbinder::Scope *Scope() + binder::Scope *Scope() { return scope_; } - const varbinder::Scope *Scope() const + const binder::Scope *Scope() const { return scope_; } @@ -56,7 +56,7 @@ public: private: util::StringView name_; - varbinder::Scope *scope_; + binder::Scope *scope_; EnumLiteralTypeKind kind_; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ts/enumType.cpp b/ets2panda/checker/types/ts/enumType.cpp index 69a7be5132683f85b6cc916ffd3d36ac58b18d42..dabd5567cc8eb1fa6b2d1084ffe73a0d4531169c 100644 --- a/ets2panda/checker/types/ts/enumType.cpp +++ b/ets2panda/checker/types/ts/enumType.cpp @@ -15,7 +15,7 @@ #include "enumType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" namespace panda::es2panda::checker { void EnumType::ToString(std::stringstream &ss) const @@ -25,7 +25,7 @@ void EnumType::ToString(std::stringstream &ss) const void EnumType::Identical([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other) { - // NOTE: aszilagyi + // TODO(aszilagyi) } void EnumType::AssignmentTarget(TypeRelation *relation, Type *source) @@ -37,14 +37,14 @@ void EnumType::AssignmentTarget(TypeRelation *relation, Type *source) TypeFacts EnumType::GetTypeFacts() const { - // NOTE: aszilagyi + // TODO(aszilagyi) return TypeFacts::NUMBER_FACTS; } Type *EnumType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, [[maybe_unused]] GlobalTypesHolder *global_types) { - // NOTE: aszilagyi + // TODO(aszilagyi) return this; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ts/enumType.h b/ets2panda/checker/types/ts/enumType.h index 5accd1eea5b1e9ef7ce491db8bb525091ea4c7cd..60aadce2bd94aaf39b743a40ff8e3a5ca0850aa4 100644 --- a/ets2panda/checker/types/ts/enumType.h +++ b/ets2panda/checker/types/ts/enumType.h @@ -18,24 +18,24 @@ #include "checker/types/type.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class EnumVariable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class EnumType : public Type { public: - EnumType(varbinder::Variable *enum_literal_var, varbinder::EnumVariable *enum_var) + EnumType(binder::Variable *enum_literal_var, binder::EnumVariable *enum_var) : Type(TypeFlag::ENUM), enum_literal_var_(enum_literal_var), enum_var_(enum_var) { } - const varbinder::Variable *EnumLiteralVar() const + const binder::Variable *EnumLiteralVar() const { return enum_literal_var_; } - const varbinder::EnumVariable *EnumVar() const + const binder::EnumVariable *EnumVar() const { return enum_var_; } @@ -47,8 +47,8 @@ public: Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; private: - varbinder::Variable *enum_literal_var_; - varbinder::EnumVariable *enum_var_; + binder::Variable *enum_literal_var_; + binder::EnumVariable *enum_var_; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ts/interfaceType.cpp b/ets2panda/checker/types/ts/interfaceType.cpp index 03e7f5e131e74646818aadc91c0ea6e96da7ba74..78dfefa0a381206f2f9c10bb72ab57b80a9dabb1 100644 --- a/ets2panda/checker/types/ts/interfaceType.cpp +++ b/ets2panda/checker/types/ts/interfaceType.cpp @@ -15,7 +15,7 @@ #include "interfaceType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/checker.h" #include "checker/types/ts/typeParameter.h" @@ -50,8 +50,8 @@ void InterfaceType::Identical(TypeRelation *relation, Type *other) InterfaceType *other_interface = other->AsObjectType()->AsInterfaceType(); - const ArenaVector &target_properties = Properties(); - const ArenaVector &source_properties = other_interface->Properties(); + const ArenaVector &target_properties = Properties(); + const ArenaVector &source_properties = other_interface->Properties(); if (target_properties.size() != source_properties.size()) { relation->Result(false); @@ -61,7 +61,7 @@ void InterfaceType::Identical(TypeRelation *relation, Type *other) for (auto *target_prop : target_properties) { bool found_prop = std::any_of(source_properties.begin(), source_properties.end(), - [target_prop, relation](varbinder::LocalVariable *source_prop) { + [target_prop, relation](binder::LocalVariable *source_prop) { if (target_prop->Name() == source_prop->Name()) { Type *target_type = relation->GetChecker()->GetTypeOfVariable(target_prop); Type *source_type = relation->GetChecker()->GetTypeOfVariable(source_prop); @@ -160,7 +160,7 @@ void InterfaceType::CollectSignatures(ArenaVector *collected_signat } } -void InterfaceType::CollectProperties(ArenaVector *collected_properties) const +void InterfaceType::CollectProperties(ArenaVector *collected_properties) const { for (auto *current_prop : desc_->properties) { bool prop_already_collected = false; diff --git a/ets2panda/checker/types/ts/interfaceType.h b/ets2panda/checker/types/ts/interfaceType.h index 5fd9f12c2564240ff1f5cb9ffbe4458ceba9a78a..4db02efb914574a5d40148c6a694094f59a6dd4e 100644 --- a/ets2panda/checker/types/ts/interfaceType.h +++ b/ets2panda/checker/types/ts/interfaceType.h @@ -44,12 +44,12 @@ public: return name_; } - void SetMergedTypeParams(std::pair, size_t> &&merged_type_params) + void SetMergedTypeParams(std::pair, size_t> &&merged_type_params) { merged_type_params_ = std::move(merged_type_params); } - const std::pair, size_t> &GetMergedTypeParams() const + const std::pair, size_t> &GetMergedTypeParams() const { return merged_type_params_; } @@ -64,10 +64,10 @@ public: return type_param_types_; } - varbinder::LocalVariable *GetProperty(const util::StringView &name, - [[maybe_unused]] bool search_in_base) const override + binder::LocalVariable *GetProperty(const util::StringView &name, + [[maybe_unused]] bool search_in_base) const override { - varbinder::LocalVariable *result_prop = ObjectType::GetProperty(name, false); + binder::LocalVariable *result_prop = ObjectType::GetProperty(name, false); if (result_prop != nullptr) { return result_prop; @@ -121,9 +121,9 @@ public: return FindIndexInfo(true); } - ArenaVector Properties() override + ArenaVector Properties() override { - ArenaVector properties(allocator_->Adapter()); + ArenaVector properties(allocator_->Adapter()); CollectProperties(&properties); return properties; } @@ -134,7 +134,7 @@ public: Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; void CollectSignatures(ArenaVector *collected_signatures, bool collect_call_signatures) const; - void CollectProperties(ArenaVector *collected_properties) const; + void CollectProperties(ArenaVector *collected_properties) const; const IndexInfo *FindIndexInfo(bool find_number_info) const; IndexInfo *FindIndexInfo(bool find_number_info); @@ -142,7 +142,7 @@ private: util::StringView name_; ArenaVector bases_; ArenaAllocator *allocator_; - std::pair, size_t> merged_type_params_ {}; + std::pair, size_t> merged_type_params_ {}; std::vector type_param_types_ {}; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ts/numberLiteralType.cpp b/ets2panda/checker/types/ts/numberLiteralType.cpp index 9d69f691c72d1362024d4eebeeeec481488dc6fc..a396052d1d5dc9722c753d50bacf98b36954baf6 100644 --- a/ets2panda/checker/types/ts/numberLiteralType.cpp +++ b/ets2panda/checker/types/ts/numberLiteralType.cpp @@ -16,7 +16,7 @@ #include "numberLiteralType.h" #include "util/helpers.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { @@ -41,7 +41,7 @@ void NumberLiteralType::AssignmentTarget(TypeRelation *relation, Type *source) { if (source->IsEnumType()) { const EnumType *source_enum_type = source->AsEnumType(); - const varbinder::EnumVariable *enum_var = source_enum_type->EnumVar(); + const binder::EnumVariable *enum_var = source_enum_type->EnumVar(); if (std::holds_alternative(enum_var->Value()) && value_ == std::get(enum_var->Value())) { relation->Result(true); diff --git a/ets2panda/checker/types/ts/numberType.cpp b/ets2panda/checker/types/ts/numberType.cpp index 67db73f6afd01ad442c44fd9a61f890c789dabc3..f49a00670e64d369c7f908c1e1651056a3269fc8 100644 --- a/ets2panda/checker/types/ts/numberType.cpp +++ b/ets2panda/checker/types/ts/numberType.cpp @@ -15,7 +15,7 @@ #include "numberType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { @@ -37,7 +37,7 @@ void NumberType::AssignmentTarget(TypeRelation *relation, Type *source) relation->Result(true); } else if (source->IsEnumType()) { const EnumType *source_enum_type = source->AsEnumType(); - const varbinder::EnumVariable *enum_var = source_enum_type->EnumVar(); + const binder::EnumVariable *enum_var = source_enum_type->EnumVar(); if (std::holds_alternative(enum_var->Value())) { relation->Result(true); diff --git a/ets2panda/checker/types/ts/objectDescriptor.cpp b/ets2panda/checker/types/ts/objectDescriptor.cpp index bac05c06cc9a69e6887990b54787a2fb3843b76e..c47da6be2541b21352da156672cb44012ca94074 100644 --- a/ets2panda/checker/types/ts/objectDescriptor.cpp +++ b/ets2panda/checker/types/ts/objectDescriptor.cpp @@ -15,12 +15,12 @@ #include "objectDescriptor.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/indexInfo.h" #include "checker/types/signature.h" namespace panda::es2panda::checker { -varbinder::LocalVariable *ObjectDescriptor::FindProperty(const util::StringView &name) const +binder::LocalVariable *ObjectDescriptor::FindProperty(const util::StringView &name) const { for (auto *it : properties) { if (it->Name() == name) { diff --git a/ets2panda/checker/types/ts/objectDescriptor.h b/ets2panda/checker/types/ts/objectDescriptor.h index 67a594e1770f71356fc93e55f1543f5f62fbadd9..c1ebc3891be4ffdfe130a6b51c5396db1e3e37a1 100644 --- a/ets2panda/checker/types/ts/objectDescriptor.h +++ b/ets2panda/checker/types/ts/objectDescriptor.h @@ -20,9 +20,9 @@ #include "util/ustring.h" #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LocalVariable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class Signature; @@ -44,12 +44,12 @@ public: NO_COPY_SEMANTIC(ObjectDescriptor); NO_MOVE_SEMANTIC(ObjectDescriptor); - varbinder::LocalVariable *FindProperty(const util::StringView &name) const; + binder::LocalVariable *FindProperty(const util::StringView &name) const; void Copy(ArenaAllocator *allocator, ObjectDescriptor *copied_desc, TypeRelation *relation, GlobalTypesHolder *global_types); // NOLINTBEGIN(misc-non-private-member-variables-in-classes) - ArenaVector properties; + ArenaVector properties; ArenaVector call_signatures; ArenaVector construct_signatures; IndexInfo *string_index_info {}; diff --git a/ets2panda/checker/types/ts/objectLiteralType.cpp b/ets2panda/checker/types/ts/objectLiteralType.cpp index 44c84847f078bc506e1400528e0a0d8832e7e3fd..20f4cadfb235b832d467fb704cb5e6c7b3c1b828 100644 --- a/ets2panda/checker/types/ts/objectLiteralType.cpp +++ b/ets2panda/checker/types/ts/objectLiteralType.cpp @@ -15,7 +15,7 @@ #include "objectLiteralType.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/indexInfo.h" #include "checker/types/signature.h" @@ -48,15 +48,15 @@ void ObjectLiteralType::ToString(std::stringstream &ss) const } for (auto *it : desc_->properties) { - if (it->HasFlag(varbinder::VariableFlags::READONLY)) { + if (it->HasFlag(binder::VariableFlags::READONLY)) { ss << "readonly "; } ss << it->Name(); - if (it->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if (it->HasFlag(binder::VariableFlags::OPTIONAL)) { ss << "?"; } - if (it->HasFlag(varbinder::VariableFlags::PROPERTY)) { + if (it->HasFlag(binder::VariableFlags::PROPERTY)) { ss << ": "; } diff --git a/ets2panda/checker/types/ts/objectType.cpp b/ets2panda/checker/types/ts/objectType.cpp index 860e515e3ceec71bf777ec8937323bde4c86d5f4..a5cea0d8ae5d395c76d8b573c66eef20f8286aaf 100644 --- a/ets2panda/checker/types/ts/objectType.cpp +++ b/ets2panda/checker/types/ts/objectType.cpp @@ -67,7 +67,7 @@ void ObjectType::Identical(TypeRelation *relation, Type *other) } for (auto *it : desc_->properties) { - varbinder::LocalVariable *found = other_obj->Desc()->FindProperty(it->Name()); + binder::LocalVariable *found = other_obj->Desc()->FindProperty(it->Name()); if (found == nullptr) { relation->Result(false); return; @@ -112,12 +112,12 @@ void ObjectType::Identical(TypeRelation *relation, Type *other) void ObjectType::AssignProperties(TypeRelation *relation, ObjectType *source) { - const ArenaVector &target_properties = Properties(); + const ArenaVector &target_properties = Properties(); IndexInfo *number_info = NumberIndexInfo(); IndexInfo *string_info = StringIndexInfo(); for (auto *it : target_properties) { - varbinder::LocalVariable *found = source->GetProperty(it->Name(), true); + binder::LocalVariable *found = source->GetProperty(it->Name(), true); Type *target_type = relation->GetChecker()->GetTypeOfVariable(it); if (found != nullptr) { @@ -127,8 +127,7 @@ void ObjectType::AssignProperties(TypeRelation *relation, ObjectType *source) return; } - if (found->HasFlag(varbinder::VariableFlags::OPTIONAL) && - !it->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if (found->HasFlag(binder::VariableFlags::OPTIONAL) && !it->HasFlag(binder::VariableFlags::OPTIONAL)) { relation->Result(false); return; } @@ -136,7 +135,7 @@ void ObjectType::AssignProperties(TypeRelation *relation, ObjectType *source) continue; } - if (number_info != nullptr && it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME) && + if (number_info != nullptr && it->HasFlag(binder::VariableFlags::NUMERIC_NAME) && !relation->IsAssignableTo(number_info->GetType(), target_type)) { return; } @@ -145,7 +144,7 @@ void ObjectType::AssignProperties(TypeRelation *relation, ObjectType *source) return; } - if (!it->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if (!it->HasFlag(binder::VariableFlags::OPTIONAL)) { relation->Result(false); return; } @@ -188,7 +187,7 @@ void ObjectType::AssignIndexInfo([[maybe_unused]] TypeRelation *relation, Object } for (auto *it : source->Properties()) { - if (assign_number_info && !it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME)) { + if (assign_number_info && !it->HasFlag(binder::VariableFlags::NUMERIC_NAME)) { continue; } @@ -204,7 +203,7 @@ void ObjectType::CheckExcessProperties(TypeRelation *relation, ObjectType *sourc for (auto *it : source->Properties()) { auto *found = GetProperty(it->Name(), true); - if (found != nullptr || (it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME) && NumberIndexInfo() != nullptr) || + if (found != nullptr || (it->HasFlag(binder::VariableFlags::NUMERIC_NAME) && NumberIndexInfo() != nullptr) || StringIndexInfo() != nullptr) { continue; } @@ -229,17 +228,6 @@ void ObjectType::AssignmentTarget(TypeRelation *relation, Type *source) CheckExcessProperties(relation, source_obj); } - // Just to avoid extra nesting level(s): - auto const assign_index_info = [this, relation, source_obj]() -> void { - if (relation->IsTrue()) { - AssignIndexInfo(relation, source_obj); - - if (relation->IsTrue()) { - AssignIndexInfo(relation, source_obj, false); - } - } - }; - if (relation->IsTrue()) { AssignProperties(relation, source_obj); @@ -249,7 +237,13 @@ void ObjectType::AssignmentTarget(TypeRelation *relation, Type *source) if (relation->IsTrue()) { AssignSignatures(relation, source_obj, false); - assign_index_info(); + if (relation->IsTrue()) { + AssignIndexInfo(relation, source_obj); + + if (relation->IsTrue()) { + AssignIndexInfo(relation, source_obj, false); + } + } } } } diff --git a/ets2panda/checker/types/ts/objectType.h b/ets2panda/checker/types/ts/objectType.h index 6c196b8cc8e890ef7463fdb1558f9f31e5ddaea2..b7d76ae4ee7cd162fea76b2c485981cb217dd0a9 100644 --- a/ets2panda/checker/types/ts/objectType.h +++ b/ets2panda/checker/types/ts/objectType.h @@ -19,7 +19,7 @@ #include "checker/types/type.h" #include "checker/types/ts/objectDescriptor.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "util/ustring.h" #include "util/enumbitops.h" @@ -121,7 +121,7 @@ public: return desc_->number_index_info; } - virtual ArenaVector Properties() + virtual ArenaVector Properties() { return desc_->properties; } @@ -136,13 +136,12 @@ public: return desc_; } - void AddProperty(varbinder::LocalVariable *prop) + void AddProperty(binder::LocalVariable *prop) { desc_->properties.push_back(prop); } - virtual varbinder::LocalVariable *GetProperty(const util::StringView &name, - [[maybe_unused]] bool search_in_base) const + virtual binder::LocalVariable *GetProperty(const util::StringView &name, [[maybe_unused]] bool search_in_base) const { for (auto *it : desc_->properties) { if (name == it->Name()) { diff --git a/ets2panda/checker/types/ts/tupleType.cpp b/ets2panda/checker/types/ts/tupleType.cpp index 8e278973daf45087945afb3d2c217e2e395c3541..594228dd2a45435408868c222080d5bee0e85ed6 100644 --- a/ets2panda/checker/types/ts/tupleType.cpp +++ b/ets2panda/checker/types/ts/tupleType.cpp @@ -40,7 +40,7 @@ void TupleType::ToString(std::stringstream &ss) const if (named_members_.empty()) { for (auto it = desc_->properties.begin(); it != desc_->properties.end(); it++) { (*it)->TsType()->ToString(ss); - if ((*it)->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if ((*it)->HasFlag(binder::VariableFlags::OPTIONAL)) { ss << "?"; } @@ -53,7 +53,7 @@ void TupleType::ToString(std::stringstream &ss) const const util::StringView &member_name = FindNamedMemberName(*it); ss << member_name; - if ((*it)->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if ((*it)->HasFlag(binder::VariableFlags::OPTIONAL)) { ss << "?"; } @@ -70,28 +70,26 @@ void TupleType::ToString(std::stringstream &ss) const void TupleType::Identical(TypeRelation *relation, Type *other) { - if (!other->IsObjectType() || !other->AsObjectType()->IsTupleType()) { - return; - } - - TupleType *other_tuple = other->AsObjectType()->AsTupleType(); - if (kind_ == other_tuple->Kind() && desc_->properties.size() == other_tuple->Properties().size()) { - for (size_t i = 0; i < desc_->properties.size(); i++) { - varbinder::LocalVariable *target_prop = desc_->properties[i]; - varbinder::LocalVariable *source_prop = other_tuple->Properties()[i]; - - if (target_prop->Flags() != source_prop->Flags()) { - relation->Result(false); - return; - } - - relation->IsIdenticalTo(target_prop->TsType(), source_prop->TsType()); - - if (!relation->IsTrue()) { - return; + if (other->IsObjectType() && other->AsObjectType()->IsTupleType()) { + TupleType *other_tuple = other->AsObjectType()->AsTupleType(); + if (kind_ == other_tuple->Kind() && desc_->properties.size() == other_tuple->Properties().size()) { + for (size_t i = 0; i < desc_->properties.size(); i++) { + binder::LocalVariable *target_prop = desc_->properties[i]; + binder::LocalVariable *source_prop = other_tuple->Properties()[i]; + + if (target_prop->Flags() != source_prop->Flags()) { + relation->Result(false); + return; + } + + relation->IsIdenticalTo(target_prop->TsType(), source_prop->TsType()); + + if (!relation->IsTrue()) { + return; + } } + relation->Result(true); } - relation->Result(true); } } @@ -115,8 +113,8 @@ void TupleType::AssignmentTarget(TypeRelation *relation, Type *source) auto *target_prop = desc_->properties[i]; if (i < source_properties.size()) { - if (!target_prop->HasFlag(varbinder::VariableFlags::OPTIONAL) && - source_properties[i]->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if (!target_prop->HasFlag(binder::VariableFlags::OPTIONAL) && + source_properties[i]->HasFlag(binder::VariableFlags::OPTIONAL)) { relation->Result(false); return; } @@ -130,7 +128,7 @@ void TupleType::AssignmentTarget(TypeRelation *relation, Type *source) continue; } - if (!target_prop->HasFlag(varbinder::VariableFlags::OPTIONAL)) { + if (!target_prop->HasFlag(binder::VariableFlags::OPTIONAL)) { relation->Result(false); return; } diff --git a/ets2panda/checker/types/ts/tupleType.h b/ets2panda/checker/types/ts/tupleType.h index afe6946eeeaf067a41fd5759e82427e1774ad2a7..7d0183d647d34f28cd24e727708977c4b2655098 100644 --- a/ets2panda/checker/types/ts/tupleType.h +++ b/ets2panda/checker/types/ts/tupleType.h @@ -18,12 +18,12 @@ #include "macros.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ts/elementFlags.h" #include "checker/types/ts/objectType.h" namespace panda::es2panda::checker { -using NamedTupleMemberPool = ArenaUnorderedMap; +using NamedTupleMemberPool = ArenaUnorderedMap; class TupleType : public ObjectType { public: @@ -44,7 +44,7 @@ public: { if (readonly_) { for (auto *it : Properties()) { - it->AddFlag(varbinder::VariableFlags::READONLY); + it->AddFlag(binder::VariableFlags::READONLY); } } } @@ -79,7 +79,7 @@ public: return named_members_; } - const util::StringView &FindNamedMemberName(varbinder::LocalVariable *member) const + const util::StringView &FindNamedMemberName(binder::LocalVariable *member) const { auto res = named_members_.find(member); return res->second; diff --git a/ets2panda/checker/types/ts/unionType.cpp b/ets2panda/checker/types/ts/unionType.cpp index b10f5f5b6cf605e0cd26aa8cd313f8abc9ef44b9..b20105533dd381c2d48422ab8c2044cff64a4080 100644 --- a/ets2panda/checker/types/ts/unionType.cpp +++ b/ets2panda/checker/types/ts/unionType.cpp @@ -152,7 +152,7 @@ void UnionType::RemoveRedundantLiteralTypesFromUnion(UnionType *type) } auto &constituent_types = type->ConstituentTypes(); - /* NOTE: dbatyai. use std::erase_if */ + /* TODO(dbatyai): use std::erase_if */ auto it = constituent_types.begin(); while (it != constituent_types.end()) { if ((remove_number_literals && (*it)->IsNumberLiteralType()) || diff --git a/ets2panda/checker/types/ts/unionType.h b/ets2panda/checker/types/ts/unionType.h index 6fbeaf082d45a53bb23bf06c7f884d604d02f0a2..0b519d582b1ed973cedbf04ca877e3f738f48836 100644 --- a/ets2panda/checker/types/ts/unionType.h +++ b/ets2panda/checker/types/ts/unionType.h @@ -101,7 +101,7 @@ public: return (constituent_flags_ & flag) != 0; } - ArenaUnorderedMap &CachedSyntheticProperties() + ArenaUnorderedMap &CachedSyntheticProperties() { return cached_synthetic_properties_; } @@ -133,7 +133,7 @@ private: ArenaVector constituent_types_; TypeFlag constituent_flags_ {TypeFlag::NONE}; - ArenaUnorderedMap cached_synthetic_properties_; + ArenaUnorderedMap cached_synthetic_properties_; ObjectType *merged_object_type_ {}; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/type.cpp b/ets2panda/checker/types/type.cpp index 3de0f71ec74810480cfcf7831207979d6db427fc..35d135fc7fa5896097d26357de5ab1e870ec3690 100644 --- a/ets2panda/checker/types/type.cpp +++ b/ets2panda/checker/types/type.cpp @@ -84,7 +84,7 @@ void Type::IsSupertypeOf(TypeRelation *const relation, [[maybe_unused]] Type *so relation->Result(false); } -Type *Type::AsSuper([[maybe_unused]] Checker *checker, [[maybe_unused]] varbinder::Variable *source_var) +Type *Type::AsSuper([[maybe_unused]] Checker *checker, [[maybe_unused]] binder::Variable *source_var) { return nullptr; } diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index 98378f18920fe5ace27e63aeb926f1aa1855ad0d..2c6d11a786a3deb0f9be83dfdd7ef7fae5b8feb8 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -25,9 +25,9 @@ #include #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class ObjectDescriptor; @@ -145,16 +145,6 @@ public: return reinterpret_cast(this); } - bool IsConditionalExprType() const - { - return HasTypeFlag(TypeFlag::CONDITION_EXPRESSION_TYPE); - } - - bool IsConstantType() const - { - return HasTypeFlag(checker::TypeFlag::CONSTANT); - } - TypeFlag TypeFlags() const { return type_flags_; @@ -180,17 +170,17 @@ public: return id_; } - void SetVariable(varbinder::Variable *variable) + void SetVariable(binder::Variable *variable) { variable_ = variable; } - varbinder::Variable *Variable() + binder::Variable *Variable() { return variable_; } - const varbinder::Variable *Variable() const + const binder::Variable *Variable() const { return variable_; } @@ -218,18 +208,13 @@ public: return 0; } - virtual std::tuple ResolveConditionExpr() const - { - UNREACHABLE(); - }; - virtual void Identical(TypeRelation *relation, Type *other); virtual void AssignmentTarget(TypeRelation *relation, Type *source) = 0; virtual bool AssignmentSource(TypeRelation *relation, Type *target); virtual void Compare(TypeRelation *relation, Type *other); virtual void Cast(TypeRelation *relation, Type *target); virtual void IsSupertypeOf(TypeRelation *relation, Type *source); - virtual Type *AsSuper(Checker *checker, varbinder::Variable *source_var); + virtual Type *AsSuper(Checker *checker, binder::Variable *source_var); virtual Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types); virtual Type *Substitute(TypeRelation *relation, const Substitution *substitution); @@ -237,7 +222,7 @@ public: protected: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) TypeFlag type_flags_; - varbinder::Variable *variable_ {}; // Variable associated with the type if any + binder::Variable *variable_ {}; // Variable associated with the type if any uint64_t id_; // NOLINTEND(misc-non-private-member-variables-in-classes) }; diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index bf8c29c6aa6d3073b73a40775f212be4b32d61fb..5bc36dad5cc0f7d65d7230392a56ebf5d5df97a8 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -79,7 +79,6 @@ enum class TypeFlag : uint64_t { GETTER = 1ULL << 54ULL, // ETS Getter SETTER = 1ULL << 55ULL, // ETS Setter ETS_EXTENSION_FUNC_HELPER = 1ULL << 56ULL, // ETS Extension Function Helper - ETS_UNION = 1ULL << 57ULL, // ETS union ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | @@ -128,9 +127,7 @@ enum class TypeFlag : uint64_t { POSSIBLY_FALSY = DEFINITELY_FALSY | STRING | NUMBER | BOOLEAN | BIGINT, VALID_ARITHMETIC_TYPE = ANY | NUMBER_LIKE | BIGINT_LIKE | ENUM, UNIT = LITERAL | UNIQUE_SYMBOL | NULLABLE, - GETTER_SETTER = GETTER | SETTER, - CONDITION_EXPRESSION_TYPE = - NULLABLE | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ARRAY + GETTER_SETTER = GETTER | SETTER }; DEFINE_BITOPS(TypeFlag) diff --git a/ets2panda/checker/types/typeMapping.h b/ets2panda/checker/types/typeMapping.h index 3d6d406d80b40dfd1b2daba10cc8576180a702cf..6fe7873d22fb286f648e7b0f6d635bc5fb03e4b3 100644 --- a/ets2panda/checker/types/typeMapping.h +++ b/ets2panda/checker/types/typeMapping.h @@ -53,7 +53,6 @@ _(TypeFlag::FUNCTION, ETSFunctionType) \ _(TypeFlag::ETS_OBJECT, ETSObjectType) \ _(TypeFlag::ETS_ARRAY, ETSArrayType) \ - _(TypeFlag::ETS_UNION, ETSUnionType) \ _(TypeFlag::NON_PRIMITIVE, NonPrimitiveType) \ _(TypeFlag::WILDCARD, WildcardType) \ _(TypeFlag::ETS_TYPE_PARAMETER, ETSTypeParameter) \ diff --git a/ets2panda/checker/types/typeRelation.cpp b/ets2panda/checker/types/typeRelation.cpp index 9c25f672ca1cb1f0ed6462fd436e6a17b65f0a07..6dda8adc8cab76b0b1adb697e93a150fc8816d43 100644 --- a/ets2panda/checker/types/typeRelation.cpp +++ b/ets2panda/checker/types/typeRelation.cpp @@ -94,7 +94,7 @@ bool TypeRelation::IsIdenticalTo(IndexInfo *source, IndexInfo *target) return result_ == RelationResult::TRUE; } -// NOTE: applyNarrowing -> flag +// TODO(user): applyNarrowing -> flag bool TypeRelation::IsAssignableTo(Type *source, Type *target) { result_ = CacheLookup(source, target, checker_->AssignableResults(), RelationType::ASSIGNABLE); @@ -156,7 +156,7 @@ bool TypeRelation::IsCastableTo(Type *const source, Type *const target) return false; } - // NOTE: Can't cache if the node has BoxingUnboxingFlags. These flags should be stored and restored on the node + // FIXME: Can't cache if the node has BoxingUnboxingFlags. These flags should be stored and restored on the node // on cache hit. if (UncheckedCast() && node_->GetBoxingUnboxingFlags() == ir::BoxingUnboxingFlags::NONE) { checker_->UncheckedCastableResult().cached.insert( diff --git a/ets2panda/compiler/base/catchTable.cpp b/ets2panda/compiler/base/catchTable.cpp index 598f8482c03209e0e4eb37898f15db5597b298c5..a19942d5a35d8b6f76dc4c621033390cb335bdc4 100644 --- a/ets2panda/compiler/base/catchTable.cpp +++ b/ets2panda/compiler/base/catchTable.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/catchTable.h b/ets2panda/compiler/base/catchTable.h index 7b1e86d2fc497374e99edd084bc36403b26c627f..9bd2c5d572c7e7ddee2487a822b3b7a6702cd037 100644 --- a/ets2panda/compiler/base/catchTable.h +++ b/ets2panda/compiler/base/catchTable.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index dbabdb9ba8406d8114ecc5e59d8ebd13e1287ea1..7ebaf1929e5691f8312b8b56436f0ed46b7b5f46 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -17,72 +17,64 @@ #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "ir/expressions/assignmentExpression.h" #include "ir/expressions/binaryExpression.h" -#include "ir/expressions/callExpression.h" #include "ir/expressions/unaryExpression.h" namespace panda::es2panda::compiler { -bool Condition::CompileBinaryExpr(PandaGen *pg, const ir::BinaryExpression *bin_expr, Label *false_label) -{ - switch (bin_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: - case lexer::TokenType::PUNCTUATOR_LESS_THAN: - case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: { - // This is a special case - // These operators are expressed via cmp instructions and the following - // if-else branches. Condition also expressed via cmp instruction and - // the following if-else. - // the goal of this method is to merge these two sequences of instructions. - RegScope rs(pg); - VReg lhs = pg->AllocReg(); - - bin_expr->Left()->Compile(pg); - pg->StoreAccumulator(bin_expr, lhs); - bin_expr->Right()->Compile(pg); - pg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); - return true; - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - bin_expr->Left()->Compile(pg); - pg->ToBoolean(bin_expr); - pg->BranchIfFalse(bin_expr, false_label); - - bin_expr->Right()->Compile(pg); - pg->ToBoolean(bin_expr); - pg->BranchIfFalse(bin_expr, false_label); - return true; - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - auto *end_label = pg->AllocLabel(); - - bin_expr->Left()->Compile(pg); - pg->ToBoolean(bin_expr); - pg->BranchIfTrue(bin_expr, end_label); - - bin_expr->Right()->Compile(pg); - pg->ToBoolean(bin_expr); - pg->BranchIfFalse(bin_expr, false_label); - pg->SetLabel(bin_expr, end_label); - return true; - } - default: { - break; - } - } - return false; -} - void Condition::Compile(PandaGen *pg, const ir::Expression *expr, Label *false_label) { if (expr->IsBinaryExpression()) { - if (CompileBinaryExpr(pg, expr->AsBinaryExpression(), false_label)) { - return; + const auto *bin_expr = expr->AsBinaryExpression(); + + switch (bin_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: + case lexer::TokenType::PUNCTUATOR_LESS_THAN: + case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: { + // This is a special case + // These operators are expressed via cmp instructions and the following + // if-else branches. Condition also expressed via cmp instruction and + // the following if-else. + // the goal of this method is to merge these two sequences of instructions. + RegScope rs(pg); + VReg lhs = pg->AllocReg(); + + bin_expr->Left()->Compile(pg); + pg->StoreAccumulator(bin_expr, lhs); + bin_expr->Right()->Compile(pg); + pg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); + return; + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { + bin_expr->Left()->Compile(pg); + pg->ToBoolean(bin_expr); + pg->BranchIfFalse(bin_expr, false_label); + + bin_expr->Right()->Compile(pg); + pg->ToBoolean(bin_expr); + pg->BranchIfFalse(bin_expr, false_label); + return; + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { + auto *end_label = pg->AllocLabel(); + + bin_expr->Left()->Compile(pg); + pg->ToBoolean(bin_expr); + pg->BranchIfTrue(bin_expr, end_label); + + bin_expr->Right()->Compile(pg); + pg->ToBoolean(bin_expr); + pg->BranchIfFalse(bin_expr, false_label); + pg->SetLabel(bin_expr, end_label); + return; + } + default: { + break; + } } } else if (expr->IsUnaryExpression() && expr->AsUnaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK) { @@ -99,107 +91,83 @@ void Condition::Compile(PandaGen *pg, const ir::Expression *expr, Label *false_l pg->BranchIfFalse(expr, false_label); } -Condition::Result Condition::CheckConstantExpr(ETSGen *etsg, const ir::Expression *expr) +Condition::Result Condition::CheckConstantExpr(const ir::Expression *expr) { - const auto resulting_expression = [](const ir::Expression *e) { - if (e->IsBinaryExpression() && e->AsBinaryExpression()->IsLogicalExtended()) { - return e->AsBinaryExpression()->Result(); - } - if (e->IsAssignmentExpression() && e->AsAssignmentExpression()->IsLogicalExtended()) { - return e->AsAssignmentExpression()->Result(); - } - return e; - }(expr); - if (resulting_expression == nullptr) { - return Result::UNKNOWN; - } - - if (etsg->Checker()->IsNullOrVoidExpression(resulting_expression)) { - return Result::CONST_FALSE; - } - - auto expr_res = resulting_expression->TsType()->ResolveConditionExpr(); - if (std::get<0>(expr_res)) { - return std::get<1>(expr_res) ? Result::CONST_TRUE : Result::CONST_FALSE; + if (expr->TsType()->HasTypeFlag(checker::TypeFlag::CONSTANT)) { + auto res = expr->TsType()->AsETSBooleanType()->GetValue(); + return res ? Result::CONST_TRUE : Result::CONST_FALSE; } return Result::UNKNOWN; } -bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label) -{ - switch (bin_expr->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_EQUAL: - case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: - case lexer::TokenType::PUNCTUATOR_LESS_THAN: - case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: - case lexer::TokenType::KEYW_INSTANCEOF: { - auto ttctx = TargetTypeContext(etsg, bin_expr->OperationType()); - - RegScope rs(etsg); - VReg lhs = etsg->AllocReg(); - - bin_expr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); - bin_expr->Right()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); - etsg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); - return true; - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - bin_expr->Left()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Left(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); - - bin_expr->Right()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); - return true; - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - auto *end_label = etsg->AllocLabel(); - - bin_expr->Left()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfTrue(bin_expr->Left(), end_label); - etsg->BranchIfTrue(bin_expr, end_label); - - bin_expr->Right()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); - etsg->SetLabel(bin_expr, end_label); - return true; - } - default: { - break; - } - } - return false; -} - void Condition::Compile(ETSGen *etsg, const ir::Expression *expr, Label *false_label) { if (expr->IsBinaryExpression()) { - if (CompileBinaryExpr(etsg, expr->AsBinaryExpression(), false_label)) { - return; + const auto *bin_expr = expr->AsBinaryExpression(); + + switch (bin_expr->OperatorType()) { + case lexer::TokenType::PUNCTUATOR_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: + case lexer::TokenType::PUNCTUATOR_LESS_THAN: + case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: + case lexer::TokenType::KEYW_INSTANCEOF: { + auto ttctx = TargetTypeContext(etsg, bin_expr->OperationType()); + + RegScope rs(etsg); + VReg lhs = etsg->AllocReg(); + + bin_expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); + bin_expr->Right()->Compile(etsg); + etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); + etsg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); + return; + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { + bin_expr->Left()->Compile(etsg); + etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); + etsg->BranchIfFalse(bin_expr, false_label); + + bin_expr->Right()->Compile(etsg); + etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); + etsg->BranchIfFalse(bin_expr, false_label); + return; + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { + auto *end_label = etsg->AllocLabel(); + + bin_expr->Left()->Compile(etsg); + etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); + etsg->BranchIfTrue(bin_expr, end_label); + + bin_expr->Right()->Compile(etsg); + etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); + etsg->BranchIfFalse(bin_expr, false_label); + etsg->SetLabel(bin_expr, end_label); + return; + } + default: { + break; + } } } else if (expr->IsUnaryExpression() && expr->AsUnaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK) { expr->AsUnaryExpression()->Argument()->Compile(etsg); etsg->ApplyConversion(expr->AsUnaryExpression()->Argument(), etsg->Checker()->GlobalETSBooleanType()); - etsg->ResolveConditionalResultIfTrue(expr, false_label); etsg->BranchIfTrue(expr, false_label); return; } - ASSERT(expr->TsType()->IsConditionalExprType()); + + // TODO(user): Handle implicit bool conversion: not zero int == true, not null obj ref == true, otherwise false + ASSERT(expr->TsType()->IsETSBooleanType() || + (expr->TsType()->IsETSObjectType() && + expr->TsType()->AsETSObjectType()->HasObjectFlag( + checker::ETSObjectFlags::BUILTIN_BOOLEAN))); // already checked by checker::CheckTruthinessOfType() expr->Compile(etsg); etsg->ApplyConversion(expr, etsg->Checker()->GlobalETSBooleanType()); - etsg->ResolveConditionalResultIfFalse(expr, false_label); etsg->BranchIfFalse(expr, false_label); } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/base/condition.h b/ets2panda/compiler/base/condition.h index 165b37cf8d2e7caf6470ea6021958b0eab24a697..85071b3a40643b8ddf78e2f63e2b126ace3156ae 100644 --- a/ets2panda/compiler/base/condition.h +++ b/ets2panda/compiler/base/condition.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -35,11 +35,7 @@ public: static void Compile(PandaGen *pg, const ir::Expression *expr, Label *false_label); static void Compile(ETSGen *etsg, const ir::Expression *expr, Label *false_label); - static Result CheckConstantExpr(ETSGen *etsg, const ir::Expression *expr); - -private: - static bool CompileBinaryExpr(PandaGen *pg, const ir::BinaryExpression *bin_expr, Label *false_label); - static bool CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label); + static Result CheckConstantExpr(const ir::Expression *expr); }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/base/destructuring.cpp b/ets2panda/compiler/base/destructuring.cpp index fa1d00f5313fc887e28b41ace507e4adefc3dbd8..fbea14995db4deb09e06dbcd7567122f1fffb2c7 100644 --- a/ets2panda/compiler/base/destructuring.cpp +++ b/ets2panda/compiler/base/destructuring.cpp @@ -70,6 +70,7 @@ static void GenRestElement(PandaGen *pg, const ir::SpreadElement *rest_element, static void GenArray(PandaGen *pg, const ir::ArrayExpression *array) { + // RegScope rs(pg); DestructuringIterator iterator(pg, array); if (array->Elements().empty()) { diff --git a/ets2panda/compiler/base/destructuring.h b/ets2panda/compiler/base/destructuring.h index 358640c0fc932a29d75dfee0b7e5d1162509e666..6a0662e8055b6eda69d4cc56ad6381f305e1c217 100644 --- a/ets2panda/compiler/base/destructuring.h +++ b/ets2panda/compiler/base/destructuring.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/hoisting.cpp b/ets2panda/compiler/base/hoisting.cpp index c367fbab65cabe02c421f0e31213286b72ef350b..3d555fdb356e3393b56426c77ab5d122b504fdce 100644 --- a/ets2panda/compiler/base/hoisting.cpp +++ b/ets2panda/compiler/base/hoisting.cpp @@ -16,11 +16,11 @@ #include "hoisting.h" #include "ir/base/scriptFunction.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/core/pandagen.h" namespace panda::es2panda::compiler { -static void HoistVar(PandaGen *pg, varbinder::Variable *var, const varbinder::VarDecl *decl) +static void HoistVar(PandaGen *pg, binder::Variable *var, const binder::VarDecl *decl) { auto *scope = pg->Scope(); @@ -30,13 +30,13 @@ static void HoistVar(PandaGen *pg, varbinder::Variable *var, const varbinder::Va return; } - varbinder::ConstScopeFindResult result(decl->Name(), scope, 0, var); + binder::ConstScopeFindResult result(decl->Name(), scope, 0, var); pg->LoadConst(decl->Node(), Constant::JS_UNDEFINED); pg->StoreAccToLexEnv(decl->Node(), result, true); } -static void HoistFunction(PandaGen *pg, varbinder::Variable *var, const varbinder::FunctionDecl *decl) +static void HoistFunction(PandaGen *pg, binder::Variable *var, const binder::FunctionDecl *decl) { const ir::ScriptFunction *script_function = decl->Node()->AsScriptFunction(); auto *scope = pg->Scope(); @@ -50,7 +50,7 @@ static void HoistFunction(PandaGen *pg, varbinder::Variable *var, const varbinde } ASSERT(scope->IsFunctionScope() || scope->IsCatchScope() || scope->IsLocalScope() || scope->IsModuleScope()); - varbinder::ConstScopeFindResult result(decl->Name(), scope, 0, var); + binder::ConstScopeFindResult result(decl->Name(), scope, 0, var); pg->DefineFunction(decl->Node(), script_function, internal_name); pg->StoreAccToLexEnv(decl->Node(), result, true); @@ -62,7 +62,7 @@ void Hoisting::Hoist(PandaGen *pg) for (const auto &[_, var] : scope->Bindings()) { (void)_; - if (!var->HasFlag(varbinder::VariableFlags::HOIST)) { + if (!var->HasFlag(binder::VariableFlags::HOIST)) { continue; } diff --git a/ets2panda/compiler/base/iterators.cpp b/ets2panda/compiler/base/iterators.cpp index 9eb761c488596cb66dd410cf31c0a25159d1c75c..a3e78d43d0ced25daca712447d8d302cdcc524f6 100644 --- a/ets2panda/compiler/base/iterators.cpp +++ b/ets2panda/compiler/base/iterators.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/iterators.h b/ets2panda/compiler/base/iterators.h index 5607b9142a82d61cf8138ee982a052e89f78bff6..e63183ad1867005cac921c4ac100c1c2176608d5 100644 --- a/ets2panda/compiler/base/iterators.h +++ b/ets2panda/compiler/base/iterators.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/lexenv.cpp b/ets2panda/compiler/base/lexenv.cpp index cef7d9366b78123df2c781595e20b68a482c4224..29f7582b124b92b47f0d9a3ed47afde1f584d336 100644 --- a/ets2panda/compiler/base/lexenv.cpp +++ b/ets2panda/compiler/base/lexenv.cpp @@ -15,7 +15,7 @@ #include "lexenv.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/core/envScope.h" #include "compiler/core/pandagen.h" #include "compiler/core/moduleContext.h" @@ -29,7 +29,7 @@ static bool CheckTdz(const ir::AstNode *node) return node->IsIdentifier() && node->AsIdentifier()->IsTdz(); } -static void CheckConstAssignment(PandaGen *pg, const ir::AstNode *node, varbinder::Variable *variable) +static void CheckConstAssignment(PandaGen *pg, const ir::AstNode *node, binder::Variable *variable) { if (!variable->Declaration()->IsConstDecl()) { return; @@ -40,7 +40,7 @@ static void CheckConstAssignment(PandaGen *pg, const ir::AstNode *node, varbinde // VirtualLoadVar -static void ExpandLoadLexVar(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) +static void ExpandLoadLexVar(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result) { if (result.variable->Declaration()->IsVarDecl()) { pg->LoadLexicalVar(node, result.lex_level, result.variable->AsLocalVariable()->LexIdx()); @@ -49,7 +49,7 @@ static void ExpandLoadLexVar(PandaGen *pg, const ir::AstNode *node, const varbin } } -static void ExpandLoadNormalVar(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) +static void ExpandLoadNormalVar(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result) { auto *local = result.variable->AsLocalVariable(); @@ -60,7 +60,7 @@ static void ExpandLoadNormalVar(PandaGen *pg, const ir::AstNode *node, const var } } -void VirtualLoadVar::Expand(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) +void VirtualLoadVar::Expand(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result) { if (result.variable->LexicalBound()) { ExpandLoadLexVar(pg, node, result); @@ -71,9 +71,9 @@ void VirtualLoadVar::Expand(PandaGen *pg, const ir::AstNode *node, const varbind // VirtualStoreVar -static void StoreLocalExport(PandaGen *pg, const ir::AstNode *node, varbinder::Variable *variable) +static void StoreLocalExport(PandaGen *pg, const ir::AstNode *node, binder::Variable *variable) { - if (!variable->HasFlag(varbinder::VariableFlags::LOCAL_EXPORT) || !pg->Scope()->IsModuleScope()) { + if (!variable->HasFlag(binder::VariableFlags::LOCAL_EXPORT) || !pg->Scope()->IsModuleScope()) { return; } @@ -86,10 +86,10 @@ static void StoreLocalExport(PandaGen *pg, const ir::AstNode *node, varbinder::V } } -static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, +static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_decl) { - varbinder::LocalVariable *local = result.variable->AsLocalVariable(); + binder::LocalVariable *local = result.variable->AsLocalVariable(); const auto *decl = result.variable->Declaration(); @@ -106,7 +106,7 @@ static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const varbi StoreLocalExport(pg, node, local); } -static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, +static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_decl) { auto *local = result.variable->AsLocalVariable(); @@ -124,7 +124,7 @@ static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const va StoreLocalExport(pg, node, local); } -void VirtualStoreVar::Expand(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, +void VirtualStoreVar::Expand(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_decl) { if (result.variable->LexicalBound()) { diff --git a/ets2panda/compiler/base/lexenv.h b/ets2panda/compiler/base/lexenv.h index c8f200b6399e466fc9f13863fba288dc70d003cb..325ff6475cf721b78399eca130d0faf03138b1da 100644 --- a/ets2panda/compiler/base/lexenv.h +++ b/ets2panda/compiler/base/lexenv.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_COMPILER_SCOPES_LEXENV_H #define ES2PANDA_COMPILER_SCOPES_LEXENV_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/irnode.h" namespace panda::es2panda::compiler { @@ -26,15 +26,14 @@ class VirtualLoadVar { public: VirtualLoadVar() = delete; - static void Expand(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result); + static void Expand(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result); }; class VirtualStoreVar { public: VirtualStoreVar() = delete; - static void Expand(PandaGen *pg, const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, - bool is_decl); + static void Expand(PandaGen *pg, const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_decl); }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/base/literals.cpp b/ets2panda/compiler/base/literals.cpp index 660f3c814692b5f00552c3965023019996dbaa33..bc6655873fb5bdb77e0709d1e667e497cf1f6a04 100644 --- a/ets2panda/compiler/base/literals.cpp +++ b/ets2panda/compiler/base/literals.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/literals.h b/ets2panda/compiler/base/literals.h index debb3e00d7fcaa26fad21e531a50a250070707a6..ec799f0b61fbbe953e2828f0505c55ddced46437 100644 --- a/ets2panda/compiler/base/literals.h +++ b/ets2panda/compiler/base/literals.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/lreference.cpp b/ets2panda/compiler/base/lreference.cpp index 0c80103e64676bebb1b0e2fa5882a1ad78ea0966..1202ef83796f520c4fd6a7d0ae55edaabec352bd 100644 --- a/ets2panda/compiler/base/lreference.cpp +++ b/ets2panda/compiler/base/lreference.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,13 +15,12 @@ #include "lreference.h" -#include "varbinder/declaration.h" -#include "varbinder/variableFlags.h" +#include "binder/declaration.h" +#include "binder/variableFlags.h" #include "compiler/base/destructuring.h" #include "compiler/core/function.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "checker/types/ets/etsUnionType.h" #include "ir/astNode.h" #include "ir/base/spreadElement.h" #include "ir/base/classProperty.h" @@ -42,7 +41,7 @@ LReference::LReferenceBase LReference::CreateBase(CodeGen *cg, const ir::AstNode // NOTE: This case is never reached in case of ETS case ir::AstNodeType::IDENTIFIER: { const util::StringView &name = node->AsIdentifier()->Name(); - auto res = cg->Scope()->Find(name, varbinder::ResolveBindingOptions::ALL); + auto res = cg->Scope()->Find(name, binder::ResolveBindingOptions::ALL); if (res.variable == nullptr) { res.variable = node->AsIdentifier()->Variable(); @@ -77,7 +76,7 @@ LReference::LReferenceBase LReference::CreateBase(CodeGen *cg, const ir::AstNode } JSLReference::JSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, - varbinder::ConstScopeFindResult res, bool is_declaration) + binder::ConstScopeFindResult res, bool is_declaration) : LReference(node, ref_kind, res, is_declaration), pg_(static_cast(cg)) { if (Kind() != ReferenceKind::MEMBER) { @@ -174,7 +173,7 @@ void JSLReference::SetValue() const } ETSLReference::ETSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, - varbinder::ConstScopeFindResult res, bool is_declaration) + binder::ConstScopeFindResult res, bool is_declaration) : LReference(node, ref_kind, res, is_declaration), etsg_(static_cast(cg)) { if (Kind() != ReferenceKind::MEMBER) { @@ -207,10 +206,10 @@ ETSLReference ETSLReference::Create(CodeGen *const cg, const ir::AstNode *const { if (node->Type() == ir::AstNodeType::IDENTIFIER) { const auto &name = node->AsIdentifier()->Name(); - auto res = cg->Scope()->FindInFunctionScope(name, varbinder::ResolveBindingOptions::ALL); + auto res = cg->Scope()->FindInFunctionScope(name, binder::ResolveBindingOptions::ALL); if (res.variable == nullptr) { - res = cg->Scope()->FindInGlobal(name, varbinder::ResolveBindingOptions::ALL_VARIABLES | - varbinder::ResolveBindingOptions::ALL_METHOD); + res = cg->Scope()->FindInGlobal(name, binder::ResolveBindingOptions::ALL_VARIABLES | + binder::ResolveBindingOptions::ALL_METHOD); if (res.variable == nullptr) { res.variable = node->AsIdentifier()->Variable(); } @@ -221,12 +220,12 @@ ETSLReference ETSLReference::Create(CodeGen *const cg, const ir::AstNode *const return std::make_from_tuple(CreateBase(cg, node, is_declaration)); } -ReferenceKind ETSLReference::ResolveReferenceKind(const varbinder::Variable *variable) +ReferenceKind ETSLReference::ResolveReferenceKind(const binder::Variable *variable) { - if (variable->HasFlag(varbinder::VariableFlags::SYNTHETIC)) { + if (variable->HasFlag(binder::VariableFlags::SYNTHETIC)) { return ReferenceKind::METHOD; } - if (variable->HasFlag(varbinder::VariableFlags::LOCAL)) { + if (variable->HasFlag(binder::VariableFlags::LOCAL)) { return ReferenceKind::LOCAL; } @@ -269,76 +268,67 @@ void ETSLReference::GetValue() const } } -void ETSLReference::SetValueComputed(const ir::MemberExpression *member_expr) const -{ - auto object_type = member_expr->Object()->TsType(); - if (object_type->IsETSDynamicType()) { - auto lang = object_type->AsETSDynamicType()->Language(); - etsg_->StoreElementDynamic(Node(), base_reg_, prop_reg_, lang); - } else { - etsg_->StoreArrayElement(Node(), base_reg_, prop_reg_, - etsg_->GetVRegType(base_reg_)->AsETSArrayType()->ElementType()); - } -} - -void ETSLReference::SetValueGetterSetter(const ir::MemberExpression *member_expr) const +void ETSLReference::SetValue() const { - const auto *sig = member_expr->PropVar()->TsType()->AsETSFunctionType()->FindSetter(); + switch (Kind()) { + case ReferenceKind::MEMBER: { + auto *member_expr = Node()->AsMemberExpression(); + if (!member_expr->IsIgnoreBox()) { + etsg_->ApplyConversion(Node(), member_expr->TsType()); + } - auto arg_reg = etsg_->AllocReg(); - etsg_->StoreAccumulator(Node(), arg_reg); + if (member_expr->IsComputed()) { + auto object_type = member_expr->Object()->TsType(); + if (object_type->IsETSDynamicType()) { + auto lang = object_type->AsETSDynamicType()->Language(); + etsg_->StoreElementDynamic(Node(), base_reg_, prop_reg_, lang); + } else { + etsg_->StoreArrayElement(Node(), base_reg_, prop_reg_, + etsg_->GetVRegType(base_reg_)->AsETSArrayType()->ElementType()); + } + break; + } - if (sig->Function()->IsStatic()) { - etsg_->CallThisStatic0(Node(), arg_reg, sig->InternalName()); - } else { - etsg_->CallThisVirtual1(Node(), base_reg_, sig->InternalName(), arg_reg); - } -} + if (member_expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { + const auto *sig = member_expr->PropVar()->TsType()->AsETSFunctionType()->FindSetter(); -void ETSLReference::SetValue() const -{ - if (Kind() == ReferenceKind::MEMBER) { - auto *member_expr = Node()->AsMemberExpression(); - if (!member_expr->IsIgnoreBox()) { - etsg_->ApplyConversion(Node(), member_expr->TsType()); - } + auto arg_reg = etsg_->AllocReg(); + etsg_->StoreAccumulator(Node(), arg_reg); - if (member_expr->IsComputed()) { - SetValueComputed(member_expr); - return; - } + if (sig->Function()->IsStatic()) { + etsg_->CallThisStatic0(Node(), arg_reg, sig->InternalName()); + } else { + etsg_->CallThisVirtual1(Node(), base_reg_, sig->InternalName(), arg_reg); + } + break; + } - if (member_expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { - SetValueGetterSetter(member_expr); - return; - } + auto &prop_name = member_expr->Property()->AsIdentifier()->Name(); + if (member_expr->PropVar()->HasFlag(binder::VariableFlags::STATIC)) { + util::StringView full_name = + etsg_->FormClassPropReference(static_obj_ref_->AsETSObjectType(), prop_name); + if (static_obj_ref_->IsETSDynamicType()) { + auto lang = static_obj_ref_->AsETSDynamicType()->Language(); + etsg_->StorePropertyDynamic(Node(), member_expr->TsType(), base_reg_, prop_name, lang); + } else { + etsg_->StoreStaticProperty(Node(), member_expr->TsType(), full_name); + } + break; + } - auto &prop_name = member_expr->Property()->AsIdentifier()->Name(); - if (member_expr->PropVar()->HasFlag(varbinder::VariableFlags::STATIC)) { - util::StringView full_name = etsg_->FormClassPropReference(static_obj_ref_->AsETSObjectType(), prop_name); if (static_obj_ref_->IsETSDynamicType()) { auto lang = static_obj_ref_->AsETSDynamicType()->Language(); etsg_->StorePropertyDynamic(Node(), member_expr->TsType(), base_reg_, prop_name, lang); } else { - etsg_->StoreStaticProperty(Node(), member_expr->TsType(), full_name); + auto type = etsg_->Checker()->MaybeBoxedType(member_expr->PropVar(), etsg_->Allocator()); + etsg_->StoreProperty(Node(), type, base_reg_, prop_name); } - return; + break; } - - if (static_obj_ref_->IsETSDynamicType()) { - auto lang = static_obj_ref_->AsETSDynamicType()->Language(); - etsg_->StorePropertyDynamic(Node(), member_expr->TsType(), base_reg_, prop_name, lang); - } else if (static_obj_ref_->IsETSUnionType()) { - etsg_->StoreUnionProperty(Node(), base_reg_, prop_name); - } else { - auto type = etsg_->Checker()->MaybeBoxedType(member_expr->PropVar(), etsg_->Allocator()); - if (type->IsETSUnionType()) { - type = type->AsETSUnionType()->GetLeastUpperBoundType(); - } - etsg_->StoreProperty(Node(), type, base_reg_, prop_name); + default: { + etsg_->StoreVar(Node()->AsIdentifier(), Result()); + break; } - } else { - etsg_->StoreVar(Node()->AsIdentifier(), Result()); } } diff --git a/ets2panda/compiler/base/lreference.h b/ets2panda/compiler/base/lreference.h index cae126baabc34f933049df266ff741dc66c43453..083327793688b1d0061206a17034db0ac7cc575b 100644 --- a/ets2panda/compiler/base/lreference.h +++ b/ets2panda/compiler/base/lreference.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -16,7 +16,7 @@ #ifndef ES2PANDA_COMPILER_BASE_JSLREFERENCE_H #define ES2PANDA_COMPILER_BASE_JSLREFERENCE_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/irnode.h" namespace panda::es2panda::ir { @@ -63,7 +63,7 @@ public: ref_kind_ = ref_kind; } - varbinder::Variable *Variable() const + binder::Variable *Variable() const { return res_.variable; } @@ -73,12 +73,12 @@ public: return node_; } - varbinder::ConstScopeFindResult &Result() + binder::ConstScopeFindResult &Result() { return res_; } - const varbinder::ConstScopeFindResult &Result() const + const binder::ConstScopeFindResult &Result() const { return res_; } @@ -90,10 +90,10 @@ public: protected: using LReferenceBase = - std::tuple; + std::tuple; static LReferenceBase CreateBase(CodeGen *cg, const ir::AstNode *node, bool is_declaration); - explicit LReference(const ir::AstNode *node, ReferenceKind ref_kind, varbinder::ConstScopeFindResult res, + explicit LReference(const ir::AstNode *node, ReferenceKind ref_kind, binder::ConstScopeFindResult res, bool is_declaration) : node_(node), ref_kind_(ref_kind), res_(res), is_declaration_(is_declaration) { @@ -102,13 +102,13 @@ protected: private: const ir::AstNode *node_; ReferenceKind ref_kind_; - varbinder::ConstScopeFindResult res_; + binder::ConstScopeFindResult res_; bool is_declaration_; }; class JSLReference : public LReference { public: - JSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, varbinder::ConstScopeFindResult res, + JSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, binder::ConstScopeFindResult res, bool is_declaration); ~JSLReference() = default; NO_COPY_SEMANTIC(JSLReference); @@ -131,7 +131,7 @@ private: class ETSLReference : public LReference { public: - ETSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, varbinder::ConstScopeFindResult res, + ETSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind ref_kind, binder::ConstScopeFindResult res, bool is_declaration); ~ETSLReference() = default; NO_COPY_SEMANTIC(ETSLReference); @@ -141,12 +141,9 @@ public: void SetValue() const; static ETSLReference Create(CodeGen *cg, const ir::AstNode *node, bool is_declaration); - static ReferenceKind ResolveReferenceKind(const varbinder::Variable *variable); + static ReferenceKind ResolveReferenceKind(const binder::Variable *variable); private: - void SetValueComputed(const ir::MemberExpression *member_expr) const; - void SetValueGetterSetter(const ir::MemberExpression *member_expr) const; - ETSGen *etsg_; const checker::Type *static_obj_ref_ {}; VReg base_reg_ {}; diff --git a/ets2panda/compiler/base/optionalChain.cpp b/ets2panda/compiler/base/optionalChain.cpp index eba359006f12732ca2c86a09516cde601006e310..441985b5f3724a110b5a5664bea7002f7a3b427b 100644 --- a/ets2panda/compiler/base/optionalChain.cpp +++ b/ets2panda/compiler/base/optionalChain.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/base/optionalChain.h b/ets2panda/compiler/base/optionalChain.h index 8d470c7466410d5ac05e31e6ff984d4c40ad9d85..b48c9b47e469d7b7c22b70cada38afacc07fc213 100644 --- a/ets2panda/compiler/base/optionalChain.h +++ b/ets2panda/compiler/base/optionalChain.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/ASTCompiler.h b/ets2panda/compiler/core/ASTCompiler.h index d6fa1d171c83dc98930b52a24d5dd9753b2a1dec..b5bd6661794f22acfc3e000542ef9b1282941eda 100644 --- a/ets2panda/compiler/core/ASTCompiler.h +++ b/ets2panda/compiler/core/ASTCompiler.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -17,152 +17,6 @@ #define ES2PANDA_COMPILER_CORE_ASTCOMPILER_H #include "compiler/core/dynamicContext.h" -#include "ir/opaqueTypeNode.h" -#include "ir/as/namedType.h" -#include "ir/as/prefixAssertionExpression.h" -#include "ir/base/catchClause.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classProperty.h" -#include "ir/base/classStaticBlock.h" -#include "ir/base/decorator.h" -#include "ir/base/metaProperty.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/property.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/base/templateElement.h" -#include "ir/base/tsIndexSignature.h" -#include "ir/base/tsMethodSignature.h" -#include "ir/base/tsPropertySignature.h" -#include "ir/base/tsSignatureDeclaration.h" -#include "ir/ets/etsClassLiteral.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/ets/etsImportDeclaration.h" -#include "ir/ets/etsLaunchExpression.h" -#include "ir/ets/etsNewArrayInstanceExpression.h" -#include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" -#include "ir/ets/etsPackageDeclaration.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ets/etsPrimitiveType.h" -#include "ir/ets/etsScript.h" -#include "ir/ets/etsStructDeclaration.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsWildcardType.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/awaitExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/chainExpression.h" -#include "ir/expressions/classExpression.h" -#include "ir/expressions/conditionalExpression.h" -#include "ir/expressions/directEvalExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/importExpression.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/newExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/omittedExpression.h" -#include "ir/expressions/sequenceExpression.h" -#include "ir/expressions/superExpression.h" -#include "ir/expressions/taggedTemplateExpression.h" -#include "ir/expressions/templateLiteral.h" -#include "ir/expressions/thisExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/expressions/updateExpression.h" -#include "ir/expressions/yieldExpression.h" -#include "ir/expressions/literals/bigIntLiteral.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "ir/expressions/literals/charLiteral.h" -#include "ir/expressions/literals/nullLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/regExpLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/exportAllDeclaration.h" -#include "ir/module/exportDefaultDeclaration.h" -#include "ir/module/exportNamedDeclaration.h" -#include "ir/module/exportSpecifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/module/importDefaultSpecifier.h" -#include "ir/module/importNamespaceSpecifier.h" -#include "ir/module/importSpecifier.h" -#include "ir/statements/assertStatement.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/breakStatement.h" -#include "ir/statements/classDeclaration.h" -#include "ir/statements/continueStatement.h" -#include "ir/statements/debuggerStatement.h" -#include "ir/statements/doWhileStatement.h" -#include "ir/statements/emptyStatement.h" -#include "ir/statements/expressionStatement.h" -#include "ir/statements/forInStatement.h" -#include "ir/statements/forOfStatement.h" -#include "ir/statements/forUpdateStatement.h" -#include "ir/statements/functionDeclaration.h" -#include "ir/statements/ifStatement.h" -#include "ir/statements/labelledStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/statements/switchCaseStatement.h" -#include "ir/statements/switchStatement.h" -#include "ir/statements/throwStatement.h" -#include "ir/statements/tryStatement.h" -#include "ir/statements/variableDeclaration.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/statements/whileStatement.h" -#include "ir/ts/tsAnyKeyword.h" -#include "ir/ts/tsArrayType.h" -#include "ir/ts/tsAsExpression.h" -#include "ir/ts/tsBigintKeyword.h" -#include "ir/ts/tsBooleanKeyword.h" -#include "ir/ts/tsClassImplements.h" -#include "ir/ts/tsConditionalType.h" -#include "ir/ts/tsConstructorType.h" -#include "ir/ts/tsEnumDeclaration.h" -#include "ir/ts/tsEnumMember.h" -#include "ir/ts/tsExternalModuleReference.h" -#include "ir/ts/tsFunctionType.h" -#include "ir/ts/tsImportEqualsDeclaration.h" -#include "ir/ts/tsImportType.h" -#include "ir/ts/tsIndexedAccessType.h" -#include "ir/ts/tsInferType.h" -#include "ir/ts/tsInterfaceBody.h" -#include "ir/ts/tsInterfaceDeclaration.h" -#include "ir/ts/tsInterfaceHeritage.h" -#include "ir/ts/tsIntersectionType.h" -#include "ir/ts/tsLiteralType.h" -#include "ir/ts/tsMappedType.h" -#include "ir/ts/tsModuleBlock.h" -#include "ir/ts/tsModuleDeclaration.h" -#include "ir/ts/tsNamedTupleMember.h" -#include "ir/ts/tsNeverKeyword.h" -#include "ir/ts/tsNonNullExpression.h" -#include "ir/ts/tsNullKeyword.h" -#include "ir/ts/tsNumberKeyword.h" -#include "ir/ts/tsObjectKeyword.h" -#include "ir/ts/tsParameterProperty.h" -#include "ir/ts/tsParenthesizedType.h" -#include "ir/ts/tsQualifiedName.h" -#include "ir/ts/tsStringKeyword.h" -#include "ir/ts/tsThisType.h" -#include "ir/ts/tsTupleType.h" -#include "ir/ts/tsTypeAliasDeclaration.h" -#include "ir/ts/tsTypeAssertion.h" -#include "ir/ts/tsTypeLiteral.h" -#include "ir/ts/tsTypeOperator.h" -#include "ir/ts/tsTypeParameterDeclaration.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsTypePredicate.h" -#include "ir/ts/tsTypeQuery.h" -#include "ir/ts/tsTypeReference.h" -#include "ir/ts/tsUndefinedKeyword.h" -#include "ir/ts/tsUnionType.h" -#include "ir/ts/tsUnknownKeyword.h" -#include "ir/ts/tsVoidKeyword.h" namespace panda::es2panda::compiler { class CodeGen; diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp deleted file mode 100644 index 9f9b376f1bf28e456a0aeef0bbcabd1b81dc4349..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ /dev/null @@ -1,409 +0,0 @@ -/** - * 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 "ASTVerifier.h" - -#include "es2panda.h" -#include "varbinder/variableFlags.h" -#include "varbinder/scope.h" -#include "ir/astNode.h" -#include "ir/base/catchClause.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classStaticBlock.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsPackageDeclaration.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/classDeclaration.h" -#include "ir/statements/expressionStatement.h" -#include "ir/statements/throwStatement.h" -#include "ir/statements/tryStatement.h" -#include "ir/statements/variableDeclaration.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/ts/tsClassImplements.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" -#include "ir/ts/tsTypeParameterInstantiation.h" - -namespace panda::es2panda::compiler { - -bool ASTVerifier::IsCorrectProgram(const parser::Program *program) -{ - bool is_correct = true; - error_messages_.clear(); - - for (auto *statement : program->Ast()->Statements()) { - is_correct &= HaveParents(statement); - } - is_correct &= HaveParents(program->GlobalClass()); - - for (auto *statement : program->Ast()->Statements()) { - is_correct &= HaveTypes(statement); - } - is_correct &= HaveTypes(program->GlobalClass()); - - for (auto *statement : program->Ast()->Statements()) { - is_correct &= HaveVariables(statement); - } - is_correct &= HaveVariables(program->GlobalClass()); - - for (auto *statement : program->Ast()->Statements()) { - is_correct &= HaveScopes(statement); - } - is_correct &= HaveScopes(program->GlobalClass()); - -#ifndef NDEBUG - std::for_each(error_messages_.begin(), error_messages_.end(), [](auto const msg) { LOG(INFO, COMMON) << msg; }); -#endif // NDEBUG - return is_correct; -} - -std::string ToStringHelper(const varbinder::ScopeType type) -{ - switch (type) { - case varbinder::ScopeType::CATCH: { - return "CATCH"; - } - case varbinder::ScopeType::CATCH_PARAM: { - return "CATCH_PARAM"; - } - case varbinder::ScopeType::CLASS: { - return "CLASS"; - } - case varbinder::ScopeType::FUNCTION: { - return "FUNCTION"; - } - case varbinder::ScopeType::FUNCTION_PARAM: { - return "FUNCTION_PARAM"; - } - case varbinder::ScopeType::GLOBAL: { - return "GLOBAL"; - } - case varbinder::ScopeType::LOCAL: { - return "LOCAL"; - } - case varbinder::ScopeType::LOOP: { - return "LOOP"; - } - case varbinder::ScopeType::LOOP_DECL: { - return "LOOP_DECL"; - } - case varbinder::ScopeType::MODULE: { - return "MODULE"; - } - case varbinder::ScopeType::PARAM: { - return "PARAM"; - } - default: { - return "MUST BE UNREACHABLE"; - } - } -} - -std::string ToStringHelper(const util::StringView &name) -{ - return name == nullptr ? "" : name.Mutf8(); -} - -std::string ToStringHelper(const varbinder::Scope *scope) -{ - if (scope == nullptr) { - return ""; - } - - switch (scope->Type()) { - case varbinder::ScopeType::FUNCTION: { - return "FUNC_SCOPE " + ToStringHelper(scope->AsFunctionScope()->Name()); - } - case varbinder::ScopeType::LOCAL: { - return "LOCAL_SCOPE "; - } - case varbinder::ScopeType::CATCH: { - return "CATCH_SCOPE "; - } - default: { - return "MUST BE UNREACHABLE"; - } - } -} - -std::string ToStringHelper(const varbinder::Variable *var) -{ - if (var == nullptr) { - return ""; - } - - switch (var->Type()) { - case varbinder::VariableType::LOCAL: { - return "LOCAL_VAR " + ToStringHelper(var->Name()); - } - case varbinder::VariableType::MODULE: { - return "MODULE_VAR " + ToStringHelper(var->Name()); - } - case varbinder::VariableType::GLOBAL: { - return "GLOBAL_VAR " + ToStringHelper(var->Name()); - } - case varbinder::VariableType::ENUM: { - return "ENUM_VAR " + ToStringHelper(var->Name()); - } - default: { - return "MUST BE UNREACHABLE"; - } - } -} - -template -std::string ToStringParamsHelper(const ir::AstNode *parent, const ArenaVector ¶ms) -{ - std::string name; - if (parent != nullptr) { - name = ToStringHelper(parent) + " "; - } - - name += "("; - for (auto const *param : params) { - name += ToStringHelper(param); - } - - return name + ")"; -} - -std::string ToStringHelper(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return ""; - } - - switch (ast->Type()) { - case ir::AstNodeType::IDENTIFIER: { - return "ID " + ToStringHelper(ast->AsIdentifier()->Name()); - } - case ir::AstNodeType::CLASS_DEFINITION: { - return "CLS_DEF " + ToStringHelper(ast->AsClassDefinition()->Ident()); - } - case ir::AstNodeType::CLASS_DECLARATION: { - return "CLS_DECL " + ToStringHelper(ast->AsClassDeclaration()->Definition()); - } - case ir::AstNodeType::BLOCK_STATEMENT: { - return "BLOCK " + ToStringHelper(ast->AsBlockStatement()->Scope()); - } - case ir::AstNodeType::SCRIPT_FUNCTION: { - auto const *sf = ast->AsScriptFunction(); - return "SCRIPT_FUN " + ToStringHelper(sf->Scope()) + "::" + ToStringHelper(sf->Id()); - } - case ir::AstNodeType::FUNCTION_EXPRESSION: { - return "FUN_EXPR " + ToStringHelper(ast->AsFunctionExpression()->Function()); - } - case ir::AstNodeType::METHOD_DEFINITION: { - return "METHOD_DEF " + ToStringHelper(ast->AsMethodDefinition()->Value()); - } - case ir::AstNodeType::ETS_TYPE_REFERENCE_PART: { - return "TYPE_REF_PART " + ToStringHelper(ast->AsETSTypeReferencePart()->Name()); - } - case ir::AstNodeType::ETS_TYPE_REFERENCE: { - return "TYPE_REF " + ToStringHelper(ast->AsETSTypeReference()->Part()); - } - case ir::AstNodeType::VARIABLE_DECLARATOR: { - return "VAR_DECLARATOR " + ToStringHelper(ast->AsVariableDeclarator()->Id()); - } - case ir::AstNodeType::VARIABLE_DECLARATION: { - if (ast->AsVariableDeclaration()->Declarators().empty()) { - return "VAR_DECLARATION "; - } - return "VAR_DECLARATION " + ToStringHelper(ast->AsVariableDeclaration()->Declarators().at(0)); - } - case ir::AstNodeType::CALL_EXPRESSION: { - return "CALL_EXPR " + ToStringHelper(ast->AsCallExpression()->Callee()) + "(...)"; - } - case ir::AstNodeType::EXPRESSION_STATEMENT: { - return "EXPR_STMT " + ToStringHelper(ast->AsExpressionStatement()->GetExpression()); - } - case ir::AstNodeType::MEMBER_EXPRESSION: { - auto const *me = ast->AsMemberExpression(); - return "MEMBER_EXPR " + ToStringHelper(me->Object()) + "." + ToStringHelper(me->Property()); - } - case ir::AstNodeType::CLASS_STATIC_BLOCK: { - return "CLS_STATIC_BLOCK " + ToStringHelper(ast->AsClassStaticBlock()->Function()); - } - case ir::AstNodeType::ETS_PACKAGE_DECLARATION: { - return "PKG_DECL "; - } - case ir::AstNodeType::TS_TYPE_PARAMETER_DECLARATION: { - auto params = ast->AsTSTypeParameterDeclaration()->Params(); - return "PARAM_DECL " + ToStringParamsHelper(ast->Parent(), params); - } - case ir::AstNodeType::TS_TYPE_PARAMETER: { - return "TYPE_PARAM " + ToStringHelper(ast->AsTSTypeParameter()->Name()); - } - case ir::AstNodeType::TS_TYPE_PARAMETER_INSTANTIATION: { - return "PARAM_INSTANTIATION " + - ToStringParamsHelper(ast->Parent(), ast->AsTSTypeParameterInstantiation()->Params()); - } - case ir::AstNodeType::THROW_STATEMENT: { - return "THROW_STMT " + ToStringHelper(ast->AsThrowStatement()->Argument()); - } - case ir::AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION: { - return "NEW_CLS_INSTANCE " + ToStringHelper(ast->AsETSNewClassInstanceExpression()->GetTypeRef()); - } - case ir::AstNodeType::STRING_LITERAL: { - return "STR_LITERAL " + ToStringHelper(ast->AsStringLiteral()->Str()); - } - case ir::AstNodeType::TRY_STATEMENT: { - return "TRY_STMT " + ToStringHelper(ast->AsTryStatement()->Block()); - } - case ir::AstNodeType::CATCH_CLAUSE: { - return "CATCH_CLAUSE "; - } - case ir::AstNodeType::NUMBER_LITERAL: { - return "NUMBER_LITERAL " + ToStringHelper(ast->AsNumberLiteral()->Str()); - } - case ir::AstNodeType::ETS_PARAMETER_EXPRESSION: { - return "ETS_PARAM_EXPR " + ToStringHelper(ast->AsETSParameterExpression()->Ident()); - } - case ir::AstNodeType::TS_INTERFACE_DECLARATION: { - return "TS_INTERFACE_DECL " + ToStringHelper(ast->AsTSInterfaceDeclaration()->Id()); - } - case ir::AstNodeType::TS_INTERFACE_BODY: { - return "TS_INTERFACE_BODY "; - } - case ir::AstNodeType::ETS_FUNCTION_TYPE: { - return "ETS_FUNC_TYPE " + - ToStringParamsHelper(ast->Parent(), ast->AsETSFunctionType()->Params()); - } - case ir::AstNodeType::TS_CLASS_IMPLEMENTS: { - return "TS_CLASS_IMPL " + ToStringHelper(ast->AsTSClassImplements()->Expr()); - } - default: { - return "MUST BE UNREACHABLE"; - } - } -} - -bool ASTVerifier::HasParent(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - if (ast->Parent() == nullptr) { - error_messages_.push_back("NULL_PARENT: " + ToStringHelper(ast)); - return false; - } - - return true; -} - -bool ASTVerifier::HaveParents(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - bool has_parent = HasParent(ast); - ast->IterateRecursively([this, &has_parent](ir::AstNode *child) { has_parent &= HasParent(child); }); - return has_parent; -} - -bool ASTVerifier::HasType(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - if (ast->IsTyped() && static_cast(ast)->TsType() == nullptr) { - error_messages_.push_back("NULL_TS_TYPE: " + ToStringHelper(ast)); - return false; - } - return true; -} - -bool ASTVerifier::HaveTypes(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - bool has_type = HasType(ast); - ast->IterateRecursively([this, &has_type](ir::AstNode *child) { has_type &= HasType(child); }); - return has_type; -} - -bool ASTVerifier::HasVariable(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - if (!ast->IsIdentifier() || ast->AsIdentifier()->Variable() != nullptr) { - return true; - } - - error_messages_.push_back("NULL_VARIABLE: " + ToStringHelper(ast->AsIdentifier())); - return false; -} - -bool ASTVerifier::HaveVariables(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - bool has_variable = HasVariable(ast); - ast->IterateRecursively([this, &has_variable](ir::AstNode *child) { has_variable &= HasVariable(child); }); - return has_variable; -} - -bool ASTVerifier::HasScope(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - if (!ast->IsIdentifier()) { - return true; // we will check only Identifier - } - // we will check only local variables of identifiers - if (HasVariable(ast) && ast->AsIdentifier()->Variable()->IsLocalVariable() && - ast->AsIdentifier()->Variable()->AsLocalVariable()->GetScope() == nullptr) { - error_messages_.push_back("NULL_SCOPE_LOCAL_VAR: " + ToStringHelper(ast)); - return false; - } - // NOTE(tatiana): Add check that the scope enclose this identifier - return true; -} - -bool ASTVerifier::HaveScopes(const ir::AstNode *ast) -{ - if (ast == nullptr) { - return false; - } - - bool has_scope = HasScope(ast); - ast->IterateRecursively([this, &has_scope](ir::AstNode *child) { has_scope &= HasScope(child); }); - return has_scope; -} - -} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ASTVerifier.h b/ets2panda/compiler/core/ASTVerifier.h deleted file mode 100644 index d9bdba1180982ab20a5050b1b263dfe8f9db2cda..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/core/ASTVerifier.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2021-2022 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_COMPILER_CORE_ASTVERIFIER_H -#define ES2PANDA_COMPILER_CORE_ASTVERIFIER_H - -#include "parser/program/program.h" - -namespace panda::es2panda::compiler { - -class ASTVerifier { -public: - using ErrorMessages = std::vector; - NO_COPY_SEMANTIC(ASTVerifier); - NO_MOVE_SEMANTIC(ASTVerifier); - - ASTVerifier() = default; - ~ASTVerifier() = default; - - bool IsCorrectProgram(const parser::Program *program); - bool HaveParents(const ir::AstNode *ast); - bool HasParent(const ir::AstNode *ast); - bool HaveTypes(const ir::AstNode *ast); - bool HasType(const ir::AstNode *ast); - bool HaveVariables(const ir::AstNode *ast); - bool HasVariable(const ir::AstNode *ast); - bool HasScope(const ir::AstNode *ast); - bool HaveScopes(const ir::AstNode *ast); - - ErrorMessages GetErrorMessages() - { - return error_messages_; - } - -private: - ErrorMessages error_messages_; -}; - -std::string ToStringHelper(const ir::AstNode *ast); - -} // namespace panda::es2panda::compiler - -#endif // ES2PANDA_COMPILER_CORE_ASTVERIFIER_H diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 4770e12ab3c3b6adab796ada779aa83caaa6a554..c7f91c0d7962a2e2b8797f073f71b64e0e9c642f 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,11 +15,13 @@ #include "ETSCompiler.h" -#include "checker/types/ets/etsDynamicFunctionType.h" -#include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/ETSGen.h" -#include "compiler/function/functionBuilder.h" +#include "ir/base/catchClause.h" +#include "ir/base/classProperty.h" +#include "ir/expressions/identifier.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/returnStatement.h" namespace panda::es2panda::compiler { @@ -196,42 +198,38 @@ void ETSCompiler::Compile(const ir::ETSPackageDeclaration *st) const void ETSCompiler::Compile(const ir::ETSParameterExpression *expr) const { - ETSGen *etsg = GetETSGen(); - expr->Ident()->Identifier::Compile(etsg); + (void)expr; + UNREACHABLE(); } -void ETSCompiler::Compile([[maybe_unused]] const ir::ETSPrimitiveType *node) const +void ETSCompiler::Compile(const ir::ETSPrimitiveType *node) const { + (void)node; UNREACHABLE(); } -void ETSCompiler::Compile([[maybe_unused]] const ir::ETSStructDeclaration *node) const +void ETSCompiler::Compile(const ir::ETSStructDeclaration *node) const { + (void)node; UNREACHABLE(); } void ETSCompiler::Compile(const ir::ETSTypeReference *node) const { - ETSGen *etsg = GetETSGen(); - node->Part()->Compile(etsg); + (void)node; + UNREACHABLE(); } void ETSCompiler::Compile(const ir::ETSTypeReferencePart *node) const -{ - ETSGen *etsg = GetETSGen(); - node->Name()->Compile(etsg); -} - -void ETSCompiler::Compile(const ir::ETSUnionType *node) const { (void)node; UNREACHABLE(); } -void ETSCompiler::Compile([[maybe_unused]] const ir::ETSWildcardType *node) const +void ETSCompiler::Compile(const ir::ETSWildcardType *node) const { - ETSGen *etsg = GetETSGen(); - etsg->Unimplemented(); + (void)node; + UNREACHABLE(); } // compile methods for EXPRESSIONS in alphabetical order void ETSCompiler::Compile(const ir::ArrayExpression *expr) const @@ -242,23 +240,8 @@ void ETSCompiler::Compile(const ir::ArrayExpression *expr) const void ETSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const { - ETSGen *etsg = GetETSGen(); - ASSERT(expr->ResolvedLambda() != nullptr); - auto *ctor = expr->ResolvedLambda()->TsType()->AsETSObjectType()->ConstructSignatures()[0]; - std::vector arguments; - - for (auto *it : expr->CapturedVars()) { - if (it->HasFlag(varbinder::VariableFlags::LOCAL)) { - arguments.push_back(it->AsLocalVariable()->Vreg()); - } - } - - if (expr->propagate_this_) { - arguments.push_back(etsg->GetThisReg()); - } - - etsg->InitLambdaObject(expr, ctor, arguments); - etsg->SetAccumulatorType(expr->resolved_lambda_->TsType()); + (void)expr; + UNREACHABLE(); } void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const @@ -602,6 +585,7 @@ void ETSCompiler::Compile(const ir::ReturnStatement *st) const } etsg->LoadBuiltinVoid(st); + } else { auto ttctx = compiler::TargetTypeContext(etsg, etsg->ReturnType()); @@ -625,6 +609,7 @@ void ETSCompiler::Compile(const ir::ReturnStatement *st) const etsg->LoadAccumulator(st, res); } + // etsg->ApplyConversion(st, st->ReturnType()); etsg->ReturnAcc(st); } diff --git a/ets2panda/compiler/core/ETSCompiler.h b/ets2panda/compiler/core/ETSCompiler.h index bbd98de6b3953f14afa6c4796deabf8930fa8225..91b2fbddc6381690af70dba216a497639f6f07b0 100644 --- a/ets2panda/compiler/core/ETSCompiler.h +++ b/ets2panda/compiler/core/ETSCompiler.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 49bef2b5e863afcea98eedff9a7f3111d67986c5..04fa62fea3b7c5b54a51eb49c30cce01c565ac03 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. @@ -21,20 +21,19 @@ #include "ir/expressions/assignmentExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/binaryExpression.h" -#include "ir/expressions/callExpression.h" #include "ir/expressions/memberExpression.h" #include "ir/expressions/templateLiteral.h" #include "ir/statements/breakStatement.h" #include "ir/statements/continueStatement.h" #include "ir/statements/tryStatement.h" #include "ir/ts/tsInterfaceDeclaration.h" -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "compiler/base/lreference.h" #include "compiler/base/catchTable.h" #include "compiler/core/dynamicContext.h" #include "compiler/core/compilerContext.h" -#include "varbinder/ETSBinder.h" -#include "varbinder/variable.h" +#include "binder/ETSBinder.h" +#include "binder/variable.h" #include "checker/types/type.h" #include "checker/types/typeFlag.h" #include "checker/checker.h" @@ -45,8 +44,8 @@ namespace panda::es2panda::compiler { -ETSGen::ETSGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, - varbinder::FunctionScope *scope, ProgramElement *program_element, AstCompiler *astcompiler) noexcept +ETSGen::ETSGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, binder::FunctionScope *scope, + ProgramElement *program_element, AstCompiler *astcompiler) noexcept : CodeGen(allocator, spiller, context, scope, program_element, astcompiler), containing_object_type_(util::Helpers::GetContainingObjectType(RootNode())) { @@ -68,9 +67,9 @@ const checker::ETSChecker *ETSGen::Checker() const noexcept return Context()->Checker()->AsETSChecker(); } -const varbinder::ETSBinder *ETSGen::VarBinder() const noexcept +const binder::ETSBinder *ETSGen::Binder() const noexcept { - return Context()->VarBinder()->AsETSBinder(); + return Context()->Binder()->AsETSBinder(); } const checker::Type *ETSGen::ReturnType() const noexcept @@ -114,7 +113,7 @@ void ETSGen::StoreAccumulator(const ir::AstNode *const node, const VReg vreg) { const auto *const acc_type = GetAccumulatorType(); - if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Ra().Emit(node, vreg); } else if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Ra().Emit(node, vreg); @@ -129,7 +128,7 @@ void ETSGen::LoadAccumulator(const ir::AstNode *node, VReg vreg) { const auto *const vreg_type = GetVRegType(vreg); - if (vreg_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (vreg_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Ra().Emit(node, vreg); } else if (vreg_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Ra().Emit(node, vreg); @@ -145,7 +144,7 @@ IRNode *ETSGen::AllocMov(const ir::AstNode *const node, const VReg vd, const VRe const auto *const source_type = GetVRegType(vs); auto *const mov = [this, source_type, node, vd, vs]() -> IRNode * { - if (source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { return Allocator()->New(node, vd, vs); } if (source_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { @@ -174,7 +173,7 @@ IRNode *ETSGen::AllocMov(const ir::AstNode *const node, OutVReg vd, const VReg v return Allocator()->New(node, *vd.reg, vs); } -checker::Type const *ETSGen::TypeForVar(varbinder::Variable const *var) const noexcept +checker::Type const *ETSGen::TypeForVar(binder::Variable const *var) const noexcept { return Checker()->MaybeBoxedType(var, Allocator()); } @@ -183,7 +182,7 @@ void ETSGen::MoveVreg(const ir::AstNode *const node, const VReg vd, const VReg v { const auto *const source_type = GetVRegType(vs); - if (source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Ra().Emit(node, vd, vs); } else if (source_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Ra().Emit(node, vd, vs); @@ -194,11 +193,11 @@ void ETSGen::MoveVreg(const ir::AstNode *const node, const VReg vd, const VReg v SetVRegType(vd, source_type); } -util::StringView ETSGen::FormDynamicModulePropReference(const varbinder::Variable *var) +util::StringView ETSGen::FormDynamicModulePropReference(const binder::Variable *var) { - ASSERT(VarBinder()->IsDynamicModuleVariable(var) || VarBinder()->IsDynamicNamespaceVariable(var)); + ASSERT(Binder()->IsDynamicModuleVariable(var) || Binder()->IsDynamicNamespaceVariable(var)); - auto *data = VarBinder()->DynamicImportDataForVar(var); + auto *data = Binder()->DynamicImportDataForVar(var); ASSERT(data != nullptr); auto *import = data->import; @@ -216,7 +215,7 @@ void ETSGen::LoadAccumulatorDynamicModule(const ir::AstNode *node, const ir::ETS util::StringView ETSGen::FormDynamicModulePropReference(const ir::ETSImportDeclaration *import) { std::stringstream ss; - auto pkg_name = VarBinder()->Program()->GetPackageName(); + auto pkg_name = Binder()->Program()->GetPackageName(); if (!pkg_name.Empty()) { ss << pkg_name << '.'; } @@ -227,11 +226,11 @@ util::StringView ETSGen::FormDynamicModulePropReference(const ir::ETSImportDecla return util::UString(ss.str(), Allocator()).View(); } -void ETSGen::LoadDynamicModuleVariable(const ir::AstNode *node, varbinder::Variable const *const var) +void ETSGen::LoadDynamicModuleVariable(const ir::AstNode *node, binder::Variable const *const var) { RegScope rs(this); - auto *data = VarBinder()->DynamicImportDataForVar(var); + auto *data = Binder()->DynamicImportDataForVar(var); auto *import = data->import; LoadStaticProperty(node, var->TsType(), FormDynamicModulePropReference(var)); @@ -248,19 +247,19 @@ void ETSGen::LoadDynamicModuleVariable(const ir::AstNode *node, varbinder::Varia } } -void ETSGen::LoadDynamicNamespaceVariable(const ir::AstNode *node, varbinder::Variable const *const var) +void ETSGen::LoadDynamicNamespaceVariable(const ir::AstNode *node, binder::Variable const *const var) { LoadStaticProperty(node, var->TsType(), FormDynamicModulePropReference(var)); } -void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const var) +void ETSGen::LoadVar(const ir::AstNode *node, binder::Variable const *const var) { - if (VarBinder()->IsDynamicModuleVariable(var)) { + if (Binder()->IsDynamicModuleVariable(var)) { LoadDynamicModuleVariable(node, var); return; } - if (VarBinder()->IsDynamicNamespaceVariable(var)) { + if (Binder()->IsDynamicNamespaceVariable(var)) { LoadDynamicNamespaceVariable(node, var); return; } @@ -294,7 +293,7 @@ void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const v } } - if (var->HasFlag(varbinder::VariableFlags::BOXED) && !node->AsIdentifier()->IsIgnoreBox()) { + if (var->HasFlag(binder::VariableFlags::BOXED) && !node->AsIdentifier()->IsIgnoreBox()) { EmitLocalBoxGet(node, var->TsType()); } @@ -303,7 +302,7 @@ void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const v } } -void ETSGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) +void ETSGen::StoreVar(const ir::AstNode *node, const binder::ConstScopeFindResult &result) { auto *local = result.variable->AsLocalVariable(); ApplyConversion(node, local->TsType()); @@ -319,7 +318,7 @@ void ETSGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindRe break; } case ReferenceKind::LOCAL: { - if (local->HasFlag(varbinder::VariableFlags::BOXED)) { + if (local->HasFlag(binder::VariableFlags::BOXED)) { EmitLocalBoxSet(node, local); } else { StoreAccumulator(node, local->Vreg()); @@ -353,7 +352,7 @@ util::StringView ETSGen::FormClassPropReference(const checker::ETSObjectType *cl return util::StringView(*res.first); } -util::StringView ETSGen::FormClassPropReference(varbinder::Variable const *const var) +util::StringView ETSGen::FormClassPropReference(binder::Variable const *const var) { auto containing_object_type = util::Helpers::GetContainingObjectType(var->Declaration()->Node()); return FormClassPropReference(containing_object_type, var->Name()); @@ -369,7 +368,7 @@ void ETSGen::StoreStaticOwnProperty(const ir::AstNode *node, const checker::Type void ETSGen::StoreStaticProperty(const ir::AstNode *const node, const checker::Type *prop_type, const util::StringView &full_name) { - if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Sa().Emit(node, full_name); } else if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Sa().Emit(node, full_name); @@ -381,7 +380,7 @@ void ETSGen::StoreStaticProperty(const ir::AstNode *const node, const checker::T void ETSGen::LoadStaticProperty(const ir::AstNode *const node, const checker::Type *prop_type, const util::StringView &full_name) { - if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Sa().Emit(node, full_name); } else if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Sa().Emit(node, full_name); @@ -397,7 +396,7 @@ void ETSGen::StoreProperty(const ir::AstNode *const node, const checker::Type *p { const auto full_name = FormClassPropReference(GetVRegType(obj_reg)->AsETSObjectType(), name); - if (node->IsIdentifier() && node->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::BOXED)) { + if (node->IsIdentifier() && node->AsIdentifier()->Variable()->HasFlag(binder::VariableFlags::BOXED)) { prop_type = Checker()->GlobalBuiltinBoxType(prop_type); } if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { @@ -412,10 +411,10 @@ void ETSGen::StoreProperty(const ir::AstNode *const node, const checker::Type *p void ETSGen::LoadProperty(const ir::AstNode *const node, const checker::Type *prop_type, const VReg obj_reg, const util::StringView &full_name) { - if (node->IsIdentifier() && node->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::BOXED)) { + if (node->IsIdentifier() && node->AsIdentifier()->Variable()->HasFlag(binder::VariableFlags::BOXED)) { prop_type = Checker()->GlobalBuiltinBoxType(prop_type); } - if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Ra().Emit(node, obj_reg, full_name); } else if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Ra().Emit(node, obj_reg, full_name); @@ -426,28 +425,6 @@ void ETSGen::LoadProperty(const ir::AstNode *const node, const checker::Type *pr SetAccumulatorType(prop_type); } -void ETSGen::StoreUnionProperty([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] VReg obj_reg, - [[maybe_unused]] const util::StringView &prop_name) -{ -#ifdef PANDA_WITH_ETS - Ra().Emit(node, obj_reg, prop_name); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS -} - -void ETSGen::LoadUnionProperty([[maybe_unused]] const ir::AstNode *const node, - [[maybe_unused]] const checker::Type *prop_type, [[maybe_unused]] const VReg obj_reg, - [[maybe_unused]] const util::StringView &prop_name) -{ -#ifdef PANDA_WITH_ETS - Ra().Emit(node, obj_reg, prop_name); - SetAccumulatorType(prop_type); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS -} - void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, const util::StringView &prop_name, Language lang) { @@ -495,7 +472,7 @@ void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type * StoreAccumulator(node, prop_name_reg); // Set property by name - Ra().Emit(node, method_name, obj_reg, prop_name_reg, prop_value_reg, dummy_reg_); + Ra().Emit(node, method_name, obj_reg, prop_name_reg, prop_value_reg, dummy_reg_); SetAccumulatorType(Checker()->GlobalVoidType()); } @@ -537,7 +514,7 @@ void ETSGen::LoadPropertyDynamic(const ir::AstNode *node, const checker::Type *p StoreAccumulator(node, prop_name_object); // Get property by name - Ra().Emit(node, method_name, obj_reg, prop_name_object); + Ra().Emit(node, method_name, obj_reg, prop_name_object); SetAccumulatorType(type); if (prop_type != type && !prop_type->IsETSDynamicType()) { @@ -555,7 +532,7 @@ void ETSGen::StoreElementDynamic(const ir::AstNode *node, VReg object_reg, VReg StoreAccumulator(node, value_reg); // Set property by index - Ra().Emit(node, method_name, object_reg, index, value_reg, dummy_reg_); + Ra().Emit(node, method_name, object_reg, index, value_reg, dummy_reg_); SetAccumulatorType(Checker()->GlobalVoidType()); } @@ -569,7 +546,7 @@ void ETSGen::LoadElementDynamic(const ir::AstNode *node, VReg object_reg, Langua StoreAccumulator(node, index_reg); // Get property by index - Ra().Emit(node, method_name, object_reg, index_reg); + Ra().Emit(node, method_name, object_reg, index_reg); SetAccumulatorType(Checker()->GlobalBuiltinDynamicType(lang)); } @@ -634,25 +611,25 @@ void ETSGen::InitLambdaObject(const ir::AstNode *node, checker::Signature *signa Ra().Emit(node, name, arguments[0], VReg::RegStart()); break; } - case 2U: { + case 2: { CONV_LAMBDA_CTOR_ARG(0); CONV_LAMBDA_CTOR_ARG(1); Ra().Emit(node, name, arguments[0], arguments[1]); break; } - case 3U: { + case 3: { CONV_LAMBDA_CTOR_ARG(0); CONV_LAMBDA_CTOR_ARG(1); CONV_LAMBDA_CTOR_ARG(2); - Ra().Emit(node, name, arguments[0], arguments[1], arguments[2U], VReg::RegStart()); + Ra().Emit(node, name, arguments[0], arguments[1], arguments[2], VReg::RegStart()); break; } - case 4U: { + case 4: { CONV_LAMBDA_CTOR_ARG(0); CONV_LAMBDA_CTOR_ARG(1); CONV_LAMBDA_CTOR_ARG(2); CONV_LAMBDA_CTOR_ARG(3); - Ra().Emit(node, name, arguments[0], arguments[1], arguments[2U], arguments[3U]); + Ra().Emit(node, name, arguments[0], arguments[1], arguments[2], arguments[3]); break; } default: { @@ -674,15 +651,12 @@ void ETSGen::InitLambdaObject(const ir::AstNode *node, checker::Signature *signa VReg ETSGen::GetThisReg() const { - const auto res = Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS); + const auto res = Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS); return res.variable->AsLocalVariable()->Vreg(); } void ETSGen::LoadDefaultValue([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] const checker::Type *type) { - if (type->IsETSUnionType()) { - type = Checker()->GetGlobalTypesHolder()->GlobalETSObjectType(); - } if (type->IsETSObjectType() || type->IsETSArrayType()) { LoadAccumulatorNull(node, type); } else if (type->IsETSBooleanType()) { @@ -708,7 +682,7 @@ void ETSGen::ReturnAcc(const ir::AstNode *node) { const auto *const acc_type = GetAccumulatorType(); - if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { + if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { Sa().Emit(node); } else if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Sa().Emit(node); @@ -721,7 +695,7 @@ void ETSGen::EmitIsInstance(const ir::AstNode *const node, const VReg lhs) { if (GetAccumulatorType()->IsETSDynamicType() || GetVRegType(lhs)->IsETSDynamicType()) { ASSERT(GetAccumulatorType()->IsETSDynamicType() && GetVRegType(lhs)->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, lhs, MoveAccToReg(node)); + Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, lhs, MoveAccToReg(node)); } else { SwapBinaryOpArgs(node, lhs); if (!GetVRegType(lhs)->IsETSNullType()) { @@ -1073,7 +1047,7 @@ void ETSGen::EmitLocalBoxGet(ir::AstNode const *node, checker::Type const *conte SetAccumulatorType(content_type); } -void ETSGen::EmitLocalBoxSet(ir::AstNode const *node, varbinder::LocalVariable *lhs_var) +void ETSGen::EmitLocalBoxSet(ir::AstNode const *node, binder::LocalVariable *lhs_var) { auto *content_type = lhs_var->TsType(); auto vreg = lhs_var->Vreg(); @@ -1449,7 +1423,7 @@ void ETSGen::CastToInt(const ir::AstNode *node) void ETSGen::CastToArrayOrObject(const ir::AstNode *const node, const checker::Type *const target_type, const bool unchecked) { - ASSERT(GetAccumulatorType()->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)); + ASSERT(GetAccumulatorType()->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)); const auto *const source_type = GetAccumulatorType(); if (source_type->IsETSDynamicType() && target_type->IsETSDynamicType()) { @@ -1482,7 +1456,7 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t return; } - // NOTE: itrubachev. Introduce checker::TypeFlag::LAMBDA_OBJECT and lambda object type itself in es2panda. + // TODO(itrubachev) Introduce checker::TypeFlag::LAMBDA_OBJECT and lambda object type itself in es2panda. // Now lambda object is any class with invoke method, that seems strange if (target_type->IsLambdaObject()) { VReg dyn_obj_reg = AllocReg(); @@ -1512,7 +1486,7 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t Sa().Emit(node, util::UString(ss.str(), Allocator()).View()); StoreAccumulator(node, type_reg); - Ra().Emit(node, method_name, dyn_obj_reg, type_reg); + Ra().Emit(node, method_name, dyn_obj_reg, type_reg); SetAccumulatorType(target_type); return; } @@ -1679,7 +1653,7 @@ void ETSGen::CastDynamicTo(const ir::AstNode *node, enum checker::TypeFlag type_ void ETSGen::EmitCheckedNarrowingReferenceConversion(const ir::AstNode *const node, const checker::Type *const target_type) { - ASSERT(target_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)); + ASSERT(target_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)); if (target_type->IsETSObjectType()) { Sa().Emit(node, target_type->AsETSObjectType()->AssemblerName()); @@ -1904,8 +1878,7 @@ void ETSGen::Negate(const ir::AstNode *node) void ETSGen::LogicalNot(const ir::AstNode *node) { - ASSERT(GetAccumulatorType()->IsConditionalExprType()); - ResolveConditionalResultIfFalse(node); + ASSERT(GetAccumulatorType()->IsETSBooleanType()); Sa().Emit(node, 1); } @@ -2113,27 +2086,21 @@ void ETSGen::BuildTemplateString(const ir::TemplateLiteral *node) auto builder = AllocReg(); StoreAccumulator(node, builder); - // Just to reduce extra nested level(s): - auto const append_expressions = [this, &builder](ArenaVector const &expressions, - ArenaVector const &quasis) -> void { - auto const num = expressions.size(); - std::size_t i = 0U; - - while (i < num) { - StringBuilderAppend(expressions[i], builder); - if (!quasis[++i]->Raw().Empty()) { - StringBuilderAppend(quasis[i], builder); - } - } - }; - if (auto const &quasis = node->Quasis(); !quasis.empty()) { if (!quasis[0]->Raw().Empty()) { StringBuilderAppend(quasis[0], builder); } if (auto const &expressions = node->Expressions(); !expressions.empty()) { - append_expressions(expressions, quasis); + auto const num = expressions.size(); + std::size_t i = 0U; + + while (i < num) { + StringBuilderAppend(expressions[i], builder); + if (!quasis[++i]->Raw().Empty()) { + StringBuilderAppend(quasis[i], builder); + } + } } } @@ -2270,18 +2237,6 @@ void ETSGen::LoadStringLength(const ir::AstNode *node) SetAccumulatorType(Checker()->GlobalIntType()); } -void ETSGen::FloatIsNaN(const ir::AstNode *node) -{ - Ra().Emit(node, Signatures::BUILTIN_FLOAT_IS_NAN, dummy_reg_, 0); - SetAccumulatorType(Checker()->GlobalETSBooleanType()); -} - -void ETSGen::DoubleIsNaN(const ir::AstNode *node) -{ - Ra().Emit(node, Signatures::BUILTIN_DOUBLE_IS_NAN, dummy_reg_, 0); - SetAccumulatorType(Checker()->GlobalETSBooleanType()); -} - void ETSGen::LoadStringChar(const ir::AstNode *node, const VReg string_obj, const VReg char_index) { Ra().Emit(node, Signatures::BUILTIN_STRING_CHAR_AT, string_obj, char_index); diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 77e6c004b0ad16b67b9bae23a7c36ac9496cec4f..c70e92e3786f1a7531de00d7a2c9fd9371268cc5 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -17,7 +17,7 @@ #define ES2PANDA_COMPILER_CORE_ETSGEN_H #include "ir/astNode.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "compiler/core/codeGen.h" #include "compiler/core/ETSfunction.h" #include "compiler/core/targetTypeContext.h" @@ -29,11 +29,10 @@ namespace panda::es2panda::compiler { class ETSGen final : public CodeGen { public: explicit ETSGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, - varbinder::FunctionScope *scope, ProgramElement *program_element, - AstCompiler *astcompiler) noexcept; + binder::FunctionScope *scope, ProgramElement *program_element, AstCompiler *astcompiler) noexcept; [[nodiscard]] const checker::ETSChecker *Checker() const noexcept; - [[nodiscard]] const varbinder::ETSBinder *VarBinder() const noexcept; + [[nodiscard]] const binder::ETSBinder *Binder() const noexcept; [[nodiscard]] const checker::Type *ReturnType() const noexcept; [[nodiscard]] const checker::ETSObjectType *ContainingObjectType() const noexcept; @@ -51,12 +50,12 @@ public: [[nodiscard]] IRNode *AllocMov(const ir::AstNode *node, OutVReg vd, VReg vs) override; void MoveVreg(const ir::AstNode *node, VReg vd, VReg vs); - [[nodiscard]] checker::Type const *TypeForVar(varbinder::Variable const *var) const noexcept override; + [[nodiscard]] checker::Type const *TypeForVar(binder::Variable const *var) const noexcept override; - void LoadVar(const ir::AstNode *node, varbinder::Variable const *var); - void LoadDynamicModuleVariable(const ir::AstNode *node, varbinder::Variable const *var); - void LoadDynamicNamespaceVariable(const ir::AstNode *node, varbinder::Variable const *var); - void StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result); + void LoadVar(const ir::AstNode *node, binder::Variable const *var); + void LoadDynamicModuleVariable(const ir::AstNode *node, binder::Variable const *var); + void LoadDynamicNamespaceVariable(const ir::AstNode *node, binder::Variable const *var); + void StoreVar(const ir::AstNode *node, const binder::ConstScopeFindResult &result); void LoadStaticProperty(const ir::AstNode *node, const checker::Type *prop_type, const util::StringView &full_name); void StoreStaticProperty(const ir::AstNode *node, const checker::Type *prop_type, @@ -78,10 +77,6 @@ public: void StoreElementDynamic(const ir::AstNode *node, VReg object_reg, VReg index, Language lang); void LoadElementDynamic(const ir::AstNode *node, VReg object_reg, Language lang); - void StoreUnionProperty(const ir::AstNode *node, VReg obj_reg, const util::StringView &name); - void LoadUnionProperty(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, - const util::StringView &prop_name); - void LoadUndefinedDynamic(const ir::AstNode *node, Language lang); void LoadThis(const ir::AstNode *node); @@ -101,158 +96,6 @@ public: bool TryLoadConstantExpression(const ir::Expression *node); void Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, Label *if_false); - template - void ResolveConditionalResultFloat(const ir::AstNode *node, [[maybe_unused]] Label *if_false, Label *end) - { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - VReg tmp_reg = AllocReg(); - StoreAccumulator(node, tmp_reg); - if (type->IsFloatType()) { - FloatIsNaN(node); - } else { - DoubleIsNaN(node); - } - - Sa().Emit(node, 1); - auto real_end_label = [](Label *end_label, Label *if_false_label, ETSGen *etsgn, bool use_false_label) { - if (use_false_label) { - return if_false_label; - } - if (end_label == nullptr) { - end_label = etsgn->AllocLabel(); - } - return end_label; - }(end, if_false, this, USE_FALSE_LABEL); - BranchIfFalse(node, real_end_label); - LoadAccumulator(node, tmp_reg); - VReg zero_reg = AllocReg(); - - if (type->IsFloatType()) { - MoveImmediateToRegister(node, zero_reg, checker::TypeFlag::FLOAT, 0); - BinaryNumberComparison(node, zero_reg, real_end_label); - } else { - MoveImmediateToRegister(node, zero_reg, checker::TypeFlag::DOUBLE, 0); - BinaryNumberComparison(node, zero_reg, real_end_label); - } - } - - template - void ResolveConditionalResultNumeric(const ir::AstNode *node, [[maybe_unused]] Label *if_false, Label *end) - { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - switch (type->TypeFlags()) { - case checker::TypeFlag::LONG: { - CastToInt(node); - [[fallthrough]]; - } - case checker::TypeFlag::BYTE: - case checker::TypeFlag::CHAR: - case checker::TypeFlag::SHORT: - case checker::TypeFlag::INT: { - if constexpr (BEFORE_LOGICAL_NOT) { - Label *zero_primitive = AllocLabel(); - BranchIfFalse(node, zero_primitive); - ToBinaryResult(node, zero_primitive); - } - break; - } - case checker::TypeFlag::DOUBLE: - case checker::TypeFlag::FLOAT: { - ResolveConditionalResultFloat(node, if_false, end); - break; - } - default: - break; - } - } - - template - void ResolveConditionalResultObject(const ir::AstNode *node, [[maybe_unused]] Label *if_false) - { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - if (type->IsETSStringType()) { - LoadStringLength(node); - if constexpr (BEFORE_LOGICAL_NOT) { - Label *zero_lenth = AllocLabel(); - BranchIfFalse(node, zero_lenth); - ToBinaryResult(node, zero_lenth); - } - } else { - Sa().Emit(node, 1); - } - } - - template - void ResolveConditionalResultExpression(const ir::AstNode *node, [[maybe_unused]] Label *if_false) - { - auto expr_node = node->AsExpression(); - if (Checker()->IsNullOrVoidExpression(expr_node)) { - if constexpr (USE_FALSE_LABEL) { - Branch(node, if_false); - } else { - Sa().Emit(node, 0); - } - return; - } - } - - template - void ResolveConditionalResult(const ir::AstNode *node, [[maybe_unused]] Label *if_false) - { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - if (type->IsETSObjectType() && - type->AsETSObjectType()->HasObjectFlag(panda::es2panda::checker::ETSObjectFlags::UNBOXABLE_TYPE)) { - type = GetAccumulatorType(); - } - if (type->IsETSBooleanType()) { - return; - } - - if (node->IsExpression()) { - ResolveConditionalResultExpression(node, if_false); - } - Label *if_nullable {nullptr}; - Label *end {nullptr}; - if (type->IsNullableType()) { - if constexpr (USE_FALSE_LABEL) { - BranchIfNull(node, if_false); - } else { - if_nullable = AllocLabel(); - end = AllocLabel(); - BranchIfNull(node, if_nullable); - } - } - if (type->IsETSArrayType()) { - compiler::VReg obj_reg = AllocReg(); - StoreAccumulator(node, obj_reg); - LoadArrayLength(node, obj_reg); - } else if (type->IsETSObjectType()) { - ResolveConditionalResultObject(node, if_false); - } else { - ResolveConditionalResultNumeric(node, if_false, end); - } - if (if_nullable != nullptr) { - Branch(node, end); - SetLabel(node, if_nullable); - Sa().Emit(node, 0); - } - if (end != nullptr) { - SetLabel(node, end); - } - } - - template - void ResolveConditionalResultIfFalse(const ir::AstNode *node, Label *if_false = nullptr) - { - ResolveConditionalResult(node, if_false); - } - - template - void ResolveConditionalResultIfTrue(const ir::AstNode *node, Label *if_false = nullptr) - { - ResolveConditionalResult(node, if_false); - } - void BranchIfFalse(const ir::AstNode *node, Label *if_false) { Sa().Emit(node, if_false); @@ -364,7 +207,7 @@ public: void EmitLocalBoxCtor(ir::AstNode const *node); void EmitLocalBoxGet(ir::AstNode const *node, checker::Type const *content_type); - void EmitLocalBoxSet(ir::AstNode const *node, varbinder::LocalVariable *lhs); + void EmitLocalBoxSet(ir::AstNode const *node, binder::LocalVariable *lhs); void LoadArrayLength(const ir::AstNode *node, VReg array_reg); void LoadArrayElement(const ir::AstNode *node, VReg object_reg); @@ -424,6 +267,11 @@ public: switch (value_type) { // NOTE: operand of increment instruction (INCI) is defined in spec as 32-bit integer, // but its current implementation actually can work with 64-bit integers as well. + // Thus, leave this case just in case for possible use in the future. + // case checker::TypeFlag::LONG: { + // Ra().Emit(node, reg, static_cast(value)); + // break; + // } case checker::TypeFlag::INT: { Ra().Emit(node, reg, static_cast(value)); break; @@ -457,9 +305,6 @@ public: void LoadStringLength(const ir::AstNode *node); void LoadStringChar(const ir::AstNode *node, VReg string_obj, VReg char_index); - void FloatIsNaN(const ir::AstNode *node); - void DoubleIsNaN(const ir::AstNode *node); - void CompileStatements(const ArenaVector &statements); // Cast @@ -535,7 +380,7 @@ public: void CallThisStatic2(const ir::AstNode *const node, const VReg ctor, const util::StringView name, const VReg arg0, const VReg arg1) { - Ra().Emit(node, name, ctor, arg0, arg1, dummy_reg_); + Ra().Emit(node, name, ctor, arg0, arg1, dummy_reg_); } void CallDynamic(const ir::AstNode *node, VReg &obj, VReg ¶m2, checker::Signature *signature, @@ -574,7 +419,7 @@ public: void GetType(const ir::AstNode *node, bool is_ets_primitive) { if (is_ets_primitive) { - // NOTE: SzD. LoadStaticProperty if ETS stdlib has static TYPE constants otherwise fallback to LdaType + // TODO(SzD) LoadStaticProperty if ETS stdlib has static TYPE constants otherwise fallback to LdaType } else { auto class_ref = GetAccumulatorType()->AsETSObjectType()->AssemblerName(); Sa().Emit(node, class_ref); @@ -591,7 +436,7 @@ private: void StringBuilderAppend(const ir::AstNode *node, VReg builder); void AppendString(const ir::Expression *bin_expr, VReg builder); void StringBuilder(const ir::Expression *left, const ir::Expression *right, VReg builder); - util::StringView FormClassPropReference(varbinder::Variable const *var); + util::StringView FormClassPropReference(binder::Variable const *var); void UnaryMinus(const ir::AstNode *node); void UnaryTilde(const ir::AstNode *node); void UnaryDollarDollar(const ir::AstNode *node); @@ -655,12 +500,9 @@ private: template void ConditionalBranching(const ir::AstNode *node, Label *if_false) { + SetAccumulatorType(Checker()->GlobalETSBooleanType()); if constexpr (std::is_same_v) { - ResolveConditionalResultIfTrue(node, if_false); - Sa().Emit(node); - Sa().Emit(node, 1); - } else { - ResolveConditionalResultIfFalse(node, if_false); + LogicalNot(node); } BranchIfFalse(node, if_false); } @@ -677,7 +519,6 @@ private: } else { CallThisVirtual1(node, lhs, Signatures::BUILTIN_OBJECT_EQUALS, arg0); } - SetAccumulatorType(Checker()->GlobalETSBooleanType()); ConditionalBranching(node, if_false); JumpTo(node, if_true); @@ -703,7 +544,7 @@ private: void BinaryDynamicStrictEquality(const ir::AstNode *node, VReg lhs, Label *if_false) { ASSERT(GetAccumulatorType()->IsETSDynamicType() && GetVRegType(lhs)->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_STRICT_EQUAL, lhs, MoveAccToReg(node)); + Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_STRICT_EQUAL, lhs, MoveAccToReg(node)); Ra().Emit(node, if_false); } @@ -902,22 +743,22 @@ private: const auto name = signature->InternalName(); switch (arguments.size()) { - case 0U: { + case 0: { Ra().Emit(node, name, ctor, dummy_reg_); break; } - case 1U: { + case 1: { COMPILE_ARG(0); Ra().Emit(node, name, ctor, arg0); break; } - case 2U: { + case 2: { COMPILE_ARG(0); COMPILE_ARG(1); - Ra().Emit(node, name, ctor, arg0, arg1, dummy_reg_); + Ra().Emit(node, name, ctor, arg0, arg1, dummy_reg_); break; } - case 3U: { + case 3: { COMPILE_ARG(0); COMPILE_ARG(1); COMPILE_ARG(2); @@ -951,29 +792,29 @@ private: const auto name = signature->InternalName(); switch (arguments.size()) { - case 0U: { + case 0: { Ra().Emit(node, name, dummy_reg_, dummy_reg_); break; } - case 1U: { + case 1: { COMPILE_ARG(0); Ra().Emit(node, name, arg0, dummy_reg_); break; } - case 2U: { + case 2: { COMPILE_ARG(0); COMPILE_ARG(1); Ra().Emit(node, name, arg0, arg1); break; } - case 3U: { + case 3: { COMPILE_ARG(0); COMPILE_ARG(1); COMPILE_ARG(2); - Ra().Emit(node, name, arg0, arg1, arg2, dummy_reg_); + Ra().Emit(node, name, arg0, arg1, arg2, dummy_reg_); break; } - case 4U: { + case 4: { COMPILE_ARG(0); COMPILE_ARG(1); COMPILE_ARG(2); @@ -1021,16 +862,16 @@ private: const auto name = signature->InternalName(); switch (arguments.size()) { - case 0U: { + case 0: { Ra().Emit(node, name, obj, param2); break; } - case 1U: { + case 1: { COMPILE_ARG(0); - Ra().Emit(node, name, obj, param2, arg0, dummy_reg_); + Ra().Emit(node, name, obj, param2, arg0, dummy_reg_); break; } - case 2U: { + case 2: { COMPILE_ARG(0); COMPILE_ARG(1); Ra().Emit(node, name, obj, param2, arg0, arg1); @@ -1049,7 +890,7 @@ private: index++; } - Rra().Emit(node, obj, arguments.size() + 2U, name, obj); + Rra().Emit(node, obj, arguments.size() + 2, name, obj); break; } } @@ -1069,7 +910,7 @@ private: void LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::TypeFlag target_type); void InitializeContainingClass(); - util::StringView FormDynamicModulePropReference(const varbinder::Variable *var); + util::StringView FormDynamicModulePropReference(const binder::Variable *var); util::StringView FormDynamicModulePropReference(const ir::ETSImportDeclaration *import); friend class TargetTypeContext; @@ -1082,9 +923,8 @@ private: template void ETSGen::LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::TypeFlag target_type) { - auto type_kind = target_type_ && (!target_type_->IsETSObjectType() && !target_type_->IsETSUnionType()) - ? checker::ETSChecker::TypeKind(target_type_) - : target_type; + auto type_kind = + target_type_ && !target_type_->IsETSObjectType() ? checker::ETSChecker::TypeKind(target_type_) : target_type; switch (type_kind) { case checker::TypeFlag::ETS_BOOLEAN: diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index a8589bcf512267dc099fad9d38cf86607d835d47..f74b9f7e1200ded9cf5f1c38f37f2a8a8e8b5d0d 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -16,9 +16,9 @@ #include "ETSemitter.h" #include "compiler/core/ETSGen.h" -#include "varbinder/varbinder.h" -#include "varbinder/variableFlags.h" -#include "varbinder/ETSBinder.h" +#include "binder/binder.h" +#include "binder/variableFlags.h" +#include "binder/ETSBinder.h" #include "ir/astNode.h" #include "ir/expressions/identifier.h" #include "ir/base/decorator.h" @@ -48,7 +48,7 @@ namespace panda::es2panda::compiler { #ifdef PANDA_WITH_ETS static constexpr auto EXTENSION = panda_file::SourceLang::ETS; #else -// NOTE: temporary dummy gn buildfix until ETS plugin has gn build support +// TODO: temporary dummy gn buildfix until ETS plugin has gn build support static constexpr auto EXTENSION = panda_file::SourceLang::PANDA_ASSEMBLY; #endif @@ -62,7 +62,7 @@ static uint32_t TranslateModifierFlags(ir::ModifierFlags modifier_flags) if ((modifier_flags & ir::ModifierFlags::PROTECTED) != 0) { access_flags = ACC_PROTECTED; } - // NOTE: torokg. Add ACC_INTERNAL access flag to libpandabase + // TODO(torokg): Add ACC_INTERNAL access flag to libpandabase } else if ((modifier_flags & ir::ModifierFlags::PROTECTED) != 0) { access_flags = ACC_PROTECTED; } else { @@ -135,7 +135,7 @@ pandasm::Function *ETSFunctionEmitter::GenFunctionSignature() } void ETSFunctionEmitter::GenVariableSignature(pandasm::debuginfo::LocalVariable &variable_debug, - [[maybe_unused]] varbinder::LocalVariable *variable) const + [[maybe_unused]] binder::LocalVariable *variable) const { variable_debug.signature = Signatures::ANY; variable_debug.signature_type = Signatures::ANY; @@ -192,9 +192,9 @@ static pandasm::Function GenExternalFunction(checker::Signature *signature, bool void ETSEmitter::GenAnnotation() { Program()->lang = EXTENSION; - const auto *varbinder = static_cast(Context()->VarBinder()); + const auto *binder = static_cast(Context()->Binder()); - auto *global_record_table = varbinder->GetGlobalRecordTable(); + auto *global_record_table = binder->GetGlobalRecordTable(); for (auto *class_decl : global_record_table->ClassDefinitions()) { GenClassRecord(class_decl, false); @@ -215,7 +215,7 @@ void ETSEmitter::GenAnnotation() Program()->function_table.emplace(func.name, std::move(func)); } - for (auto [extProg, recordTable] : varbinder->GetExternalRecordTable()) { + for (auto [extProg, recordTable] : binder->GetExternalRecordTable()) { (void)extProg; GenExternalRecord(recordTable); } @@ -227,9 +227,9 @@ void ETSEmitter::GenAnnotation() } } -void ETSEmitter::GenExternalRecord(varbinder::RecordTable *record_table) +void ETSEmitter::GenExternalRecord(binder::RecordTable *record_table) { - bool is_gen_std_lib = record_table->Program()->VarBinder()->IsGenStdLib(); + bool is_gen_std_lib = record_table->Program()->Binder()->IsGenStdLib(); for (auto *class_decl : record_table->ClassDefinitions()) { GenClassRecord(class_decl, !is_gen_std_lib); } @@ -362,7 +362,7 @@ void ETSEmitter::GenField(const checker::Type *ts_type, const util::StringView & void ETSEmitter::GenClassInheritedFields(const checker::ETSObjectType *base_type, pandasm::Record &class_record) { - std::vector foreign_props = base_type->ForeignProperties(); + std::vector foreign_props = base_type->ForeignProperties(); for (const auto *foreign_prop : foreign_props) { auto *decl_node = foreign_prop->Declaration()->Node(); @@ -412,7 +412,7 @@ void ETSEmitter::GenInterfaceRecord(const ir::TSInterfaceDeclaration *interface_ } interface_record.metadata->SetAccessFlags(access_flags); - interface_record.source_file = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + interface_record.source_file = Context()->Binder()->Program()->AbsoluteName().Mutf8(); interface_record.metadata->SetAttributeValue(Signatures::EXTENDS_ATTRIBUTE, Signatures::BUILTIN_OBJECT); for (auto *it : base_type->Interfaces()) { @@ -456,14 +456,16 @@ void ETSEmitter::GenClassRecord(const ir::ClassDefinition *class_def, bool exter } class_record.metadata->SetAccessFlags(access_flags); - class_record.source_file = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + class_record.source_file = Context()->Binder()->Program()->AbsoluteName().Mutf8(); auto *base_type = class_def->TsType()->AsETSObjectType(); + if (base_type->SuperType() != nullptr) { class_record.metadata->SetAttributeValue(Signatures::EXTENDS_ATTRIBUTE, base_type->SuperType()->AssemblerName().Mutf8()); } else { - // NOTE: rtakacs. Replace the whole if block (below) with assert when lambda objects have super class. + // TODO(rtakacs): replace the whole if block (below) with assert when lambda objects have super class. + // ASSERT(base_type->AssemblerName().Mutf8() == Signatures::BUILTIN_OBJECT); if (base_type->AssemblerName().Mutf8() != Signatures::BUILTIN_OBJECT) { class_record.metadata->SetAttributeValue(Signatures::EXTENDS_ATTRIBUTE, Signatures::BUILTIN_OBJECT); } @@ -476,7 +478,7 @@ void ETSEmitter::GenClassRecord(const ir::ClassDefinition *class_def, bool exter } auto *decl_node = it->GetDeclNode(); - // NOTE: itrubachev. replace it with ASSERT(decl_node->IsTSInterfaceDeclaration()) + // TODO(itrubachev): replace it with ASSERT(decl_node->IsTSInterfaceDeclaration()) // after adding proper creation of lambda object in ETSFunctionType::AssignmentSource if (!decl_node->IsTSInterfaceDeclaration()) { continue; diff --git a/ets2panda/compiler/core/ETSemitter.h b/ets2panda/compiler/core/ETSemitter.h index af3b1748bdd24d211d177d855155f3b079656198..cde1417ee8105e07477e01fa10048c7dbf03286f 100644 --- a/ets2panda/compiler/core/ETSemitter.h +++ b/ets2panda/compiler/core/ETSemitter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -18,9 +18,9 @@ #include "emitter.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class RecordTable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class ClassDefinition; @@ -58,7 +58,7 @@ protected: void GenFunctionAnnotations(pandasm::Function *func) override; void GenVariableSignature(pandasm::debuginfo::LocalVariable &variable_debug, - varbinder::LocalVariable *variable) const override; + binder::LocalVariable *variable) const override; }; class ETSEmitter : public Emitter { @@ -71,7 +71,7 @@ public: void GenAnnotation() override; private: - void GenExternalRecord(varbinder::RecordTable *record_table); + void GenExternalRecord(binder::RecordTable *record_table); void GenGlobalArrayRecord(checker::ETSArrayType *array_type, checker::Signature *signature); void GenClassRecord(const ir::ClassDefinition *class_def, bool external); void GenEnumRecord(const ir::TSEnumDeclaration *enum_decl, bool external); diff --git a/ets2panda/compiler/core/ETSfunction.cpp b/ets2panda/compiler/core/ETSfunction.cpp index e25e0915d014772397df95e050bd789622477f85..4df1cb5a4b2ec44d6a2c1d9797656aa70031a61b 100644 --- a/ets2panda/compiler/core/ETSfunction.cpp +++ b/ets2panda/compiler/core/ETSfunction.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,11 +15,11 @@ #include "ETSfunction.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" +#include "binder/binder.h" +#include "binder/ETSBinder.h" #include "util/helpers.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/lreference.h" #include "compiler/core/ETSGen.h" #include "compiler/core/envScope.h" @@ -48,6 +48,7 @@ void ETSFunction::CallImplicitCtor(ETSGen *etsg) auto res = std::find_if(super_type->ConstructSignatures().cbegin(), super_type->ConstructSignatures().cend(), [](const checker::Signature *sig) { return sig->Params().empty(); }); + if (res == super_type->ConstructSignatures().cend()) { return; } @@ -57,26 +58,24 @@ void ETSFunction::CallImplicitCtor(ETSGen *etsg) void ETSFunction::CompileSourceBlock(ETSGen *etsg, const ir::BlockStatement *block) { - auto const check_initializer = [](ArenaVector const &nodes) -> bool { - for (auto const *const node : nodes) { - if (node->IsMethodDefinition() && node->AsClassElement()->Key()->IsIdentifier()) { - if (node->AsClassElement()->Id()->Name() == compiler::Signatures::INIT_METHOD) { - return false; - } - } - } - return true; - }; - auto *script_func = etsg->RootNode()->AsScriptFunction(); - if (script_func->IsEnum()) { - // NOTE: add enum methods + // TODO(user): add enum methods } else if (script_func->IsStaticBlock()) { const auto *class_def = etsg->ContainingObjectType()->GetDeclNode()->AsClassDefinition(); // Check if it is the Global class static constructor and the special '_$init$_" method exists - bool const compile_initializer = class_def->IsGlobal() ? check_initializer(class_def->Body()) : true; + bool compile_initializer = true; + if (class_def->IsGlobal()) { + for (const auto *prop : class_def->Body()) { + if (prop->IsMethodDefinition() && prop->AsClassElement()->Key()->IsIdentifier()) { + if (prop->AsClassElement()->Key()->AsIdentifier()->Name() == compiler::Signatures::INIT_METHOD) { + compile_initializer = false; + break; + } + } + } + } for (const auto *prop : class_def->Body()) { if (!prop->IsClassProperty() || !prop->IsStatic()) { @@ -113,6 +112,7 @@ void ETSFunction::CompileSourceBlock(ETSGen *etsg, const ir::BlockStatement *blo if (script_func->IsConstructor() || script_func->IsStaticBlock() || script_func->IsEntryPoint()) { ASSERT(etsg->ReturnType() != etsg->Checker()->GlobalBuiltinVoidType()); etsg->EmitReturnVoid(block); + } else { ASSERT(!etsg->ReturnType()->IsETSVoidType()); etsg->LoadBuiltinVoid(block); @@ -149,7 +149,7 @@ void ETSFunction::CompileFunction(ETSGen *etsg) const auto *decl = etsg->RootNode()->AsScriptFunction(); if (const ir::AstNode *body = decl->Body(); body->IsExpression()) { - // NOTE + // TODO(user): } else { CompileSourceBlock(etsg, body->AsBlockStatement()); } diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index 23fc28f983e779a35e8f1d8cd8a810190aa0c3b6..a0b4815892d893a6432ee139e5fcea744c7a4b0c 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,10 +15,18 @@ #include "JSCompiler.h" -#include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" -#include "compiler/function/functionBuilder.h" +#include "ir/base/catchClause.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/scriptFunction.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/returnStatement.h" #include "util/helpers.h" namespace panda::es2panda::compiler { @@ -515,39 +523,39 @@ void JSCompiler::Compile(const ir::ETSPackageDeclaration *expr) const UNREACHABLE(); } -void JSCompiler::Compile([[maybe_unused]] const ir::ETSParameterExpression *expr) const -{ - UNREACHABLE(); -} - -void JSCompiler::Compile([[maybe_unused]] const ir::ETSPrimitiveType *expr) const +void JSCompiler::Compile(const ir::ETSParameterExpression *expr) const { + (void)expr; UNREACHABLE(); } -void JSCompiler::Compile([[maybe_unused]] const ir::ETSStructDeclaration *node) const +void JSCompiler::Compile(const ir::ETSPrimitiveType *expr) const { + (void)expr; UNREACHABLE(); } -void JSCompiler::Compile([[maybe_unused]] const ir::ETSTypeReference *expr) const +void JSCompiler::Compile(const ir::ETSStructDeclaration *node) const { + (void)node; UNREACHABLE(); } -void JSCompiler::Compile([[maybe_unused]] const ir::ETSTypeReferencePart *expr) const +void JSCompiler::Compile(const ir::ETSTypeReference *expr) const { + (void)expr; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ETSUnionType *node) const +void JSCompiler::Compile(const ir::ETSTypeReferencePart *expr) const { - (void)node; + (void)expr; UNREACHABLE(); } -void JSCompiler::Compile([[maybe_unused]] const ir::ETSWildcardType *expr) const +void JSCompiler::Compile(const ir::ETSWildcardType *expr) const { + (void)expr; UNREACHABLE(); } @@ -560,8 +568,8 @@ void JSCompiler::Compile(const ir::ArrayExpression *expr) const void JSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const { - PandaGen *pg = GetPandaGen(); - pg->DefineFunction(expr->Function(), expr->Function(), expr->Function()->Scope()->InternalName()); + (void)expr; + UNREACHABLE(); } void JSCompiler::Compile(const ir::AssignmentExpression *expr) const diff --git a/ets2panda/compiler/core/JSCompiler.h b/ets2panda/compiler/core/JSCompiler.h index 081389eca7472f88d8548c520ee6b81fd7393e9d..9ac913d79ea1e37793afb761377fc7995c0c26ae 100644 --- a/ets2panda/compiler/core/JSCompiler.h +++ b/ets2panda/compiler/core/JSCompiler.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/compiler/core/JSemitter.cpp b/ets2panda/compiler/core/JSemitter.cpp index bb0367ba175b18d2275f298261c1c8123ba8606e..f050cc9c2784f93c7e3995d0da5be0c7b3a40c2f 100644 --- a/ets2panda/compiler/core/JSemitter.cpp +++ b/ets2panda/compiler/core/JSemitter.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -16,7 +16,7 @@ #include "JSemitter.h" #include "compiler/core/pandagen.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "parser/program/program.h" #include "compiler/core/compilerContext.h" #include "assembly-program.h" @@ -45,7 +45,7 @@ pandasm::Function *JSFunctionEmitter::GenFunctionSignature() } void JSFunctionEmitter::GenVariableSignature(pandasm::debuginfo::LocalVariable &variable_debug, - [[maybe_unused]] varbinder::LocalVariable *variable) const + [[maybe_unused]] binder::LocalVariable *variable) const { variable_debug.signature = "any"; variable_debug.signature_type = "any"; @@ -77,7 +77,7 @@ void JSEmitter::GenAnnotation() #ifdef PANDA_WITH_ECMASCRIPT Program()->lang = panda_file::SourceLang::ECMASCRIPT; GenESAnnotationRecord(); - GenESModuleModeRecord(Context()->VarBinder()->Program()->Kind() == parser::ScriptKind::MODULE); + GenESModuleModeRecord(Context()->Binder()->Program()->Kind() == parser::ScriptKind::MODULE); #else UNREACHABLE(); #endif diff --git a/ets2panda/compiler/core/JSemitter.h b/ets2panda/compiler/core/JSemitter.h index 2a38cb6b1fd47b31000cb356a2a94c6951afdabb..429e154b8e4e9b6a1fa7f956ee5430102a03eca2 100644 --- a/ets2panda/compiler/core/JSemitter.h +++ b/ets2panda/compiler/core/JSemitter.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -37,7 +37,7 @@ protected: void GenFunctionAnnotations(pandasm::Function *func) override; void GenVariableSignature(pandasm::debuginfo::LocalVariable &variable_debug, - varbinder::LocalVariable *variable) const override; + binder::LocalVariable *variable) const override; }; class JSEmitter : public Emitter { diff --git a/ets2panda/compiler/core/codeGen.cpp b/ets2panda/compiler/core/codeGen.cpp index a94baabfd62a662f9035323e12f9948918d76ab4..fee8db4df1c9de2238c678937c1519e9bbe9466c 100644 --- a/ets2panda/compiler/core/codeGen.cpp +++ b/ets2panda/compiler/core/codeGen.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -36,12 +36,12 @@ const ArenaVector &CodeGen::CatchList() const noexcept return catch_list_; } -const varbinder::FunctionScope *CodeGen::TopScope() const noexcept +const binder::FunctionScope *CodeGen::TopScope() const noexcept { return top_scope_; } -const varbinder::Scope *CodeGen::Scope() const noexcept +const binder::Scope *CodeGen::Scope() const noexcept { return scope_; } @@ -106,7 +106,7 @@ const checker::Type *CodeGen::GetVRegType(const VReg vreg) const return it != type_map_.end() ? it->second : nullptr; } -checker::Type const *CodeGen::TypeForVar(varbinder::Variable const *var) const noexcept +checker::Type const *CodeGen::TypeForVar(binder::Variable const *var) const noexcept { return var->TsType(); } @@ -158,9 +158,9 @@ const util::StringView &CodeGen::FunctionName() const noexcept return top_scope_->Name(); } -varbinder::VarBinder *CodeGen::VarBinder() const noexcept +binder::Binder *CodeGen::Binder() const noexcept { - return context_->VarBinder(); + return context_->Binder(); } std::int32_t CodeGen::AddLiteralBuffer(LiteralBuffer &&buf) diff --git a/ets2panda/compiler/core/codeGen.h b/ets2panda/compiler/core/codeGen.h index 07a7c9164c3bb9a5c2b145ae938866b64f3d6633..65a1c6eeb47daab960bcc239defbec66f02b2ddd 100644 --- a/ets2panda/compiler/core/codeGen.h +++ b/ets2panda/compiler/core/codeGen.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -44,12 +44,12 @@ public: DEFAULT_MOVE_SEMANTIC(DebugInfo); ~DebugInfo() = default; - ArenaVector &VariableDebugInfo() + ArenaVector &VariableDebugInfo() { return variable_debug_info_; } - const ArenaVector &VariableDebugInfo() const + const ArenaVector &VariableDebugInfo() const { return variable_debug_info_; } @@ -62,7 +62,7 @@ public: private: friend class CodeGen; - ArenaVector variable_debug_info_; + ArenaVector variable_debug_info_; const ir::Statement *first_stmt_ {}; }; @@ -71,8 +71,7 @@ public: using TypeMap = ArenaUnorderedMap; explicit CodeGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, - varbinder::FunctionScope *scope, ProgramElement *program_element, - AstCompiler *astcompiler) noexcept + binder::FunctionScope *scope, ProgramElement *program_element, AstCompiler *astcompiler) noexcept : ast_compiler_(astcompiler), allocator_(allocator), context_(context), @@ -99,8 +98,8 @@ public: [[nodiscard]] ArenaAllocator *Allocator() const noexcept; [[nodiscard]] const ArenaVector &CatchList() const noexcept; - [[nodiscard]] const varbinder::FunctionScope *TopScope() const noexcept; - [[nodiscard]] const varbinder::Scope *Scope() const noexcept; + [[nodiscard]] const binder::FunctionScope *TopScope() const noexcept; + [[nodiscard]] const binder::Scope *Scope() const noexcept; [[nodiscard]] const ir::AstNode *RootNode() const noexcept; [[nodiscard]] ArenaVector &Insns() noexcept; @@ -124,7 +123,7 @@ public: [[nodiscard]] std::uint32_t InternalParamCount() const noexcept; [[nodiscard]] const util::StringView &InternalName() const noexcept; [[nodiscard]] const util::StringView &FunctionName() const noexcept; - [[nodiscard]] varbinder::VarBinder *VarBinder() const noexcept; + [[nodiscard]] binder::Binder *Binder() const noexcept; [[nodiscard]] Label *AllocLabel(); [[nodiscard]] std::int32_t AddLiteralBuffer(LiteralBuffer &&buf); @@ -152,7 +151,7 @@ public: [[nodiscard]] CompilerContext *Context() const noexcept; - [[nodiscard]] virtual checker::Type const *TypeForVar(varbinder::Variable const *var) const noexcept; + [[nodiscard]] virtual checker::Type const *TypeForVar(binder::Variable const *var) const noexcept; compiler::AstCompiler *GetAstCompiler() const; @@ -172,8 +171,8 @@ private: ArenaAllocator *allocator_ {}; CompilerContext *context_ {}; DebugInfo debug_info_; - varbinder::FunctionScope *top_scope_ {}; - varbinder::Scope *scope_ {}; + binder::FunctionScope *top_scope_ {}; + binder::Scope *scope_ {}; const ir::AstNode *root_node_ {}; ArenaVector insns_; ArenaVector catch_list_; diff --git a/ets2panda/compiler/core/compileJob.cpp b/ets2panda/compiler/core/compileJob.cpp index c2cc5c880fc14103e19d0847e98c05224ec1c0df..d9a3b77a89b083935b9bfbe19891bd5bfdcb53a5 100644 --- a/ets2panda/compiler/core/compileJob.cpp +++ b/ets2panda/compiler/core/compileJob.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. diff --git a/ets2panda/compiler/core/compileJob.h b/ets2panda/compiler/core/compileJob.h index 9c6175ba3c89f4a9c3800e06fba3355da9f0163d..db50df86972de63a89e5cf3a218344401033733d 100644 --- a/ets2panda/compiler/core/compileJob.h +++ b/ets2panda/compiler/core/compileJob.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -23,9 +23,9 @@ #include #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class FunctionScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::compiler { class CompilerContext; @@ -48,7 +48,7 @@ public: return &program_element_; } - void SetContext(CompilerContext *context, varbinder::FunctionScope *scope) + void SetContext(CompilerContext *context, binder::FunctionScope *scope) { context_ = context; scope_ = scope; @@ -62,7 +62,7 @@ private: std::mutex m_; std::condition_variable cond_; CompilerContext *context_ {}; - varbinder::FunctionScope *scope_ {}; + binder::FunctionScope *scope_ {}; ProgramElement program_element_; CompileJob *dependant_ {}; size_t dependencies_ {0}; diff --git a/ets2panda/compiler/core/compileQueue.cpp b/ets2panda/compiler/core/compileQueue.cpp index ea49298b98fd41536a51a0195d0eb29efa0e09e4..0804be0af0a654376180aa4c2f81775d426b09ae 100644 --- a/ets2panda/compiler/core/compileQueue.cpp +++ b/ets2panda/compiler/core/compileQueue.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. @@ -15,8 +15,8 @@ #include "compileQueue.h" -#include "varbinder/varbinder.h" -#include "varbinder/scope.h" +#include "binder/binder.h" +#include "binder/scope.h" #include "compiler/core/compilerContext.h" #include "compiler/core/emitter.h" #include "compiler/core/function.h" @@ -50,7 +50,7 @@ void CompileQueue::Schedule(CompilerContext *context) { ASSERT(jobs_count_ == 0); std::unique_lock lock(m_); - const auto &functions = context->VarBinder()->Functions(); + const auto &functions = context->Binder()->Functions(); jobs_ = new CompileJob[functions.size()](); for (auto *function : functions) { diff --git a/ets2panda/compiler/core/compileQueue.h b/ets2panda/compiler/core/compileQueue.h index 95b16d89e284a7dfdb34c7533d28c2eecbde0ce7..4544c756e12f7bcd35ee236460e10be2f1658877 100644 --- a/ets2panda/compiler/core/compileQueue.h +++ b/ets2panda/compiler/core/compileQueue.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -25,9 +25,9 @@ #include #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class FunctionScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::compiler { class CompilerContext; diff --git a/ets2panda/compiler/core/compilerContext.cpp b/ets2panda/compiler/core/compilerContext.cpp index 3e712f56a7067d35349a9e974dc491c58ccd64ee..5433157fb8443bd597fcc099d151782b5bf060bf 100644 --- a/ets2panda/compiler/core/compilerContext.cpp +++ b/ets2panda/compiler/core/compilerContext.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/compilerContext.h b/ets2panda/compiler/core/compilerContext.h index 592ad18ab80319a99add51197280cdee2d3647e4..b96b886992288e8ee0c2d002750a4894828b6af1 100644 --- a/ets2panda/compiler/core/compilerContext.h +++ b/ets2panda/compiler/core/compilerContext.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -24,10 +24,10 @@ #include #include -namespace panda::es2panda::varbinder { -class VarBinder; +namespace panda::es2panda::binder { +class Binder; class FunctionScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class Checker; @@ -44,11 +44,10 @@ class AstCompiler; class CompilerContext { public: using CodeGenCb = - std::function; + std::function; - CompilerContext(varbinder::VarBinder *varbinder, checker::Checker *checker, CompilerOptions options, - CodeGenCb code_gen_cb) - : varbinder_(varbinder), checker_(checker), options_(std::move(options)), code_gen_cb_(std::move(code_gen_cb)) + CompilerContext(binder::Binder *binder, checker::Checker *checker, CompilerOptions options, CodeGenCb code_gen_cb) + : binder_(binder), checker_(checker), options_(std::move(options)), code_gen_cb_(std::move(code_gen_cb)) { } @@ -56,9 +55,9 @@ public: NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; - varbinder::VarBinder *VarBinder() const + binder::Binder *Binder() const { - return varbinder_; + return binder_; } checker::Checker *Checker() const @@ -123,7 +122,7 @@ public: } private: - varbinder::VarBinder *varbinder_; + binder::Binder *binder_; checker::Checker *checker_; Emitter *emitter_ {}; std::vector buff_storage_; diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 14bc8b7fbdbde505a5043aef2087f4e2f417a36d..f5d80e417cab48fc5eccdaffbc61f9d4b8426568 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -31,10 +31,10 @@ #include "parser/TSparser.h" #include "parser/ETSparser.h" #include "parser/program/program.h" -#include "varbinder/JSBinder.h" -#include "varbinder/ASBinder.h" -#include "varbinder/TSBinder.h" -#include "varbinder/ETSBinder.h" +#include "binder/JSBinder.h" +#include "binder/ASBinder.h" +#include "binder/TSBinder.h" +#include "binder/ETSBinder.h" #include "checker/TSAnalyzer.h" #include "checker/TSchecker.h" #include "checker/ETSAnalyzer.h" @@ -78,39 +78,39 @@ panda::pandasm::Program *CompilerImpl::Emit(CompilerContext *context) template static CompilerContext::CodeGenCb MakeCompileJob() { - return [](CompilerContext *context, varbinder::FunctionScope *scope, - compiler::ProgramElement *program_element) -> void { - RegSpiller reg_spiller; - ArenaAllocator allocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - AstCompiler astcompiler; - CodeGen cg(&allocator, ®_spiller, context, scope, program_element, &astcompiler); - FunctionEmitter func_emitter(&cg, program_element); - func_emitter.Generate(); - }; + return + [](CompilerContext *context, binder::FunctionScope *scope, compiler::ProgramElement *program_element) -> void { + RegSpiller reg_spiller; + ArenaAllocator allocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + AstCompiler astcompiler; + CodeGen cg(&allocator, ®_spiller, context, scope, program_element, &astcompiler); + FunctionEmitter func_emitter(&cg, program_element); + func_emitter.Generate(); + }; } using EmitCb = std::function; using PhaseListGetter = std::function()>; -template +template static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const PhaseListGetter &get_phases, const EmitCb &emit_cb) { ArenaAllocator allocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - auto program = parser::Program::NewProgram(&allocator); + auto program = parser::Program::NewProgram(&allocator); program.MarkEntry(); auto parser = Parser(&program, unit.options, static_cast(unit.raw_parser_status)); auto checker = Checker(); auto analyzer = Analyzer(&checker); checker.SetAnalyzer(&analyzer); - auto *varbinder = program.VarBinder(); - varbinder->SetProgram(&program); + auto *binder = program.Binder(); + binder->SetProgram(&program); - CompilerContext context(varbinder, &checker, unit.options, + CompilerContext context(binder, &checker, unit.options, MakeCompileJob()); - varbinder->SetCompilerContext(&context); + binder->SetCompilerContext(&context); auto emitter = Emitter(&context); context.SetEmitter(&emitter); @@ -134,25 +134,25 @@ pandasm::Program *CompilerImpl::Compile(const CompilationUnit &unit) switch (unit.ext) { case ScriptExtension::TS: { - return CreateCompiler(unit, compiler::GetTrivialPhaseList, emit_cb); } case ScriptExtension::AS: { - return CreateCompiler(unit, compiler::GetTrivialPhaseList, emit_cb); } case ScriptExtension::ETS: { - return CreateCompiler(unit, compiler::GetETSPhaseList, emit_cb); } case ScriptExtension::JS: { - return CreateCompiler(unit, compiler::GetTrivialPhaseList, emit_cb); diff --git a/ets2panda/compiler/core/dynamicContext.cpp b/ets2panda/compiler/core/dynamicContext.cpp index b2c64eca4e938999970c3d0ad7f2c3b029968be8..366cb7d9232a311f0e7970f0710dffe6dc986196 100644 --- a/ets2panda/compiler/core/dynamicContext.cpp +++ b/ets2panda/compiler/core/dynamicContext.cpp @@ -263,6 +263,7 @@ void ETSTryContext::EmitFinalizer( } else { etsg->ReturnAcc(try_stmt_); } + } else if (insertion.second->IsBreakStatement()) { compiler::Label *target = etsg->ControlFlowChangeBreak(insertion.second->AsBreakStatement()->Ident()); etsg->Branch(try_stmt_, target); diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 42a9e1593868f1dfd6651a73876e1250091b5ac7..2c5f4f0943acb2f1021bea38404d7de99445d385 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -17,8 +17,8 @@ #include "ir/irnode.h" #include "util/helpers.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/literals.h" #include "compiler/core/compilerContext.h" #include "compiler/core/codeGen.h" @@ -121,7 +121,7 @@ void FunctionEmitter::Generate() util::StringView FunctionEmitter::SourceCode() const { - return cg_->VarBinder()->Program()->SourceCode(); + return cg_->Binder()->Program()->SourceCode(); } static Format MatchFormat(const IRNode *node, const Formats &formats) @@ -162,7 +162,7 @@ static size_t GetIRNodeWholeLength(const IRNode *node) const auto format = MatchFormat(node, formats); for (auto fi : format.GetFormatItem()) { - len += fi.BitWidth() / 8U; + len += fi.BitWidth() / 8; } return len; @@ -257,7 +257,7 @@ void FunctionEmitter::GenFunctionCatchTables(pandasm::Function *func) void FunctionEmitter::GenSourceFileDebugInfo(pandasm::Function *func) { - func->source_file = std::string {cg_->VarBinder()->Program()->AbsoluteName()}; + func->source_file = std::string {cg_->Binder()->Program()->AbsoluteName()}; if (!cg_->IsDebug()) { return; @@ -268,7 +268,7 @@ void FunctionEmitter::GenSourceFileDebugInfo(pandasm::Function *func) } } -static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variable_debug, varbinder::Variable *var, +static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variable_debug, binder::Variable *var, uint32_t start, uint32_t vars_length, uint32_t total_regs_num, const ScriptExtension extension) { @@ -281,7 +281,7 @@ static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variable_deb std::stringstream ss; var->AsLocalVariable()->TsType()->ToDebugInfoType(ss); variable_debug.signature = ss.str(); - variable_debug.signature_type = ss.str(); // NOTE: Handle typeParams, either class or interface + variable_debug.signature_type = ss.str(); // TODO() Handle typeParams, either class or interface } variable_debug.reg = @@ -290,7 +290,7 @@ static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variable_deb variable_debug.length = static_cast(vars_length); } -void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbinder::Scope *scope) const +void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const binder::Scope *scope) const { const auto *start_ins = scope->ScopeStart(); const auto *end_ins = scope->ScopeEnd(); @@ -298,7 +298,7 @@ void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbin uint32_t start = 0; uint32_t count = 0; - const auto extension = cg_->VarBinder()->Program()->Extension(); + const auto extension = cg_->Binder()->Program()->Extension(); for (const auto *it : cg_->Insns()) { if (start_ins == it) { @@ -347,7 +347,7 @@ void FunctionEmitter::GenVariablesDebugInfo(pandasm::Function *func) Emitter::Emitter(const CompilerContext *context) : context_(context) { prog_ = new pandasm::Program(); - prog_->function_table.reserve(context->VarBinder()->Functions().size()); + prog_->function_table.reserve(context->Binder()->Functions().size()); } Emitter::~Emitter() @@ -470,7 +470,7 @@ pandasm::Program *Emitter::Finalize(bool dump_debug_info, std::string_view globa dumper.Dump(); } - if (context_->VarBinder()->IsGenStdLib()) { + if (context_->Binder()->IsGenStdLib()) { auto it = prog_->record_table.find(std::string(global_class)); if (it != prog_->record_table.end()) { prog_->record_table.erase(it); diff --git a/ets2panda/compiler/core/emitter.h b/ets2panda/compiler/core/emitter.h index c5636ddd34f0517c04ef8c5e00e948484eb737ef..9f86ca2b19d2feb7f1054ffcafd0d5a8b8d923ac 100644 --- a/ets2panda/compiler/core/emitter.h +++ b/ets2panda/compiler/core/emitter.h @@ -35,10 +35,10 @@ struct LocalVariable; } // namespace debuginfo } // namespace panda::pandasm -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Scope; class LocalVariable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::compiler { class CodeGen; @@ -66,11 +66,11 @@ protected: virtual pandasm::Function *GenFunctionSignature() = 0; virtual void GenFunctionAnnotations(pandasm::Function *func) = 0; virtual void GenVariableSignature(pandasm::debuginfo::LocalVariable &variable_debug, - varbinder::LocalVariable *variable) const = 0; + binder::LocalVariable *variable) const = 0; void GenInstructionDebugInfo(const IRNode *ins, panda::pandasm::Ins *panda_ins); void GenFunctionInstructions(pandasm::Function *func); - void GenScopeVariableInfo(pandasm::Function *func, const varbinder::Scope *scope) const; + void GenScopeVariableInfo(pandasm::Function *func, const binder::Scope *scope) const; void GenSourceFileDebugInfo(pandasm::Function *func); void GenFunctionCatchTables(panda::pandasm::Function *func); void GenVariablesDebugInfo(pandasm::Function *func); diff --git a/ets2panda/compiler/core/envScope.cpp b/ets2panda/compiler/core/envScope.cpp index 606f28c297f5936e2955ff7d289519e43f56e7fb..3147472ba85b6dd40d002948aec57b8515c98fe4 100644 --- a/ets2panda/compiler/core/envScope.cpp +++ b/ets2panda/compiler/core/envScope.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -20,7 +20,7 @@ #include "ir/statement.h" namespace panda::es2panda::compiler { -ScopeContext::ScopeContext(CodeGen *cg, varbinder::Scope *new_scope) : cg_(cg), prev_scope_(cg_->scope_) +ScopeContext::ScopeContext(CodeGen *cg, binder::Scope *new_scope) : cg_(cg), prev_scope_(cg_->scope_) { cg->scope_ = new_scope; } @@ -47,7 +47,7 @@ EnvScope::~EnvScope() pg_->env_scope_ = prev_; } -void LoopEnvScope::CopyBindings(PandaGen *pg, varbinder::VariableScope *scope, varbinder::VariableFlags flag) +void LoopEnvScope::CopyBindings(PandaGen *pg, binder::VariableScope *scope, binder::VariableFlags flag) { if (!HasEnv()) { return; diff --git a/ets2panda/compiler/core/envScope.h b/ets2panda/compiler/core/envScope.h index 07f34944b7a09c8daa0d372ef0bebaf1046f92d7..a5b53e72b118a58ddf4bb8f58f85634b12fffe88 100644 --- a/ets2panda/compiler/core/envScope.h +++ b/ets2panda/compiler/core/envScope.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -16,7 +16,7 @@ #ifndef ES2PANDA_COMPILER_CORE_ENV_SCOPE_H #define ES2PANDA_COMPILER_CORE_ENV_SCOPE_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/irnode.h" #include "compiler/core/dynamicContext.h" #include "compiler/core/regScope.h" @@ -32,7 +32,7 @@ class PandaGen; class ScopeContext { public: - explicit ScopeContext(CodeGen *cg, varbinder::Scope *new_scope); + explicit ScopeContext(CodeGen *cg, binder::Scope *new_scope); ~ScopeContext(); NO_COPY_SEMANTIC(ScopeContext); @@ -40,7 +40,7 @@ public: private: CodeGen *cg_; - varbinder::Scope *prev_scope_; + binder::Scope *prev_scope_; }; class EnvScope { @@ -75,25 +75,25 @@ protected: class LoopEnvScope : public EnvScope { public: - explicit LoopEnvScope(PandaGen *pg, varbinder::LoopScope *scope, LabelTarget target) + explicit LoopEnvScope(PandaGen *pg, binder::LoopScope *scope, LabelTarget target) : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg, scope), lex_env_ctx_(this, pg, target) { - CopyBindings(pg, scope, varbinder::VariableFlags::PER_ITERATION); + CopyBindings(pg, scope, binder::VariableFlags::PER_ITERATION); } - explicit LoopEnvScope(PandaGen *pg, LabelTarget target, varbinder::LoopScope *scope) + explicit LoopEnvScope(PandaGen *pg, LabelTarget target, binder::LoopScope *scope) : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg), lex_env_ctx_(this, pg, target) { - CopyBindings(pg, scope, varbinder::VariableFlags::PER_ITERATION); + CopyBindings(pg, scope, binder::VariableFlags::PER_ITERATION); } - explicit LoopEnvScope(PandaGen *pg, varbinder::LoopDeclarationScope *scope) + explicit LoopEnvScope(PandaGen *pg, binder::LoopDeclarationScope *scope) : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg), lex_env_ctx_(this, pg, {}) { - CopyBindings(pg, scope, varbinder::VariableFlags::LOOP_DECL); + CopyBindings(pg, scope, binder::VariableFlags::LOOP_DECL); } - varbinder::VariableScope *Scope() const + binder::VariableScope *Scope() const { ASSERT(HasEnv()); return scope_; @@ -107,14 +107,14 @@ public: void CopyPetIterationCtx(); private: - static bool NeedEnv(varbinder::VariableScope *scope) + static bool NeedEnv(binder::VariableScope *scope) { return scope->IsVariableScope() && scope->AsVariableScope()->NeedLexEnv(); } - void CopyBindings(PandaGen *pg, varbinder::VariableScope *scope, varbinder::VariableFlags flag); + void CopyBindings(PandaGen *pg, binder::VariableScope *scope, binder::VariableFlags flag); - varbinder::VariableScope *scope_ {}; + binder::VariableScope *scope_ {}; LocalRegScope reg_scope_; LexEnvContext lex_env_ctx_; }; diff --git a/ets2panda/compiler/core/function.cpp b/ets2panda/compiler/core/function.cpp index b50d2aae908052ff9bbf75320ff8ff463b88b79c..d84c0a42b16ecfc666b7d208e630bd49ff6971d7 100644 --- a/ets2panda/compiler/core/function.cpp +++ b/ets2panda/compiler/core/function.cpp @@ -15,10 +15,10 @@ #include "function.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "util/helpers.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "ir/base/classDefinition.h" @@ -74,16 +74,16 @@ static void CompileFunctionParameterDeclaration(PandaGen *pg, const ir::ScriptFu for (const auto *param : func->Params()) { auto ref = JSLReference::Create(pg, param, true); - [[maybe_unused]] varbinder::Variable *param_var = ref.Variable(); + [[maybe_unused]] binder::Variable *param_var = ref.Variable(); if (ref.Kind() == ReferenceKind::DESTRUCTURING) { util::StringView name = util::Helpers::ToStringView(pg->Allocator(), index); - param_var = pg->Scope()->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); + param_var = pg->Scope()->FindLocal(name, binder::ResolveBindingOptions::BINDINGS); } ASSERT(param_var && param_var->IsLocalVariable()); - VReg param_reg = VReg(varbinder::VarBinder::MANDATORY_PARAMS_NUMBER + VReg::PARAM_START + index++); + VReg param_reg = VReg(binder::Binder::MANDATORY_PARAMS_NUMBER + VReg::PARAM_START + index++); ASSERT(param_var->LexicalBound() || param_var->AsLocalVariable()->Vreg() == param_reg); if (param->IsAssignmentPattern()) { diff --git a/ets2panda/compiler/core/function.h b/ets2panda/compiler/core/function.h index 063b107adf7e7cc3d7ff1d94cd78fc915ec2727c..e1539b2e08cd6177e3961f2be3c55062fbb30713 100644 --- a/ets2panda/compiler/core/function.h +++ b/ets2panda/compiler/core/function.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/moduleContext.cpp b/ets2panda/compiler/core/moduleContext.cpp index 81d9eeb00db98144381897d2f80f5a7d411a3552..c4522f64251ccc3d8c527ec9722afb073db781b0 100644 --- a/ets2panda/compiler/core/moduleContext.cpp +++ b/ets2panda/compiler/core/moduleContext.cpp @@ -15,8 +15,8 @@ #include "moduleContext.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "ir/expressions/literals/stringLiteral.h" @@ -25,7 +25,7 @@ #include "ir/module/importDeclaration.h" namespace panda::es2panda::compiler { -void CompileImports(PandaGen *pg, varbinder::ModuleScope *scope) +void CompileImports(PandaGen *pg, binder::ModuleScope *scope) { for (const auto &[importDecl, decls] : scope->Imports()) { pg->ImportModule(importDecl, importDecl->Source()->Str()); @@ -34,12 +34,12 @@ void CompileImports(PandaGen *pg, varbinder::ModuleScope *scope) pg->StoreAccumulator(importDecl, module_reg); for (const auto *decl : decls) { - varbinder::Variable *v = scope->FindLocal(decl->LocalName(), varbinder::ResolveBindingOptions::BINDINGS); + binder::Variable *v = scope->FindLocal(decl->LocalName()); if (!v->IsModuleVariable()) { ASSERT(decl->ImportName() == "*"); - varbinder::ConstScopeFindResult result(decl->LocalName(), scope, 0, v); + binder::ConstScopeFindResult result(decl->LocalName(), scope, 0, v); pg->StoreAccToLexEnv(decl->Node(), result, true); } else { v->AsModuleVariable()->ModuleReg() = module_reg; @@ -48,7 +48,7 @@ void CompileImports(PandaGen *pg, varbinder::ModuleScope *scope) } } -void CompileExports(PandaGen *pg, const varbinder::ModuleScope *scope) +void CompileExports(PandaGen *pg, const binder::ModuleScope *scope) { for (const auto &[exportDecl, decls] : scope->Exports()) { if (exportDecl->IsExportAllDeclaration()) { @@ -78,7 +78,7 @@ void CompileExports(PandaGen *pg, const varbinder::ModuleScope *scope) } } -void ModuleContext::Compile(PandaGen *pg, varbinder::ModuleScope *scope) +void ModuleContext::Compile(PandaGen *pg, binder::ModuleScope *scope) { CompileImports(pg, scope); CompileExports(pg, scope); diff --git a/ets2panda/compiler/core/moduleContext.h b/ets2panda/compiler/core/moduleContext.h index 1ed08b76c527dcb3dca67de2958c307ac5965288..6e7364479a9729c3ee1bf0fd88ead5bef93b880f 100644 --- a/ets2panda/compiler/core/moduleContext.h +++ b/ets2panda/compiler/core/moduleContext.h @@ -20,10 +20,10 @@ #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; class ModuleScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::compiler { class PandaGen; @@ -32,7 +32,7 @@ class ModuleContext { public: ModuleContext() = delete; - static void Compile(PandaGen *pg, varbinder::ModuleScope *scope); + static void Compile(PandaGen *pg, binder::ModuleScope *scope); }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/pandagen.cpp b/ets2panda/compiler/core/pandagen.cpp index b34886783bd654fb38310d7ca26a0e74bc805b39..a66c4f79d4036b1d30529d25810e63bc4b8450cb 100644 --- a/ets2panda/compiler/core/pandagen.cpp +++ b/ets2panda/compiler/core/pandagen.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. @@ -15,12 +15,12 @@ #include "pandagen.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "checker/checker.h" #include "checker/types/globalTypesHolder.h" #include "util/helpers.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/catchTable.h" #include "compiler/base/lexenv.h" #include "compiler/base/literals.h" @@ -257,8 +257,7 @@ using EcmaDirecteval = EcmaDisabled; #endif PandaGen::PandaGen(ArenaAllocator *const allocator, RegSpiller *const spiller, CompilerContext *const context, - varbinder::FunctionScope *const scope, ProgramElement *const program_element, - AstCompiler *astcompiler) + binder::FunctionScope *const scope, ProgramElement *const program_element, AstCompiler *astcompiler) : CodeGen(allocator, spiller, context, scope, program_element, astcompiler) { Function::Compile(this); @@ -418,25 +417,25 @@ void PandaGen::LoadConst(const ir::AstNode *node, Constant id) void PandaGen::GetFunctionObject(const ir::AstNode *node) { - LoadAccFromLexEnv(node, Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_FUNC)); + LoadAccFromLexEnv(node, Scope()->Find(binder::Binder::MANDATORY_PARAM_FUNC)); } void PandaGen::GetNewTarget(const ir::AstNode *node) { - LoadAccFromLexEnv(node, Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_NEW_TARGET)); + LoadAccFromLexEnv(node, Scope()->Find(binder::Binder::MANDATORY_PARAM_NEW_TARGET)); } void PandaGen::GetThis(const ir::AstNode *node) { - LoadAccFromLexEnv(node, Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS)); + LoadAccFromLexEnv(node, Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS)); } void PandaGen::SetThis(const ir::AstNode *node) { - StoreAccToLexEnv(node, Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS), true); + StoreAccToLexEnv(node, Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS), true); } -void PandaGen::LoadVar(const ir::Identifier *node, const varbinder::ConstScopeFindResult &result) +void PandaGen::LoadVar(const ir::Identifier *node, const binder::ConstScopeFindResult &result) { auto *var = result.variable; @@ -459,9 +458,9 @@ void PandaGen::LoadVar(const ir::Identifier *node, const varbinder::ConstScopeFi LoadAccFromLexEnv(node, result); } -void PandaGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, bool is_declaration) +void PandaGen::StoreVar(const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_declaration) { - varbinder::Variable *var = result.variable; + binder::Variable *var = result.variable; if (var == nullptr) { if (IsDirectEval()) { @@ -488,11 +487,11 @@ void PandaGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFind void PandaGen::LoadAccFromArgs(const ir::AstNode *node) { - if (!Scope()->HasFlag(varbinder::ScopeFlags::USE_ARGS)) { + if (!Scope()->HasFlag(binder::ScopeFlags::USE_ARGS)) { return; } - auto res = Scope()->Find(varbinder::VarBinder::FUNCTION_ARGUMENTS); + auto res = Scope()->Find(binder::Binder::FUNCTION_ARGUMENTS); ASSERT(res.scope); GetUnmappedArgs(node); @@ -622,12 +621,12 @@ VReg PandaGen::LexEnv() const noexcept return env_scope_->LexEnv(); } -void PandaGen::LoadAccFromLexEnv(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) +void PandaGen::LoadAccFromLexEnv(const ir::AstNode *node, const binder::ConstScopeFindResult &result) { VirtualLoadVar::Expand(this, node, result); } -void PandaGen::StoreAccToLexEnv(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, +void PandaGen::StoreAccToLexEnv(const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_declaration) { VirtualStoreVar::Expand(this, node, result, is_declaration); @@ -1652,7 +1651,7 @@ Operand PandaGen::ToNamedPropertyKey(const ir::Expression *prop, bool is_compute if (prop->IsStringLiteral()) { const util::StringView &str = prop->AsStringLiteral()->Str(); - /* NOTE: dbatyai. remove this when runtime handles __proto__ as property name correctly */ + /* TODO(dbatyai): remove this when runtime handles __proto__ as property name correctly */ if (str.Is("__proto__")) { return res; } @@ -1802,7 +1801,7 @@ void PandaGen::DirectEval(const ir::AstNode *node, uint32_t parser_status) void PandaGen::LoadLexicalContext(const ir::AstNode *node) { - auto result = Scope()->Find(varbinder::VarBinder::LEXICAL_CONTEXT_PARAM); + auto result = Scope()->Find(binder::Binder::LEXICAL_CONTEXT_PARAM); LoadLexicalVar(node, result.lex_level, result.variable->AsLocalVariable()->LexIdx()); } diff --git a/ets2panda/compiler/core/pandagen.h b/ets2panda/compiler/core/pandagen.h index 037e6fa4490e8354a0c56bb93f2f4937a74fb174..0709e5d89d2caf6a17f6579469649d3873069d87 100644 --- a/ets2panda/compiler/core/pandagen.h +++ b/ets2panda/compiler/core/pandagen.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -29,10 +29,10 @@ #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class FunctionScope; class Scope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class AstNode; @@ -50,7 +50,7 @@ class DynamicContext; class PandaGen final : public CodeGen { public: explicit PandaGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, - varbinder::FunctionScope *scope, ProgramElement *program_element, AstCompiler *astcompiler); + binder::FunctionScope *scope, ProgramElement *program_element, AstCompiler *astcompiler); ~PandaGen() override = default; NO_COPY_SEMANTIC(PandaGen); @@ -85,8 +85,8 @@ public: void GetNewTarget(const ir::AstNode *node); void GetThis(const ir::AstNode *node); void SetThis(const ir::AstNode *node); - void LoadVar(const ir::Identifier *node, const varbinder::ConstScopeFindResult &result); - void StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, bool is_declaration); + void LoadVar(const ir::Identifier *node, const binder::ConstScopeFindResult &result); + void StoreVar(const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_declaration); void LoadAccFromArgs(const ir::AstNode *node); void LoadObjProperty(const ir::AstNode *node, const Operand &prop); @@ -105,8 +105,8 @@ public: void TryLoadGlobalByName(const ir::AstNode *node, const util::StringView &name); void TryStoreGlobalByName(const ir::AstNode *node, const util::StringView &name); - void LoadAccFromLexEnv(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result); - void StoreAccToLexEnv(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result, bool is_declaration); + void LoadAccFromLexEnv(const ir::AstNode *node, const binder::ConstScopeFindResult &result); + void StoreAccToLexEnv(const ir::AstNode *node, const binder::ConstScopeFindResult &result, bool is_declaration); void LoadAccumulatorBigInt(const ir::AstNode *node, const util::StringView &big_int); diff --git a/ets2panda/compiler/core/programElement.cpp b/ets2panda/compiler/core/programElement.cpp index 07d847d8e07c6080bce65f2df1f9940f624a2052..bbbdd130eeabb16f52e78539650211ffd7190ec3 100644 --- a/ets2panda/compiler/core/programElement.cpp +++ b/ets2panda/compiler/core/programElement.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/programElement.h b/ets2panda/compiler/core/programElement.h index 998754ccf8e039cea6957c0b6b803265865bf82b..db5bd11d145fe9109e8f0d7efb0c3a155988149f 100644 --- a/ets2panda/compiler/core/programElement.h +++ b/ets2panda/compiler/core/programElement.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/regAllocator.cpp b/ets2panda/compiler/core/regAllocator.cpp index 07c2b353e266ed5c474cecefcb866c52e5519f3c..b4584f227dcd330a0c0124694f50cd32c27fd4ed 100644 --- a/ets2panda/compiler/core/regAllocator.cpp +++ b/ets2panda/compiler/core/regAllocator.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -128,6 +128,7 @@ VReg RegAllocatorBase::Spill(IRNode *const ins, const VReg reg) const void RegAllocatorBase::Restore(const IRNode *const ins) const { const auto spill_info = spiller_->Restore(); + if (spiller_->GetCodeGen()->GetVRegType(spill_info.OriginReg()) == nullptr) { return; } @@ -217,6 +218,7 @@ void RangeRegAllocator::Run(IRNode *const ins, VReg range_start, const std::size std::array regs {}; const auto reg_cnt = ins->Registers(®s); const auto registers = Span(regs.data(), regs.data() + reg_cnt); + if (RegIndicesValid(ins, registers).first) { PushBack(ins); return; diff --git a/ets2panda/compiler/core/regAllocator.h b/ets2panda/compiler/core/regAllocator.h index 29ab23031c6570cc432709a9759409cabeaa5b8d..9c7f8e46e69aacb537bc12e29db956c23d640615 100644 --- a/ets2panda/compiler/core/regAllocator.h +++ b/ets2panda/compiler/core/regAllocator.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/regScope.cpp b/ets2panda/compiler/core/regScope.cpp index 6e535fa1cf74f3fd1ca70e7b12bb63a1b8f9195e..96ff2ec599f3919d2c6be315d1c8ffea7ef85808 100644 --- a/ets2panda/compiler/core/regScope.cpp +++ b/ets2panda/compiler/core/regScope.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,9 +15,9 @@ #include "regScope.h" -#include "varbinder/varbinder.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/binder.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "compiler/base/hoisting.h" #include "compiler/core/codeGen.h" #include "compiler/core/pandagen.h" @@ -47,7 +47,7 @@ void RegScope::DebuggerCloseScope() LocalRegScope::LocalRegScope(PandaGen *pg) : RegScope(pg) {} -LocalRegScope::LocalRegScope(CodeGen *cg, varbinder::Scope *scope) : RegScope(cg) +LocalRegScope::LocalRegScope(CodeGen *cg, binder::Scope *scope) : RegScope(cg) { prev_scope_ = cg_->scope_; cg_->scope_ = scope; @@ -65,7 +65,7 @@ LocalRegScope::LocalRegScope(CodeGen *cg, varbinder::Scope *scope) : RegScope(cg } } -LocalRegScope::LocalRegScope(PandaGen *pg, varbinder::Scope *scope) : LocalRegScope(static_cast(pg), scope) +LocalRegScope::LocalRegScope(PandaGen *pg, binder::Scope *scope) : LocalRegScope(static_cast(pg), scope) { Hoisting::Hoist(pg); } @@ -85,7 +85,7 @@ LocalRegScope::~LocalRegScope() FunctionRegScope::FunctionRegScope(CodeGen *cg) : RegScope(cg) { - InitializeParams([](varbinder::LocalVariable *const param, const VReg param_reg) { param->BindVReg(param_reg); }); + InitializeParams([](binder::LocalVariable *const param, const VReg param_reg) { param->BindVReg(param_reg); }); } void FunctionRegScope::InitializeParams(const StoreParamCb &cb) @@ -135,7 +135,7 @@ FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), env_scope_(pg-> pg->StoreAccumulator(node, lex_env); - InitializeParams([pg, node](varbinder::LocalVariable *const param, const VReg param_reg) { + InitializeParams([pg, node](binder::LocalVariable *const param, const VReg param_reg) { if (param->LexicalBound()) { pg->LoadAccumulator(node, param_reg); pg->StoreLexicalVar(node, 0, param->LexIdx()); diff --git a/ets2panda/compiler/core/regScope.h b/ets2panda/compiler/core/regScope.h index 6fc8ce1137e87b8d4f764399da525d455977fb25..deceb3d88910f76bff545f01fa72098c4c418a7d 100644 --- a/ets2panda/compiler/core/regScope.h +++ b/ets2panda/compiler/core/regScope.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -17,7 +17,7 @@ #define ES2PANDA_COMPILER_CORE_REG_SCOPE_H #include "macros.h" -#include "varbinder/scope.h" +#include "binder/scope.h" namespace panda::es2panda::ir { class AstNode; @@ -49,8 +49,8 @@ protected: class LocalRegScope : public RegScope { public: - explicit LocalRegScope(PandaGen *pg, varbinder::Scope *scope); - explicit LocalRegScope(CodeGen *cg, varbinder::Scope *scope); + explicit LocalRegScope(PandaGen *pg, binder::Scope *scope); + explicit LocalRegScope(CodeGen *cg, binder::Scope *scope); explicit LocalRegScope(PandaGen *pg); NO_COPY_SEMANTIC(LocalRegScope); NO_MOVE_SEMANTIC(LocalRegScope); @@ -60,12 +60,12 @@ public: void *operator new[](size_t) = delete; private: - varbinder::Scope *prev_scope_ {}; + binder::Scope *prev_scope_ {}; }; class LoopRegScope : public RegScope { public: - explicit LoopRegScope(PandaGen *pg, varbinder::LoopScope *scope); + explicit LoopRegScope(PandaGen *pg, binder::LoopScope *scope); NO_COPY_SEMANTIC(LoopRegScope); NO_MOVE_SEMANTIC(LoopRegScope); ~LoopRegScope(); @@ -74,7 +74,7 @@ public: void *operator new[](size_t) = delete; private: - varbinder::Scope *prev_scope_ {}; + binder::Scope *prev_scope_ {}; }; class FunctionRegScope : public RegScope { @@ -89,7 +89,7 @@ public: void *operator new[](size_t) = delete; private: - using StoreParamCb = std::function; + using StoreParamCb = std::function; void InitializeParams(const StoreParamCb &cb); EnvScope *env_scope_ {}; }; diff --git a/ets2panda/compiler/core/regSpiller.cpp b/ets2panda/compiler/core/regSpiller.cpp index 468fd8b185dc8f8bba9d4fefc95eeabd9dbc0945..a2656e5ebe710d59a69ebd4551721397b7846c5b 100644 --- a/ets2panda/compiler/core/regSpiller.cpp +++ b/ets2panda/compiler/core/regSpiller.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/regSpiller.h b/ets2panda/compiler/core/regSpiller.h index aba5b3391aad74195a6f2d59e67e92a63ce4f237..1c2554b881ffa306d6b928119e5189d22db9ceaf 100644 --- a/ets2panda/compiler/core/regSpiller.h +++ b/ets2panda/compiler/core/regSpiller.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/core/targetTypeContext.cpp b/ets2panda/compiler/core/targetTypeContext.cpp index e40e3eb554ad953fc4d2375d0e1106d4d31bd604..55b53f9e09c24cd2878cd2c501bea2a1c8566dcd 100644 --- a/ets2panda/compiler/core/targetTypeContext.cpp +++ b/ets2panda/compiler/core/targetTypeContext.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/compiler/core/targetTypeContext.h b/ets2panda/compiler/core/targetTypeContext.h index f476a5b3e96b1aa7129ec34ace6c96c385d6060c..775f4d647fbc3a484bafe61230990bd019397b32 100644 --- a/ets2panda/compiler/core/targetTypeContext.h +++ b/ets2panda/compiler/core/targetTypeContext.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/compiler/core/vReg.cpp b/ets2panda/compiler/core/vReg.cpp index ccb80d7327d7c12046059624fbc37cbdccc1074a..83dabd39913cf1b6909f82246cfc344d9de0794f 100644 --- a/ets2panda/compiler/core/vReg.cpp +++ b/ets2panda/compiler/core/vReg.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/compiler/core/vReg.h b/ets2panda/compiler/core/vReg.h index cc56ed787b207feb7d37b75fb3c6c19a50bcae21..0e9b0385879bde13a471e1bef98b685d8aa0ab7f 100644 --- a/ets2panda/compiler/core/vReg.h +++ b/ets2panda/compiler/core/vReg.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/debugger/debuginfoDumper.cpp b/ets2panda/compiler/debugger/debuginfoDumper.cpp index 1ff0a7d9e79ab07205acb5315a7a8a4ed0bef3c6..ace63b0ec019d419cf25b1cb81f2608eb7434c76 100644 --- a/ets2panda/compiler/debugger/debuginfoDumper.cpp +++ b/ets2panda/compiler/debugger/debuginfoDumper.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -70,8 +70,11 @@ void DebugInfoDumper::WrapArray(const char *name, const std::vector &array, b ss_ << "\"" << *elem << "\""; // NOLINTNEXTLINE } else if constexpr (std::is_same_v>) { - ss_ << (std::holds_alternative(*elem) ? std::to_string(std::get(*elem)) - : std::to_string(std::get(*elem))); + if (std::holds_alternative(*elem)) { + ss_ << std::to_string(std::get(*elem)); + } else { + ss_ << std::to_string(std::get(*elem)); + } // NOLINTNEXTLINE } else { ss_ << std::to_string(*elem); diff --git a/ets2panda/compiler/debugger/debuginfoDumper.h b/ets2panda/compiler/debugger/debuginfoDumper.h index b0c581aaca82e911e4a84db54defe8ed29efe36e..03d6988938e45a0fadddb3fed98ba2915ab8503c 100644 --- a/ets2panda/compiler/debugger/debuginfoDumper.h +++ b/ets2panda/compiler/debugger/debuginfoDumper.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/function/asyncFunctionBuilder.cpp b/ets2panda/compiler/function/asyncFunctionBuilder.cpp index 5ff219746a5a3e12556be0bf4cc2fd904954f30e..3627b9950ce82ee618f08345468c20ea6765f8cf 100644 --- a/ets2panda/compiler/function/asyncFunctionBuilder.cpp +++ b/ets2panda/compiler/function/asyncFunctionBuilder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. diff --git a/ets2panda/compiler/function/asyncFunctionBuilder.h b/ets2panda/compiler/function/asyncFunctionBuilder.h index 5034debb73d5311f4aba956817a975a4b9582cbe..30ce7fde23aa2a9a9e3275bbdbeb25313b15b9be 100644 --- a/ets2panda/compiler/function/asyncFunctionBuilder.h +++ b/ets2panda/compiler/function/asyncFunctionBuilder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/function/functionBuilder.cpp b/ets2panda/compiler/function/functionBuilder.cpp index b1ff7f4d00e75930884e54966233331ff0157bc9..95a8ae550f7afbaceb1c1e2b9df3844ed4ea1954 100644 --- a/ets2panda/compiler/function/functionBuilder.cpp +++ b/ets2panda/compiler/function/functionBuilder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. @@ -15,7 +15,7 @@ #include "functionBuilder.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "util/helpers.h" #include "ir/statement.h" #include "ir/base/scriptFunction.h" @@ -84,8 +84,8 @@ void FunctionBuilder::ResumeGenerator(const ir::AstNode *node, VReg completion_t VReg FunctionBuilder::FunctionReg(const ir::ScriptFunction *node) const { - varbinder::FunctionScope *scope = node->Scope(); - auto res = scope->Find(varbinder::VarBinder::MANDATORY_PARAM_FUNC); + binder::FunctionScope *scope = node->Scope(); + auto res = scope->Find(binder::Binder::MANDATORY_PARAM_FUNC); ASSERT(res.level == 0 && res.variable->IsLocalVariable()); return res.variable->AsLocalVariable()->Vreg(); } @@ -93,7 +93,7 @@ VReg FunctionBuilder::FunctionReg(const ir::ScriptFunction *node) const void FunctionBuilder::Await(const ir::AstNode *node) { if (BuilderKind() == BuilderType::NORMAL) { - // NOTE: frobert. Implement top-level await + // TODO(frobert): Implement top-level await PandaGen::Unimplemented(); } diff --git a/ets2panda/compiler/function/functionBuilder.h b/ets2panda/compiler/function/functionBuilder.h index 3ca533d411cf540bc6ffd1febf8c57d53fe77648..9bde475c64804e84b4c4112b3aedf12cb38c5c09 100644 --- a/ets2panda/compiler/function/functionBuilder.h +++ b/ets2panda/compiler/function/functionBuilder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/function/generatorFunctionBuilder.cpp b/ets2panda/compiler/function/generatorFunctionBuilder.cpp index 95d9b8eb391d5c04b9e53578303e3c7bc0d80e5e..a75777811508b0dd0520df4b3895deeb1fb410f8 100644 --- a/ets2panda/compiler/function/generatorFunctionBuilder.cpp +++ b/ets2panda/compiler/function/generatorFunctionBuilder.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2022 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. diff --git a/ets2panda/compiler/function/generatorFunctionBuilder.h b/ets2panda/compiler/function/generatorFunctionBuilder.h index d9d162b7c00ba9f9aa59241fbf46b59fd74a8793..429266a69c87aa7b36bc94c98432ba0a79cdd467 100644 --- a/ets2panda/compiler/function/generatorFunctionBuilder.h +++ b/ets2panda/compiler/function/generatorFunctionBuilder.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/compiler/lowering/checkerPhase.cpp b/ets2panda/compiler/lowering/checkerPhase.cpp index 6ecae534d154401e6e0519e5a690617fd041e7e9..18e9df4221cc05bf5a67c7cecea55bed349c22cc 100644 --- a/ets2panda/compiler/lowering/checkerPhase.cpp +++ b/ets2panda/compiler/lowering/checkerPhase.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -20,7 +20,7 @@ namespace panda::es2panda::compiler { bool CheckerPhase::Perform(CompilerContext *ctx, [[maybe_unused]] parser::Program *program) { - return ctx->Checker()->StartChecker(ctx->VarBinder(), *ctx->Options()); + return ctx->Checker()->StartChecker(ctx->Binder(), *ctx->Options()); } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/checkerPhase.h b/ets2panda/compiler/lowering/checkerPhase.h index c6c076064238f19b4bf8d5954108872538135cc3..1fac2594bdedb9b13810871d0fd33ada56a722da 100644 --- a/ets2panda/compiler/lowering/checkerPhase.h +++ b/ets2panda/compiler/lowering/checkerPhase.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -20,10 +20,9 @@ namespace panda::es2panda::compiler { class CheckerPhase : public Phase { - std::string const &Name() override + util::StringView Name() override { - static std::string const NAME = "checker"; - return NAME; + return "checker"; } bool Perform(CompilerContext *ctx, parser::Program *program) override; diff --git a/ets2panda/compiler/lowering/ets/generateDeclarations.cpp b/ets2panda/compiler/lowering/ets/generateDeclarations.cpp index 3ea98c3b9be22c93ddaecd0a4edd4229d2e604f5..e29ed817310f4e723e5a64bf3472a5eab0d1268e 100644 --- a/ets2panda/compiler/lowering/ets/generateDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/generateDeclarations.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/compiler/lowering/ets/generateDeclarations.h b/ets2panda/compiler/lowering/ets/generateDeclarations.h index a59f1c6e047b794acd85a6780bb85850c006ed1d..a3fd6bdebabd1ee74547de7b34fc951288d74f78 100644 --- a/ets2panda/compiler/lowering/ets/generateDeclarations.h +++ b/ets2panda/compiler/lowering/ets/generateDeclarations.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -22,10 +22,9 @@ namespace panda::es2panda::compiler { class GenerateTsDeclarationsPhase : public Phase { public: - std::string const &Name() override + util::StringView Name() override { - static std::string const NAME = "generate-ts-declarations"; - return NAME; + return "generate-ts-declarations"; } bool Perform(CompilerContext *ctx, parser::Program *program) override; }; diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index abdc6fc3a22df5d19a22a477e92fdb96276d9788..31913c1a395f74a6ed6f065381c2876bdd962dcd 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -13,20 +13,20 @@ * limitations under the License. */ -// -// 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 -// once. -// +/** + * This is a sample lowering, of little value by itself. + * TODO(gogabr): + * - 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 + * once. + */ #include "opAssignment.h" #include "checker/types/typeFlag.h" -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "checker/ETSchecker.h" #include "compiler/core/compilerContext.h" #include "compiler/lowering/util.h" @@ -44,10 +44,9 @@ namespace panda::es2panda::compiler { -std::string const &OpAssignmentLowering::Name() +util::StringView OpAssignmentLowering::Name() { - static std::string const NAME = "op-assignment"; - return NAME; + return "op-assignment"; } struct Conversion { @@ -131,7 +130,7 @@ static ir::AstNode *CloneNode(checker::ETSChecker *checker, ir::AstNode *ast) 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. + // TODO(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. // Then this function will become unnecessary. const ir::BoxingUnboxingFlags old_boxing_flag {old_expr->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG}; @@ -148,7 +147,7 @@ void AdjustBoxingUnboxingFlags(ir::Expression *new_expr, const ir::Expression *o ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, ir::AssignmentExpression *assignment) { - if (assignment->TsType() == nullptr) { // hasn't been through checker + if (assignment->TsType() == nullptr) { // hasn't been throiugh checker return assignment; } @@ -174,8 +173,8 @@ ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, ir::AssignmentE 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); + auto *tmp_obj_var = scope->AddDecl( + checker->Allocator(), tmp_obj_var_id->Name(), binder::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()); @@ -187,8 +186,8 @@ ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, ir::AssignmentE 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); + auto *tmp_prop_var = scope->AddDecl( + checker->Allocator(), tmp_prop_var_id->Name(), binder::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()); diff --git a/ets2panda/compiler/lowering/ets/opAssignment.h b/ets2panda/compiler/lowering/ets/opAssignment.h index 30d20d0fd7a996cf241a88a9954dc6fe84b477c4..f85facad8559bcdd92720fa0b337ce700bff768d 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.h +++ b/ets2panda/compiler/lowering/ets/opAssignment.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -22,7 +22,7 @@ namespace panda::es2panda::compiler { class OpAssignmentLowering : public Phase { public: - std::string const &Name() override; + util::StringView Name() override; bool Perform(CompilerContext *ctx, parser::Program *program) override; bool Postcondition(CompilerContext *ctx, const parser::Program *program) override; }; diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp deleted file mode 100644 index 9aa3a1c893323672719eb9947a3f257780595b86..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/** - * 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 "unionLowering.h" -#include "varbinder/variableFlags.h" -#include "varbinder/ETSBinder.h" -#include "checker/ETSchecker.h" -#include "compiler/core/compilerContext.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classProperty.h" -#include "ir/astNode.h" -#include "ir/expression.h" -#include "ir/opaqueTypeNode.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/sequenceExpression.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/classDeclaration.h" -#include "ir/ts/tsAsExpression.h" -#include "type_helper.h" - -namespace panda::es2panda::compiler { - -std::string const &UnionLowering::Name() -{ - static std::string const NAME = "union-property-access"; - return NAME; -} - -ir::ClassDefinition *CreateUnionFieldClass(checker::ETSChecker *checker, varbinder::VarBinder *varbinder) -{ - // Create the name for the synthetic class node - util::UString union_field_class_name(util::StringView(panda_file::GetDummyClassName()), checker->Allocator()); - varbinder::Variable *found_var = nullptr; - if ((found_var = checker->Scope()->FindLocal(union_field_class_name.View(), - varbinder::ResolveBindingOptions::BINDINGS)) != nullptr) { - return found_var->Declaration()->Node()->AsClassDeclaration()->Definition(); - } - auto *ident = checker->AllocNode(union_field_class_name.View(), checker->Allocator()); - auto [decl, var] = varbinder->NewVarDecl(ident->Start(), ident->Name()); - ident->SetVariable(var); - - auto class_ctx = varbinder::LexicalScope(varbinder); - auto *class_def = checker->AllocNode(checker->Allocator(), class_ctx.GetScope(), ident, - ir::ClassDefinitionModifiers::GLOBAL, - ir::ModifierFlags::NONE, Language(Language::Id::ETS)); - - auto *class_decl = checker->AllocNode(class_def, checker->Allocator()); - class_def->Scope()->BindNode(class_decl); - class_def->SetTsType(checker->GlobalETSObjectType()); - decl->BindNode(class_decl); - var->SetScope(class_def->Scope()); - - varbinder->AsETSBinder()->BuildClassDefinition(class_def); - return class_def; -} - -void CreateUnionFieldClassProperty(ArenaAllocator *allocator, varbinder::VarBinder *varbinder, - ir::ClassDefinition *class_def, checker::Type *field_type, - const util::StringView &prop_name) -{ - auto *class_scope = class_def->Scope()->AsClassScope(); - // Enter the union filed class instance field scope - auto field_ctx = - varbinder::LexicalScope::Enter(varbinder, class_scope->InstanceFieldScope()); - - if (class_scope->FindLocal(prop_name, varbinder::ResolveBindingOptions::VARIABLES) != nullptr) { - return; - } - - // Create field name for synthetic class - auto *field_ident = allocator->New(prop_name, allocator); - - // Create the synthetic class property node - auto *field = - allocator->New(field_ident, nullptr, nullptr, ir::ModifierFlags::NONE, allocator, false); - - // Add the declaration to the scope - auto [decl, var] = varbinder->NewVarDecl(field_ident->Start(), field_ident->Name()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); - var->SetTsType(field_type); - field_ident->SetVariable(var); - field->SetTsType(field_type); - decl->BindNode(field); - - ArenaVector field_decl {allocator->Adapter()}; - field_decl.push_back(field); - class_def->AddProperties(std::move(field_decl)); -} - -ir::Expression *HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinder *varbinder, - ir::MemberExpression *expr) -{ - auto *class_def = CreateUnionFieldClass(checker, varbinder); - CreateUnionFieldClassProperty(checker->Allocator(), varbinder, class_def, expr->PropVar()->TsType(), - expr->Property()->AsIdentifier()->Name()); - if (expr->Object()->IsIdentifier()) { - auto *new_ts_type = expr->Object()->TsType()->AsETSUnionType()->GetLeastUpperBoundType(checker); - expr->Object()->AsIdentifier()->Variable()->SetTsType(new_ts_type); - } - return expr; -} - -ir::Expression *HandleUnionFunctionParameter(checker::ETSChecker *checker, ir::ETSParameterExpression *param) -{ - auto *union_type = param->Ident()->Variable()->TsType()->AsETSUnionType(); - param->Ident()->Variable()->SetTsType(union_type->GetLeastUpperBoundType(checker)); - return param; -} - -ir::Expression *HandleBinaryExpressionWithUnion(checker::ETSChecker *checker, ir::BinaryExpression *expr) -{ - auto *union_type = expr->OperationType()->AsETSUnionType(); - ir::Expression *union_node; - ir::Expression *other_union_node = nullptr; - checker::Type *other_node_type; - if (expr->Left()->TsType()->IsETSUnionType()) { - union_node = expr->Left(); - other_node_type = expr->Right()->TsType(); - if (other_node_type->IsETSUnionType()) { - other_union_node = expr->Right(); - } - } else { - union_node = expr->Right(); - other_node_type = expr->Left()->TsType(); - } - auto *source_type = - union_type->AsETSUnionType()->FindTypeIsCastableToSomeType(union_node, checker->Relation(), other_node_type); - if (source_type == nullptr) { - checker->ThrowTypeError("Bad operand type, some type of the union must be the same type as other expression.", - expr->Start()); - } - if ((union_node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U && - source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { - union_node->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); - } - auto *union_type_node = checker->AllocNode(source_type); - auto *as_expression = checker->AllocNode(union_node, union_type_node, false); - as_expression->SetParent(expr); - expr->SetOperationType(source_type); - if (other_union_node != nullptr) { - auto *other_union_type_node = checker->AllocNode(other_node_type); - auto *other_as_expression = - checker->AllocNode(other_union_node, other_union_type_node, false); - other_as_expression->SetParent(expr); - } - expr->SetTsType(checker->GlobalETSBooleanType()); - return expr; -} - -bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) -{ - for (auto &[_, ext_programs] : program->ExternalSources()) { - (void)_; - for (auto *ext_prog : ext_programs) { - Perform(ctx, ext_prog); - } - } - - checker::ETSChecker *checker = ctx->Checker()->AsETSChecker(); - - program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType()) { - return HandleUnionPropertyAccess(checker, ctx->VarBinder(), ast->AsMemberExpression()); - } - - if (ast->IsETSParameterExpression() && - ast->AsETSParameterExpression()->Ident()->Variable()->TsType() != nullptr && - ast->AsETSParameterExpression()->Ident()->Variable()->TsType()->IsETSUnionType()) { - return HandleUnionFunctionParameter(checker, ast->AsETSParameterExpression()); - } - - if (ast->IsBinaryExpression() && ast->AsBinaryExpression()->OperationType() != nullptr && - ast->AsBinaryExpression()->OperationType()->IsETSUnionType()) { - return HandleBinaryExpressionWithUnion(checker, ast->AsBinaryExpression()); - } - - return ast; - }); - - return true; -} - -bool UnionLowering::Postcondition(CompilerContext *ctx, const parser::Program *program) -{ - if (ctx->Options()->compilation_mode != CompilationMode::GEN_STD_LIB) { - return !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { - return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && - ast->AsMemberExpression()->Object()->IsIdentifier() && - ast->AsMemberExpression()->Object()->AsIdentifier()->Variable()->TsType()->IsETSUnionType(); - }); - } - - for (auto &[_, ext_programs] : program->ExternalSources()) { - (void)_; - for (auto *ext_prog : ext_programs) { - if (!Postcondition(ctx, ext_prog)) { - return false; - } - } - } - - return !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { - return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && - ast->AsMemberExpression()->Object()->IsIdentifier() && - ast->AsMemberExpression()->Object()->AsIdentifier()->Variable()->TsType()->IsETSUnionType(); - }); -} - -} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/unionLowering.h b/ets2panda/compiler/lowering/ets/unionLowering.h deleted file mode 100644 index beddab61fefe5071cf775359b7414cfd7ea96f9c..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/unionLowering.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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_COMPILER_LOWERING_UNION_LOWERING_H -#define ES2PANDA_COMPILER_LOWERING_UNION_LOWERING_H - -#include "compiler/lowering/phase.h" - -namespace panda::es2panda::compiler { - -class UnionLowering : public Phase { -public: - std::string const &Name() override; - bool Perform(CompilerContext *ctx, parser::Program *program) override; - bool Postcondition(CompilerContext *ctx, const parser::Program *program) override; -}; - -} // namespace panda::es2panda::compiler - -#endif diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index c95b0eb067f67d4a82b61938fb3893e64795c126..5877c6e4907ef23c263a0290514724a6c3c3becb 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,13 +15,11 @@ #include "phase.h" #include "checker/checker.h" -#include "compiler/core/ASTVerifier.h" #include "compiler/core/compilerContext.h" #include "lexer/token/sourceLocation.h" #include "compiler/lowering/checkerPhase.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/opAssignment.h" -#include "compiler/lowering/ets/unionLowering.h" namespace panda::es2panda::compiler { @@ -36,7 +34,6 @@ std::vector GetTrivialPhaseList() static GenerateTsDeclarationsPhase GENERATE_TS_DECLARATIONS_PHASE; static OpAssignmentLowering OP_ASSIGNMENT_LOWERING; -static UnionLowering UNION_LOWERING; std::vector GetETSPhaseList() { @@ -44,7 +41,6 @@ std::vector GetETSPhaseList() &CHECKER_PHASE, &GENERATE_TS_DECLARATIONS_PHASE, &OP_ASSIGNMENT_LOWERING, - &UNION_LOWERING, }; } @@ -61,13 +57,8 @@ bool Phase::Apply(CompilerContext *ctx, parser::Program *program) } #ifndef NDEBUG - ASTVerifier ast_before; - if (!ast_before.IsCorrectProgram(program)) { - // NOTE(tatiana): Add some error processing - } if (!Precondition(ctx, program)) { - ctx->Checker()->ThrowTypeError({"Precondition check failed for ", util::StringView {Name()}}, - lexer::SourcePosition {}); + ctx->Checker()->ThrowTypeError({"Precondition check failed for ", Name()}, lexer::SourcePosition {}); } #endif @@ -81,13 +72,8 @@ bool Phase::Apply(CompilerContext *ctx, parser::Program *program) } #ifndef NDEBUG - ASTVerifier ast_after; - if (!ast_after.IsCorrectProgram(program)) { - // NOTE(tatiana): Add some error processing - } if (!Postcondition(ctx, program)) { - ctx->Checker()->ThrowTypeError({"Postcondition check failed for ", util::StringView {Name()}}, - lexer::SourcePosition {}); + ctx->Checker()->ThrowTypeError({"Postcondition check failed for ", Name()}, lexer::SourcePosition {}); } #endif diff --git a/ets2panda/compiler/lowering/phase.h b/ets2panda/compiler/lowering/phase.h index c1b59ed0982231093880265e43d1947b311e370b..07a304620e38b37dfc8f5dea29289bde36d0b8ba 100644 --- a/ets2panda/compiler/lowering/phase.h +++ b/ets2panda/compiler/lowering/phase.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -25,7 +25,7 @@ public: /* If Apply returns false, processing is stopped. */ bool Apply(CompilerContext *ctx, parser::Program *program); - virtual std::string const &Name() = 0; + virtual util::StringView Name() = 0; virtual bool Precondition([[maybe_unused]] CompilerContext *ctx, [[maybe_unused]] const parser::Program *program) { diff --git a/ets2panda/compiler/lowering/util.cpp b/ets2panda/compiler/lowering/util.cpp index 247f182093c3aadccab01eb842fd1e022f4e33b9..38bcd67f3d888ba42b30525914e7858f36fd7e47 100644 --- a/ets2panda/compiler/lowering/util.cpp +++ b/ets2panda/compiler/lowering/util.cpp @@ -13,15 +13,13 @@ * limitations under the License. */ -#include - #include "util.h" #include "ir/expressions/identifier.h" namespace panda::es2panda::compiler { -varbinder::Scope *NearestScope(const ir::AstNode *ast) +binder::Scope *NearestScope(const ir::AstNode *ast) { while (!ast->IsScopeBearer()) { ast = ast->Parent(); @@ -40,7 +38,7 @@ ir::Identifier *Gensym(ArenaAllocator *allocator) 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); + memmove(arena_pointer, reinterpret_cast(str.c_str()), str.size() + 1); return allocator->New(util::StringView(reinterpret_cast(arena_pointer)), allocator); } diff --git a/ets2panda/compiler/lowering/util.h b/ets2panda/compiler/lowering/util.h index ba3d290a136019a4dff8fdbb411b61a20e9401e4..8c83e7b47059bd8e22e7fc0f5f820ea1ec43dfe4 100644 --- a/ets2panda/compiler/lowering/util.h +++ b/ets2panda/compiler/lowering/util.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -16,13 +16,13 @@ #ifndef ES2PANDA_COMPILER_LOWERING_UTIL_H #define ES2PANDA_COMPILER_LOWERING_UTIL_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" namespace panda::es2panda::compiler { -varbinder::Scope *NearestScope(const ir::AstNode *ast); +binder::Scope *NearestScope(const ir::AstNode *ast); ir::Identifier *Gensym(ArenaAllocator *allocator); } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 0f2a2e8dc1a580211a2867ac346d91bd59545991..35f30fef05a85fdd091786419c521dc594dc8bde 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -451,18 +451,6 @@ signatures: return_type: BUILTIN_DOUBLE ref: BUILTIN_DOUBLE_VALUE_OF - - callee: BUILTIN_FLOAT - method_name: isNaN - params: [PRIMITIVE_FLOAT] - return_type: PRIMITIVE_BOOLEAN - ref: BUILTIN_FLOAT_IS_NAN - - - callee: BUILTIN_DOUBLE - method_name: isNaN - params: [PRIMITIVE_DOUBLE] - return_type: PRIMITIVE_BOOLEAN - ref: BUILTIN_DOUBLE_IS_NAN - - callee: BUILTIN_BOOLEAN method_name: unboxed params: [] diff --git a/ets2panda/es2panda.h b/ets2panda/es2panda.h index 40774251e567cf0ba3ed97295b1960267869cddd..e0bfd92142537c09b70e3357831e2dd3d15d7260 100644 --- a/ets2panda/es2panda.h +++ b/ets2panda/es2panda.h @@ -39,9 +39,9 @@ class CompilerImpl; class CompilerContext; } // namespace compiler -namespace varbinder { -class VarBinder; -} // namespace varbinder +namespace binder { +class Binder; +} // namespace binder enum class ScriptExtension { JS, @@ -99,9 +99,9 @@ struct CompilerOptions { bool parse_only {}; std::string std_lib {}; std::string ts_decl_out {}; - std::unordered_set skip_phases {}; - std::unordered_set dump_before_phases {}; - std::unordered_set dump_after_phases {}; + std::unordered_set skip_phases {}; + std::unordered_set dump_before_phases {}; + std::unordered_set dump_after_phases {}; std::shared_ptr arkts_config {}; CompilationMode compilation_mode {}; // NOLINTEND(misc-non-private-member-variables-in-classes) diff --git a/ets2panda/ir/as/namedType.cpp b/ets2panda/ir/as/namedType.cpp index 8cd429a9bf3dffb425b8075aa0ce07c52fabf5d0..a2cac21c4e1290cba2bca1bbcad606199c8f235a 100644 --- a/ets2panda/ir/as/namedType.cpp +++ b/ets2panda/ir/as/namedType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/as/namedType.h b/ets2panda/ir/as/namedType.h index 595aa39c01108f025410425f7b6f340996ca277f..e0e839f306b8a5d6ad3265efd231446e139f15d1 100644 --- a/ets2panda/ir/as/namedType.h +++ b/ets2panda/ir/as/namedType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/as/prefixAssertionExpression.cpp b/ets2panda/ir/as/prefixAssertionExpression.cpp index 27d697f40809414e3b820c9f947529e2f1466552..61d4f4c18414c73a6b04ae8977e57fa45534ec9a 100644 --- a/ets2panda/ir/as/prefixAssertionExpression.cpp +++ b/ets2panda/ir/as/prefixAssertionExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/as/prefixAssertionExpression.h b/ets2panda/ir/as/prefixAssertionExpression.h index 60377a5179529688a3e21ea6f5d4aa71cb414eac..d848ab978327dd1f529bf9e87236bf52c70a1e14 100644 --- a/ets2panda/ir/as/prefixAssertionExpression.h +++ b/ets2panda/ir/as/prefixAssertionExpression.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index bceb87943b488f79aa83938d004a22ee54d1d161..3128b13b595a0db6b21fa81a6264617c3f82b0bb 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 1a5e3be8f7bf7693f9d643139e027ba915dd81b8..b9558663a3a25fd3e987cc93a64866b1fa0e4b12 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -16,7 +16,6 @@ #ifndef ES2PANDA_IR_AST_NODE_H #define ES2PANDA_IR_AST_NODE_H -#include "ir/astNodeFlags.h" #include "ir/astNodeMapping.h" #include "lexer/token/sourceLocation.h" #include "util/enumbitops.h" @@ -35,10 +34,10 @@ class ETSChecker; class Type; } // namespace panda::es2panda::checker -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; class Scope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { // NOLINTBEGIN(modernize-avoid-c-arrays) @@ -63,12 +62,106 @@ enum class AstNodeType { #undef DECLARE_NODE_TYPES }; +enum class AstNodeFlags { + NO_OPTS = 0, + STRICT = (1U << 0U), + PARAMETER = (1U << 1U), +}; + DEFINE_BITOPS(AstNodeFlags) +enum class ModifierFlags : uint32_t { + NONE = 0U, + STATIC = 1U << 0U, + ASYNC = 1U << 1U, + PUBLIC = 1U << 2U, + PROTECTED = 1U << 3U, + PRIVATE = 1U << 4U, + DECLARE = 1U << 5U, + READONLY = 1U << 6U, + OPTIONAL = 1U << 7U, + DEFINITE = 1U << 8U, + ABSTRACT = 1U << 9U, + CONST = 1U << 10U, + FINAL = 1U << 11U, + NATIVE = 1U << 12U, + OVERRIDE = 1U << 13U, + CONSTRUCTOR = 1U << 14U, + SYNCHRONIZED = 1U << 15U, + FUNCTIONAL = 1U << 16U, + IN = 1U << 17U, + OUT = 1U << 18U, + INTERNAL = 1U << 19U, + NULLABLE = 1U << 20U, + EXPORT = 1U << 21U, + SETTER = 1U << 22U, + DEFAULT_EXPORT = 1U << 23U, + ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, + ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, + ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, + INTERNAL_PROTECTED = INTERNAL | PROTECTED, + ACCESSOR_MODIFIERS = ABSTRACT | FINAL | OVERRIDE +}; + DEFINE_BITOPS(ModifierFlags) +enum class PrivateFieldKind { FIELD, METHOD, GET, SET, STATIC_FIELD, STATIC_METHOD, STATIC_GET, STATIC_SET }; + +enum class ScriptFunctionFlags : uint32_t { + NONE = 0U, + GENERATOR = 1U << 0U, + ASYNC = 1U << 1U, + ARROW = 1U << 2U, + EXPRESSION = 1U << 3U, + OVERLOAD = 1U << 4U, + CONSTRUCTOR = 1U << 5U, + METHOD = 1U << 6U, + STATIC_BLOCK = 1U << 7U, + HIDDEN = 1U << 8U, + IMPLICIT_SUPER_CALL_NEEDED = 1U << 9U, + ENUM = 1U << 10U, + EXTERNAL = 1U << 11U, + PROXY = 1U << 12U, + THROWS = 1U << 13U, + RETHROWS = 1U << 14U, + GETTER = 1U << 15U, + SETTER = 1U << 16U, + DEFAULT_PARAM_PROXY = 1U << 17U, + ENTRY_POINT = 1U << 18U, + INSTANCE_EXTENSION_METHOD = 1U << 19U, + HAS_RETURN = 1U << 20U +}; + DEFINE_BITOPS(ScriptFunctionFlags) +enum class TSOperatorType { READONLY, KEYOF, UNIQUE }; +enum class MappedOption { NO_OPTS, PLUS, MINUS }; + +enum class BoxingUnboxingFlags : uint32_t { + NONE = 0U, + BOX_TO_BOOLEAN = 1U << 0U, + BOX_TO_BYTE = 1U << 1U, + BOX_TO_SHORT = 1U << 2U, + BOX_TO_CHAR = 1U << 3U, + BOX_TO_INT = 1U << 4U, + BOX_TO_LONG = 1U << 5U, + BOX_TO_FLOAT = 1U << 6U, + BOX_TO_DOUBLE = 1U << 7U, + UNBOX_TO_BOOLEAN = 1U << 8U, + UNBOX_TO_BYTE = 1U << 9U, + UNBOX_TO_SHORT = 1U << 10U, + UNBOX_TO_CHAR = 1U << 11U, + UNBOX_TO_INT = 1U << 12U, + UNBOX_TO_LONG = 1U << 13U, + UNBOX_TO_FLOAT = 1U << 14U, + UNBOX_TO_DOUBLE = 1U << 15U, + BOXING_FLAG = BOX_TO_BOOLEAN | BOX_TO_BYTE | BOX_TO_SHORT | BOX_TO_CHAR | BOX_TO_INT | BOX_TO_LONG | BOX_TO_FLOAT | + BOX_TO_DOUBLE, + UNBOXING_FLAG = UNBOX_TO_BOOLEAN | UNBOX_TO_BYTE | UNBOX_TO_SHORT | UNBOX_TO_CHAR | UNBOX_TO_INT | UNBOX_TO_LONG | + UNBOX_TO_FLOAT | UNBOX_TO_DOUBLE, + +}; + DEFINE_BITOPS(BoxingUnboxingFlags) // Forward declarations @@ -134,11 +227,6 @@ public: return false; } - virtual bool IsTyped() const - { - return false; - } - // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECLARE_AS_CASTS(nodeType, className) \ className *As##className() \ @@ -253,12 +341,12 @@ public: parent_ = parent; } - [[nodiscard]] varbinder::Variable *Variable() const noexcept + [[nodiscard]] binder::Variable *Variable() const noexcept { return variable_; } - void SetVariable(varbinder::Variable *const variable) noexcept + void SetVariable(binder::Variable *const variable) noexcept { variable_ = variable; } @@ -435,7 +523,7 @@ public: return false; } - virtual varbinder::Scope *Scope() const + virtual binder::Scope *Scope() const { UNREACHABLE(); } @@ -469,7 +557,7 @@ protected: AstNode *parent_ {}; lexer::SourceRange range_ {}; AstNodeType type_; - varbinder::Variable *variable_ {}; + binder::Variable *variable_ {}; ModifierFlags flags_ {}; mutable BoxingUnboxingFlags boxing_unboxing_flags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) @@ -499,11 +587,6 @@ public: ts_type_ = ts_type; } - bool IsTyped() const override - { - return true; - } - protected: explicit Typed(AstNodeType const type) : T(type) {} explicit Typed(AstNodeType const type, ModifierFlags const flags) : T(type, flags) {} diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h deleted file mode 100644 index d8e7329a0a6e9884bbed8e24cd0114e0c9e25f14..0000000000000000000000000000000000000000 --- a/ets2panda/ir/astNodeFlags.h +++ /dev/null @@ -1,116 +0,0 @@ -/** - * 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. - */ - -#ifndef ES2PANDA_IR_AST_NODE_FLAGS_H -#define ES2PANDA_IR_AST_NODE_FLAGS_H - -#include - -namespace panda::es2panda::ir { -enum class AstNodeFlags { - NO_OPTS = 0, - STRICT = (1U << 0U), - PARAMETER = (1U << 1U), -}; - -enum class ModifierFlags : uint32_t { - NONE = 0U, - STATIC = 1U << 0U, - ASYNC = 1U << 1U, - PUBLIC = 1U << 2U, - PROTECTED = 1U << 3U, - PRIVATE = 1U << 4U, - DECLARE = 1U << 5U, - READONLY = 1U << 6U, - OPTIONAL = 1U << 7U, - DEFINITE = 1U << 8U, - ABSTRACT = 1U << 9U, - CONST = 1U << 10U, - FINAL = 1U << 11U, - NATIVE = 1U << 12U, - OVERRIDE = 1U << 13U, - CONSTRUCTOR = 1U << 14U, - SYNCHRONIZED = 1U << 15U, - FUNCTIONAL = 1U << 16U, - IN = 1U << 17U, - OUT = 1U << 18U, - INTERNAL = 1U << 19U, - NULLABLE = 1U << 20U, - EXPORT = 1U << 21U, - SETTER = 1U << 22U, - DEFAULT_EXPORT = 1U << 23U, - ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, - ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, - ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, - INTERNAL_PROTECTED = INTERNAL | PROTECTED, - ACCESSOR_MODIFIERS = ABSTRACT | FINAL | OVERRIDE -}; - -enum class PrivateFieldKind { FIELD, METHOD, GET, SET, STATIC_FIELD, STATIC_METHOD, STATIC_GET, STATIC_SET }; - -enum class ScriptFunctionFlags : uint32_t { - NONE = 0U, - GENERATOR = 1U << 0U, - ASYNC = 1U << 1U, - ARROW = 1U << 2U, - EXPRESSION = 1U << 3U, - OVERLOAD = 1U << 4U, - CONSTRUCTOR = 1U << 5U, - METHOD = 1U << 6U, - STATIC_BLOCK = 1U << 7U, - HIDDEN = 1U << 8U, - IMPLICIT_SUPER_CALL_NEEDED = 1U << 9U, - ENUM = 1U << 10U, - EXTERNAL = 1U << 11U, - PROXY = 1U << 12U, - THROWS = 1U << 13U, - RETHROWS = 1U << 14U, - GETTER = 1U << 15U, - SETTER = 1U << 16U, - DEFAULT_PARAM_PROXY = 1U << 17U, - ENTRY_POINT = 1U << 18U, - INSTANCE_EXTENSION_METHOD = 1U << 19U, - HAS_RETURN = 1U << 20U -}; - -enum class TSOperatorType { READONLY, KEYOF, UNIQUE }; -enum class MappedOption { NO_OPTS, PLUS, MINUS }; - -enum class BoxingUnboxingFlags : uint32_t { - NONE = 0U, - BOX_TO_BOOLEAN = 1U << 0U, - BOX_TO_BYTE = 1U << 1U, - BOX_TO_SHORT = 1U << 2U, - BOX_TO_CHAR = 1U << 3U, - BOX_TO_INT = 1U << 4U, - BOX_TO_LONG = 1U << 5U, - BOX_TO_FLOAT = 1U << 6U, - BOX_TO_DOUBLE = 1U << 7U, - UNBOX_TO_BOOLEAN = 1U << 8U, - UNBOX_TO_BYTE = 1U << 9U, - UNBOX_TO_SHORT = 1U << 10U, - UNBOX_TO_CHAR = 1U << 11U, - UNBOX_TO_INT = 1U << 12U, - UNBOX_TO_LONG = 1U << 13U, - UNBOX_TO_FLOAT = 1U << 14U, - UNBOX_TO_DOUBLE = 1U << 15U, - BOXING_FLAG = BOX_TO_BOOLEAN | BOX_TO_BYTE | BOX_TO_SHORT | BOX_TO_CHAR | BOX_TO_INT | BOX_TO_LONG | BOX_TO_FLOAT | - BOX_TO_DOUBLE, - UNBOXING_FLAG = UNBOX_TO_BOOLEAN | UNBOX_TO_BYTE | UNBOX_TO_SHORT | UNBOX_TO_CHAR | UNBOX_TO_INT | UNBOX_TO_LONG | - UNBOX_TO_FLOAT | UNBOX_TO_DOUBLE, -}; -} // namespace panda::es2panda::ir - -#endif \ No newline at end of file diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 55cddab5a51684b51edbf436334db68014c77ac2..245b7b86369526bbe12cb3b35558e5ef4b6e99de 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -82,7 +82,6 @@ _(ETS_CLASS_LITERAL, ETSClassLiteral) \ _(ETS_TYPE_REFERENCE, ETSTypeReference) \ _(ETS_TYPE_REFERENCE_PART, ETSTypeReferencePart) \ - _(ETS_UNION_TYPE, ETSUnionType) \ _(ETS_LAUNCH_EXPRESSION, ETSLaunchExpression) \ _(ETS_NEW_ARRAY_INSTANCE_EXPRESSION, ETSNewArrayInstanceExpression) \ _(ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION, ETSNewMultiDimArrayInstanceExpression) \ diff --git a/ets2panda/ir/base/catchClause.h b/ets2panda/ir/base/catchClause.h index d7ddd066c24266567bf005bc975505b98cd699da..12540aad948a9271a328d3f02720a7065254f804 100644 --- a/ets2panda/ir/base/catchClause.h +++ b/ets2panda/ir/base/catchClause.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_BASE_CATCH_CLAUSE_H #define ES2PANDA_IR_BASE_CATCH_CLAUSE_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" namespace panda::es2panda::ir { @@ -25,7 +25,7 @@ class Expression; class CatchClause : public TypedStatement { public: - explicit CatchClause(varbinder::CatchScope *scope, Expression *param, BlockStatement *body) + explicit CatchClause(binder::CatchScope *scope, Expression *param, BlockStatement *body) : TypedStatement(AstNodeType::CATCH_CLAUSE), scope_(scope), param_(param), body_(body) { } @@ -55,7 +55,7 @@ public: return true; } - varbinder::CatchScope *Scope() const override + binder::CatchScope *Scope() const override { return scope_; } @@ -70,7 +70,7 @@ public: checker::Type *Check(checker::ETSChecker *checker) override; private: - varbinder::CatchScope *scope_; + binder::CatchScope *scope_; Expression *param_; BlockStatement *body_; }; diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 7341aab83e5a2787b52579e2eb10a6256299f4bf..c90fee1e2d578b2a8f12bfe15e374458a4ef51ba 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -16,8 +16,8 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_CLASS_DEFINITION_H #define ES2PANDA_PARSER_INCLUDE_AST_CLASS_DEFINITION_H -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "ir/astNode.h" #include "util/bitset.h" #include "util/language.h" @@ -50,7 +50,7 @@ DEFINE_BITOPS(ClassDefinitionModifiers) class ClassDefinition : public TypedAstNode { public: - explicit ClassDefinition(varbinder::LocalScope *scope, const util::StringView &private_id, Identifier *ident, + explicit ClassDefinition(binder::LocalScope *scope, const util::StringView &private_id, Identifier *ident, TSTypeParameterDeclaration *type_params, TSTypeParameterInstantiation *super_type_params, ArenaVector &&implements, MethodDefinition *ctor, Expression *super_class, ArenaVector &&body, ClassDefinitionModifiers modifiers, @@ -70,7 +70,7 @@ public: { } - explicit ClassDefinition(ArenaAllocator *allocator, varbinder::LocalScope *scope, Identifier *ident, + explicit ClassDefinition(ArenaAllocator *allocator, binder::LocalScope *scope, Identifier *ident, ArenaVector &&body, ClassDefinitionModifiers modifiers, Language lang) : TypedAstNode(AstNodeType::CLASS_DEFINITION), scope_(scope), @@ -82,7 +82,7 @@ public: { } - explicit ClassDefinition(ArenaAllocator *allocator, varbinder::LocalScope *scope, Identifier *ident, + explicit ClassDefinition(ArenaAllocator *allocator, binder::LocalScope *scope, Identifier *ident, ClassDefinitionModifiers modifiers, ModifierFlags flags, Language lang) : TypedAstNode(AstNodeType::CLASS_DEFINITION, flags), scope_(scope), @@ -99,7 +99,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -245,7 +245,7 @@ private: void CompileStaticFieldInitializers(compiler::PandaGen *pg, compiler::VReg class_reg, const std::vector &static_computed_field_keys) const; - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; util::StringView private_id_ {}; Identifier *ident_ {}; TSTypeParameterDeclaration *type_params_ {}; diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index fd04aed68cd7004a6f0caacb642f10c15761cd4a..42e336acf5a55de4b04b2a69bb1cc8445425d3dd 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index 796fde132fa4f1e30e0386916bffbcf60c270146..836083e64fdf75040df2273a2d4a99ae15f9d2a0 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 82738acdab8b41e04f7d507aeed1a87b0bf62344..2a8f7a2df474ca604abb6a74bfc7b25bed0748fc 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -34,7 +34,7 @@ public: type_annotation_(type_annotation) { } - // NOTE: csabahurton. friend relationship can be removed once there are getters for private fields + // TODO (csabahurton): friend relationship can be removed once there are getters for private fields friend class checker::ETSAnalyzer; TypeNode *TypeAnnotation() const diff --git a/ets2panda/ir/base/classStaticBlock.cpp b/ets2panda/ir/base/classStaticBlock.cpp index 012595ebe4441171fff0650b0cd84525f864ccf4..250250abc54eead4b382da34dfe3c90e942517de 100644 --- a/ets2panda/ir/base/classStaticBlock.cpp +++ b/ets2panda/ir/base/classStaticBlock.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,7 +15,7 @@ #include "classStaticBlock.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/ETSchecker.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" diff --git a/ets2panda/ir/base/classStaticBlock.h b/ets2panda/ir/base/classStaticBlock.h index 08d9a97a2b15722f816a1d98ce6d183dad6a6ac0..5a9e8ea797fbf57d731de1e7537e8ea2e9f3fe69 100644 --- a/ets2panda/ir/base/classStaticBlock.h +++ b/ets2panda/ir/base/classStaticBlock.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index f88b13cc03b88649618baabbb677af035f4dce63..f6d349353b00665184637ce7ce95612d3e221afe 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -53,14 +53,14 @@ void MetaProperty::Compile([[maybe_unused]] compiler::PandaGen *pg) const } if (kind_ == ir::MetaProperty::MetaPropertyKind::IMPORT_META) { - // NOTE + // TODO() pg->Unimplemented(); } } checker::Type *MetaProperty::Check([[maybe_unused]] checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index cff3cf3c6bd661e08997ecfc465c3c3b6208bd3c..92022432c12257ee9a9b0c28d5ee0620f80499c9 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -15,7 +15,7 @@ #include "methodDefinition.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/astDump.h" #include "ir/base/decorator.h" #include "ir/base/classDefinition.h" @@ -148,7 +148,7 @@ checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) return nullptr; } - // NOTE: aszilagyi. make it correctly check for open function not have body + // TODO(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()); diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index 567762c7e5e3eb5280a65ae41e572680d52618a4..fed743ed14e72122056d1633b4ac1874341f9257 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -15,7 +15,7 @@ #include "scriptFunction.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/core/ETSGen.h" #include "ir/astDump.h" #include "ir/expression.h" diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 93e134422716eda3f0635a8ab6982427df2d6bea..71e63af94e24b522a526f145111a64bc2e12e674 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -17,7 +17,7 @@ #define ES2PANDA_PARSER_INCLUDE_AST_SCRIPT_FUNCTION_H #include "ir/astNode.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "util/enumbitops.h" #include "util/language.h" @@ -31,7 +31,7 @@ class TypeNode; class ScriptFunction : public AstNode { public: - explicit ScriptFunction(varbinder::FunctionScope *scope, ArenaVector &¶ms, + explicit ScriptFunction(binder::FunctionScope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, AstNode *body, TypeNode *return_type_annotation, ir::ScriptFunctionFlags func_flags, bool declare, Language lang) : AstNode(AstNodeType::SCRIPT_FUNCTION), @@ -46,7 +46,7 @@ public: { } - explicit ScriptFunction(varbinder::FunctionScope *scope, ArenaVector &¶ms, + explicit ScriptFunction(binder::FunctionScope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, AstNode *body, TypeNode *return_type_annotation, ir::ScriptFunctionFlags func_flags, ir::ModifierFlags flags, bool declare, Language lang) : AstNode(AstNodeType::SCRIPT_FUNCTION, flags), @@ -272,7 +272,7 @@ public: return true; } - varbinder::FunctionScope *Scope() const override + binder::FunctionScope *Scope() const override { return scope_; } @@ -292,7 +292,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::FunctionScope *scope_; + binder::FunctionScope *scope_; Identifier *id_ {}; ArenaVector params_; TSTypeParameterDeclaration *type_params_; diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index e5650900a5fd7be6f05c580a286b9e970bd77b31..7eac2ea11a4f0d0931c66bf7c42c7fa52e3c1d6e 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -20,6 +20,8 @@ #include "ir/astDump.h" #include "util/ustring.h" +//#include + namespace panda::es2panda::ir { void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} void TemplateElement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} @@ -28,7 +30,7 @@ void TemplateElement::Dump(ir::AstDumper *dumper) const { dumper->Add({ {"type", "TemplateElement"}, - {"value", {{"raw", /* raw_ */ ""}, {"cooked", /* cooked_ */ ""}}}, + {"value", {{"raw", "" /* raw_ */}, {"cooked", "" /* cooked_ */}}}, }); } diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index c6f203b24b91e353de82a43c3fc37a2cd96349f9..217c726b788167c2cfb87a25b5b36abaceb3b758 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -15,7 +15,7 @@ #include "tsMethodSignature.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/astDump.h" #include "ir/typeNode.h" #include "ir/ts/tsTypeParameter.h" diff --git a/ets2panda/ir/base/tsMethodSignature.h b/ets2panda/ir/base/tsMethodSignature.h index ffa4dca38709fca21aa9ff37fc4382ca0e2e69cd..573cb672a910a84fabdb23ec347298abb8a10754 100644 --- a/ets2panda/ir/base/tsMethodSignature.h +++ b/ets2panda/ir/base/tsMethodSignature.h @@ -23,7 +23,7 @@ class TSTypeParameterDeclaration; class TSMethodSignature : public AstNode { public: - explicit TSMethodSignature(varbinder::Scope *scope, Expression *key, TSTypeParameterDeclaration *type_params, + explicit TSMethodSignature(binder::Scope *scope, Expression *key, TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, TypeNode *return_type_annotation, bool computed, bool optional) : AstNode(AstNodeType::TS_METHOD_SIGNATURE), @@ -42,7 +42,7 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } @@ -90,7 +90,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; Expression *key_; TSTypeParameterDeclaration *type_params_; ArenaVector params_; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index 734c4613f9cdd7b80be713cadb2c229dd837689d..e121ff54f3f7dd46d4c6af1ec1a524223ccc068e 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -15,7 +15,7 @@ #include "tsSignatureDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/typeNode.h" #include "ir/astDump.h" #include "ir/ts/tsTypeParameter.h" diff --git a/ets2panda/ir/base/tsSignatureDeclaration.h b/ets2panda/ir/base/tsSignatureDeclaration.h index bd89af7fa3b833cc3542d3b60d05ae871697f8e6..a83caebc7735372d34101495cf0be3d29bbcd771 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.h +++ b/ets2panda/ir/base/tsSignatureDeclaration.h @@ -25,7 +25,7 @@ class TSSignatureDeclaration : public TypedAstNode { public: enum class TSSignatureDeclarationKind { CALL_SIGNATURE, CONSTRUCT_SIGNATURE }; - explicit TSSignatureDeclaration(varbinder::Scope *scope, TSSignatureDeclarationKind kind, + explicit TSSignatureDeclaration(binder::Scope *scope, TSSignatureDeclarationKind kind, TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, TypeNode *return_type_annotation) : TypedAstNode(AstNodeType::TS_SIGNATURE_DECLARATION), @@ -42,7 +42,7 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } @@ -75,7 +75,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; TSSignatureDeclarationKind kind_; TSTypeParameterDeclaration *type_params_; ArenaVector params_; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index 4b8673ebdb5f6b95ba3462129b3a263b8c346fb8..3a2abcd43a8b3b0e876b82545f5ec6305cc9429d 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -69,7 +69,7 @@ checker::Type *ETSClassLiteral::Check([[maybe_unused]] checker::ETSChecker *chec } ArenaVector type_arg_types(checker->Allocator()->Adapter()); - type_arg_types.push_back(expr_type); // NOTE: Box it if it's a primitive type + type_arg_types.push_back(expr_type); // TODO(user): Box it if it's a primitive type checker::InstantiationContext ctx(checker, checker->GlobalBuiltinTypeType(), type_arg_types, range_.start); SetTsType(ctx.Result()); diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index af4a875648c2c8fb4973badda066eafb2cbe0dcf..cc9d4f3651b55c2e01e65e30680a4b4d9cf2ab85 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index c4b962e10aab21c04c1455bd5678fca9b890f772..311491a2117c4116b08f3a87494820ca2b6abb3a 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,7 +15,7 @@ #include "etsFunctionType.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "checker/types/signature.h" @@ -112,7 +112,7 @@ checker::Type *ETSFunctionType::Check(checker::ETSChecker *checker) auto *param_ident = param->Ident(); ASSERT(param_ident->Variable()); - varbinder::Variable *param_var = param_ident->Variable(); + binder::Variable *param_var = param_ident->Variable(); ASSERT(param->TypeAnnotation()); param_var->SetTsType(checker->GetTypeFromTypeAnnotation(param->TypeAnnotation())); diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index ca4cfcf2c7d812e9903b43940a3ea3097ac195ba..b0b0e646f5a043b879d432d5013d86adcb0b2e2e 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -23,7 +23,7 @@ class TSTypeParameterDeclaration; class ETSFunctionType : public TypeNode { public: - explicit ETSFunctionType(varbinder::Scope *scope, ArenaVector &¶ms, + explicit ETSFunctionType(binder::Scope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, TypeNode *return_type, ir::ScriptFunctionFlags func_flags) : TypeNode(AstNodeType::ETS_FUNCTION_TYPE), @@ -40,7 +40,7 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } @@ -95,7 +95,7 @@ public: checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; ArenaVector params_; TSTypeParameterDeclaration *type_params_; TypeNode *return_type_; diff --git a/ets2panda/ir/ets/etsImportDeclaration.h b/ets2panda/ir/ets/etsImportDeclaration.h index 1a583ad4fb196eb9794d94124ea472bd2d172d65..9cd2390ce5c94c3dc8fd55d1ac7882911c400028 100644 --- a/ets2panda/ir/ets/etsImportDeclaration.h +++ b/ets2panda/ir/ets/etsImportDeclaration.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/ets/etsImportSource.cpp b/ets2panda/ir/ets/etsImportSource.cpp index a73b779c3e1f11d26b5fbbca698a47bcabb256b9..30c90ff13229cc49d87b627ae12ff16efeb5d847 100644 --- a/ets2panda/ir/ets/etsImportSource.cpp +++ b/ets2panda/ir/ets/etsImportSource.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index 44976cdb5f7f9f2e886c9adb79d73a677dadcab1..fbc3336dd6542cee9e8f678517edb8a84a11ce0c 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -55,6 +55,7 @@ void ETSLaunchExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const checker::Signature *signature = expr_->Signature(); bool is_static = signature->HasSignatureFlag(checker::SignatureFlags::STATIC); bool is_reference = signature->HasSignatureFlag(checker::SignatureFlags::TYPE); + if (!is_reference && expr_->Callee()->IsIdentifier()) { if (!is_static) { etsg->LoadThis(expr_); diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index db99d9e6a58b6fd1a65e0be5066bdb06cb764bed..9857e8517fd0eaa21182a32bde42c5cd3be3e589 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index e837295c0ed73ea150968c477efed4988285e9cc..9483123e2619215984c6f4cebd42a3056fdaf493 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index 68b5f7d13404ed44f4c0dcc971a667e42a1ae402..22a3f89ede5e176f5a3f23efc5062d73bbe4b76d 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 37f27e54b81ef434a97944674b158b7c2733eef0..60d66c48dbf9ad9dfbd90b17f508b2a475fa19ef 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -81,7 +81,7 @@ void ETSNewClassInstanceExpression::CreateDynamicObject(const ir::AstNode *node, } auto *var = name->AsIdentifier()->Variable(); - auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); + auto *data = etsg->Binder()->DynamicImportDataForVar(var); if (data != nullptr) { auto *import = data->import; auto *specifier = data->specifier; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index e35c911063dc6ed6b222e4d5b1af7c68924e6d86..739368683f27562d53318608f96a04063acdf292 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index d9b5d78eb103d17a88df5134a0fef6edec7c2f1a..d04ddd358e0c67ea12e15fc0614f1007c171bb22 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,7 +15,7 @@ #include "etsNewMultiDimArrayInstanceExpression.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "ir/astDump.h" #include "ir/typeNode.h" #include "compiler/core/ETSGen.h" diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index 9ed77697fb0f19292003f371ad47188617a6a59e..cda0cbfbfc31ace7e79f0e47000f08f7d12deeb2 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 6a843313d2cc24c8ec968f972fda81f811cb79bc..0a1b6a3eba28738cc44c174194252f9fd531f1c3 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index a4eab69aba039f4bca2edef92366ce5a697fbe05..c862ffe69700f0e0eb8df259431497a42cf888d3 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,11 +15,9 @@ #include "etsParameterExpression.h" +#include "compiler/core/pandagen.h" #include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/typeNode.h" #include "ir/expressions/identifier.h" @@ -75,7 +73,7 @@ Expression *ETSParameterExpression::Initializer() noexcept return initializer_; } -varbinder::Variable *ETSParameterExpression::Variable() const noexcept +binder::Variable *ETSParameterExpression::Variable() const noexcept { return ident_->Variable(); } @@ -90,7 +88,7 @@ TypeNode *ETSParameterExpression::TypeAnnotation() noexcept return !IsRestParameter() ? ident_->TypeAnnotation() : spread_->TypeAnnotation(); } -void ETSParameterExpression::SetVariable(varbinder::Variable *const variable) noexcept +void ETSParameterExpression::SetVariable(binder::Variable *const variable) noexcept { ident_->SetVariable(variable); } @@ -142,24 +140,43 @@ void ETSParameterExpression::Dump(ir::AstDumper *const dumper) const } } -void ETSParameterExpression::Compile(compiler::PandaGen *const pg) const +void ETSParameterExpression::Compile([[maybe_unused]] compiler::PandaGen *const pg) const { - pg->GetAstCompiler()->Compile(this); + UNREACHABLE(); } -void ETSParameterExpression::Compile(compiler::ETSGen *const etsg) const +void ETSParameterExpression::Compile([[maybe_unused]] compiler::ETSGen *const etsg) const { - etsg->GetAstCompiler()->Compile(this); + ident_->Identifier::Compile(etsg); } -checker::Type *ETSParameterExpression::Check(checker::TSChecker *const checker) +checker::Type *ETSParameterExpression::Check([[maybe_unused]] checker::TSChecker *const checker) { - return checker->GetAnalyzer()->Check(this); + UNREACHABLE(); } checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) { - return checker->GetAnalyzer()->Check(this); + if (TsType() == nullptr) { + checker::Type *param_type; + + if (ident_->TsType() != nullptr) { + param_type = ident_->TsType(); + } else { + param_type = !IsRestParameter() ? ident_->Check(checker) : spread_->Check(checker); + if (IsDefault()) { + [[maybe_unused]] auto *const init_type = initializer_->Check(checker); + // TODO(ttamas) : fix this aftet nullable fix + // const checker::AssignmentContext ctx(checker->Relation(), initializer_, init_type, name_type, + // initializer_->Start(), + // {"Initializers type is not assignable to the target type"}); + } + } + + SetTsType(param_type); + } + + return TsType(); } // NOLINTNEXTLINE(google-default-arguments) diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index e068b4e3b73e2bc3a29f8e033cea07664e4c6be6..d63a3dd887cd921d18cacf3f9e98f1a327a0fdb3 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -18,10 +18,6 @@ #include "ir/expression.h" -namespace panda::es2panda::checker { -class ETSAnalyzer; -} // namespace panda::es2panda::checker - namespace panda::es2panda::ir { class ETSParameterExpression final : public Expression { public: @@ -33,9 +29,6 @@ public: explicit ETSParameterExpression(AnnotatedExpression *ident_or_spread, Expression *initializer); - // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - [[nodiscard]] const Identifier *Ident() const noexcept; [[nodiscard]] Identifier *Ident() noexcept; @@ -48,8 +41,8 @@ public: void SetLexerSaved(util::StringView s) noexcept; [[nodiscard]] util::StringView LexerSaved() const noexcept; - [[nodiscard]] varbinder::Variable *Variable() const noexcept; - void SetVariable(varbinder::Variable *variable) noexcept; + [[nodiscard]] binder::Variable *Variable() const noexcept; + void SetVariable(binder::Variable *variable) noexcept; [[nodiscard]] TypeNode const *TypeAnnotation() const noexcept; [[nodiscard]] TypeNode *TypeAnnotation() noexcept; diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index c2934842b573cbd07ecae71a03b386e5b5096b9b..820b6fb5448dc8d09b2a45b200d35fd229f549cb 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,11 +15,10 @@ #include "etsPrimitiveType.h" +#include "ir/astDump.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ETSPrimitiveType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -30,19 +29,16 @@ void ETSPrimitiveType::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ETSPrimitiveType"}}); } -void ETSPrimitiveType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} +void ETSPrimitiveType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ETSPrimitiveType::Compile(compiler::ETSGen *etsg) const +void ETSPrimitiveType::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + UNREACHABLE(); } -checker::Type *ETSPrimitiveType::Check(checker::TSChecker *checker) +checker::Type *ETSPrimitiveType::Check([[maybe_unused]] checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -50,9 +46,9 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::TSChecker *ch return checker->GlobalAnyType(); } -checker::Type *ETSPrimitiveType::Check(checker::ETSChecker *checker) +checker::Type *ETSPrimitiveType::Check([[maybe_unused]] checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *checker) diff --git a/ets2panda/ir/ets/etsPrimitiveType.h b/ets2panda/ir/ets/etsPrimitiveType.h index 94df4d0eb7a0cce242401fc80356fed055a6ff39..c8ae085f4585c41133ece704a672f1730826cc76 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.h +++ b/ets2panda/ir/ets/etsPrimitiveType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -33,11 +33,11 @@ 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; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check(checker::ETSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: diff --git a/ets2panda/ir/ets/etsScript.cpp b/ets2panda/ir/ets/etsScript.cpp index 27972213820c8b625758f805160433ecab1b070e..5f80525b9c014d020044ab4410c3fe4588f3263b 100644 --- a/ets2panda/ir/ets/etsScript.cpp +++ b/ets2panda/ir/ets/etsScript.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/ets/etsScript.h b/ets2panda/ir/ets/etsScript.h index 6ab6a2346552af32f965c22bbbe117c02b68f5d9..2f0f35a9b1e9aa1756783b2753c50704138fbc99 100644 --- a/ets2panda/ir/ets/etsScript.h +++ b/ets2panda/ir/ets/etsScript.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -26,7 +26,7 @@ namespace panda::es2panda::ir { class ETSScript : public BlockStatement { public: - explicit ETSScript(ArenaAllocator *allocator, varbinder::Scope *scope, ArenaVector &&statement_list, + explicit ETSScript(ArenaAllocator *allocator, binder::Scope *scope, ArenaVector &&statement_list, parser::Program *program) : BlockStatement(allocator, scope, std::move(statement_list)), program_(program) { diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 0f62efc3caabbccafde4b829b6f214dbf9cb2b68..62f8b74cdf5b9d4c5b577779dc33efa932f0d523 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -15,7 +15,6 @@ #include "etsStructDeclaration.h" -#include "checker/TSchecker.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" @@ -49,23 +48,24 @@ void ETSStructDeclaration::Dump(ir::AstDumper *dumper) const {{"type", "ETSStructDeclaration"}, {"definition", def_}, {"decorators", AstDumper::Optional(decorators_)}}); } -void ETSStructDeclaration::Compile(compiler::PandaGen *pg) const +void ETSStructDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const { - pg->GetAstCompiler()->Compile(this); + UNREACHABLE(); } -void ETSStructDeclaration::Compile(compiler::ETSGen *etsg) const +void ETSStructDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + UNREACHABLE(); } -checker::Type *ETSStructDeclaration::Check(checker::TSChecker *checker) +checker::Type *ETSStructDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + def_->Check(checker); + return nullptr; } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index 9dc920dc91e5732e79d368d2ae6102371f1553ab..7a52e9b804388b7722ac9993ddced626184610ec 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -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(compiler::PandaGen *pg) const override; - void Compile(compiler::ETSGen *etsg) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check(checker::ETSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: ClassDefinition *def_; diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index 274f7584a719664e03c13c8566f4f10a21ce2701..849f5234630df198d5d699fb7da1081ed8f802a4 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,13 +15,11 @@ #include "etsTypeReference.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/ts/tsQualifiedName.h" #include "ir/ets/etsTypeReferencePart.h" +#include "checker/ETSchecker.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void ETSTypeReference::TransformChildren(const NodeTransformer &cb) @@ -62,23 +60,20 @@ void ETSTypeReference::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ETSTypeReference"}, {"part", part_}}); } -void ETSTypeReference::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSTypeReference::Compile(compiler::ETSGen *etsg) const +void ETSTypeReference::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void ETSTypeReference::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + part_->Compile(etsg); } -checker::Type *ETSTypeReference::Check(checker::TSChecker *checker) +checker::Type *ETSTypeReference::Check([[maybe_unused]] checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSTypeReference::Check(checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return GetType(checker); } checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) diff --git a/ets2panda/ir/ets/etsTypeReference.h b/ets2panda/ir/ets/etsTypeReference.h index adadc8fd96d79c3b587967dc29961b5a3ae9e64c..17b8ef6ce1c30595a325a66579d06005fa28314c 100644 --- a/ets2panda/ir/ets/etsTypeReference.h +++ b/ets2panda/ir/ets/etsTypeReference.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -41,10 +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(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; + 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::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 2bdb6d282c38c0244f4a3f20f5537efff25ee1d1..4d86e09056694abe5f068f41ab938457160d3c9e 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,12 +15,13 @@ #include "etsTypeReferencePart.h" +#include "ir/astDump.h" +#include "ir/expressions/identifier.h" +#include "ir/ts/tsTypeParameterInstantiation.h" +#include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" -#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ETSTypeReferencePart::TransformChildren(const NodeTransformer &cb) @@ -57,23 +58,20 @@ void ETSTypeReferencePart::Dump(ir::AstDumper *dumper) const {"previous", AstDumper::Optional(prev_)}}); } -void ETSTypeReferencePart::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSTypeReferencePart::Compile(compiler::ETSGen *etsg) const +void ETSTypeReferencePart::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void ETSTypeReferencePart::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + name_->Compile(etsg); } -checker::Type *ETSTypeReferencePart::Check(checker::TSChecker *checker) +checker::Type *ETSTypeReferencePart::Check([[maybe_unused]] checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSTypeReferencePart::Check(checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return GetType(checker); } checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index 25b9611bbae5e5b5094e75f0a58b420d31920e3b..f8d82bcf2934f5df7b119ff7dd3952b6b5eca2a2 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -58,10 +58,10 @@ 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; - checker::Type *Check(checker::ETSChecker *checker) 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::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp deleted file mode 100644 index e811f5a37d816364392c73030c8f1174b4ce992e..0000000000000000000000000000000000000000 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2021-2022 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 "etsUnionType.h" - -#include "checker/ETSchecker.h" -#include "ir/astDump.h" - -namespace panda::es2panda::ir { -void ETSUnionType::TransformChildren(const NodeTransformer &cb) -{ - for (auto *&it : types_) { - it = static_cast(cb(it)); - } -} - -void ETSUnionType::Iterate(const NodeTraverser &cb) const -{ - for (auto *it : types_) { - cb(it); - } -} - -void ETSUnionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSUnionType"}, {"types", types_}}); -} - -void ETSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *ETSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::Type *ETSUnionType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - for (auto *it : types_) { - it->Check(checker); - } - - return GetType(checker); -} - -checker::Type *ETSUnionType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - ArenaVector types(checker->Allocator()->Adapter()); - - for (auto *it : types_) { - types.push_back(it->GetType(checker)); - } - - SetTsType(checker->CreateETSUnionType(std::move(types))); - return TsType(); -} -} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsUnionType.h b/ets2panda/ir/ets/etsUnionType.h deleted file mode 100644 index c7f146794c0071eedc11af9c0cbd2535ee17229a..0000000000000000000000000000000000000000 --- a/ets2panda/ir/ets/etsUnionType.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2021 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_ETS_UNION_TYPE_H -#define ES2PANDA_IR_ETS_UNION_TYPE_H - -#include "ir/typeNode.h" - -namespace panda::es2panda::ir { -class ETSUnionType : public TypeNode { -public: - explicit ETSUnionType(ArenaVector &&types) - : TypeNode(AstNodeType::ETS_UNION_TYPE), types_(std::move(types)) - { - } - - const ArenaVector &Types() const - { - return types_; - } - - 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; - checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; - -private: - ArenaVector types_; -}; -} // namespace panda::es2panda::ir - -#endif diff --git a/ets2panda/ir/ets/etsWildcardType.cpp b/ets2panda/ir/ets/etsWildcardType.cpp index d389a94820970b98fce6abd582d1589bf1ba76e6..07db87b9c6c5e99b1846269df3f178c6b0c3ee33 100644 --- a/ets2panda/ir/ets/etsWildcardType.cpp +++ b/ets2panda/ir/ets/etsWildcardType.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -15,12 +15,11 @@ #include "etsWildcardType.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/ets/etsTypeReference.h" +#include "checker/TSchecker.h" +#include "checker/ETSchecker.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void ETSWildcardType::TransformChildren(const NodeTransformer &cb) @@ -45,19 +44,16 @@ void ETSWildcardType::Dump(ir::AstDumper *dumper) const {"out", AstDumper::Optional(IsOut())}}); } -void ETSWildcardType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} +void ETSWildcardType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ETSWildcardType::Compile(compiler::ETSGen *etsg) const +void ETSWildcardType::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + etsg->Unimplemented(); } -checker::Type *ETSWildcardType::Check(checker::TSChecker *checker) +checker::Type *ETSWildcardType::Check([[maybe_unused]] checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -65,9 +61,9 @@ checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::TSChecker *che return nullptr; } -checker::Type *ETSWildcardType::Check(checker::ETSChecker *checker) +checker::Type *ETSWildcardType::Check([[maybe_unused]] checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + return nullptr; } checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::ETSChecker *checker) diff --git a/ets2panda/ir/ets/etsWildcardType.h b/ets2panda/ir/ets/etsWildcardType.h index eb9c17a333e24f8c0bca2d1e0b08d89d0d5c2117..4ce8ce2adbed61728aa477c22a1d7fdec22f3a5c 100644 --- a/ets2panda/ir/ets/etsWildcardType.h +++ b/ets2panda/ir/ets/etsWildcardType.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. @@ -25,8 +25,7 @@ public: explicit ETSWildcardType(ir::ETSTypeReference *type_reference, ModifierFlags flags) : TypeNode(AstNodeType::ETS_WILDCARD_TYPE, flags), type_reference_(type_reference) { - ASSERT(flags == ModifierFlags::IN || flags == ModifierFlags::OUT); - ASSERT(type_reference != nullptr || flags == ModifierFlags::OUT); + ASSERT((flags == ModifierFlags::IN && type_reference != nullptr) || flags == ModifierFlags::OUT); } ir::ETSTypeReference *TypeReference() @@ -37,11 +36,11 @@ 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; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check(checker::ETSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index c3c36bef08d178a73a9bc23e6ce871535cb73f3e..887a5eaaf355421efbd40e32a7142a43dd06624e 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -343,11 +343,11 @@ checker::Type *ArrayExpression::Check(checker::TSChecker *checker) for (auto it = element_types.begin(); it != element_types.end(); it++, index++) { util::StringView member_index = util::Helpers::ToStringView(checker->Allocator(), index); - varbinder::LocalVariable *tuple_member = varbinder::Scope::CreateVar( - checker->Allocator(), member_index, varbinder::VariableFlags::PROPERTY, nullptr); + binder::LocalVariable *tuple_member = + binder::Scope::CreateVar(checker->Allocator(), member_index, binder::VariableFlags::PROPERTY, nullptr); if (in_const_context) { - tuple_member->AddFlag(varbinder::VariableFlags::READONLY); + tuple_member->AddFlag(binder::VariableFlags::READONLY); } tuple_member->SetTsType(*it); @@ -406,7 +406,7 @@ checker::Type *ArrayExpression::CheckPattern(checker::TSChecker *checker) if (assignment_pattern->Left()->IsIdentifier()) { const ir::Identifier *ident = assignment_pattern->Left()->AsIdentifier(); ASSERT(ident->Variable()); - varbinder::Variable *binding_var = ident->Variable(); + binder::Variable *binding_var = ident->Variable(); checker::Type *initializer_type = checker->GetBaseTypeOfLiteralType(assignment_pattern->Right()->Check(checker)); binding_var->SetTsType(initializer_type); @@ -459,10 +459,10 @@ checker::Type *ArrayExpression::CheckPattern(checker::TSChecker *checker) util::StringView member_index = util::Helpers::ToStringView(checker->Allocator(), index - 1); auto *member_var = - varbinder::Scope::CreateVar(checker->Allocator(), member_index, varbinder::VariableFlags::PROPERTY, *it); + binder::Scope::CreateVar(checker->Allocator(), member_index, binder::VariableFlags::PROPERTY, *it); if (member_flag == checker::ElementFlags::OPTIONAL) { - member_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + member_var->AddFlag(binder::VariableFlags::OPTIONAL); } else { min_length++; } diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 0cb1b3b65fda36d2382bd984c471d1ff3110e718..a7ceaf07c98cedf1e0434fd224eafc22f089b02c 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -44,21 +44,124 @@ void ArrowFunctionExpression::Dump(ir::AstDumper *dumper) const void ArrowFunctionExpression::Compile(compiler::PandaGen *pg) const { - pg->GetAstCompiler()->Compile(this); + pg->DefineFunction(func_, func_, func_->Scope()->InternalName()); } void ArrowFunctionExpression::Compile(compiler::ETSGen *etsg) const { - etsg->GetAstCompiler()->Compile(this); + ASSERT(resolved_lambda_ != nullptr); + auto *ctor = resolved_lambda_->TsType()->AsETSObjectType()->ConstructSignatures()[0]; + std::vector arguments; + + for (auto *it : captured_vars_) { + if (it->HasFlag(binder::VariableFlags::LOCAL)) { + arguments.push_back(it->AsLocalVariable()->Vreg()); + } + } + + if (propagate_this_) { + arguments.push_back(etsg->GetThisReg()); + } + + etsg->InitLambdaObject(this, ctor, arguments); + etsg->SetAccumulatorType(resolved_lambda_->TsType()); } checker::Type *ArrowFunctionExpression::Check(checker::TSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + binder::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_)); + + if (!func_->Body()->IsExpression()) { + func_->Body()->Check(checker); + } + + return func_type; } checker::Type *ArrowFunctionExpression::Check(checker::ETSChecker *checker) { - return checker->GetAnalyzer()->Check(this); + if (TsType() != nullptr) { + return TsType(); + } + + auto *func_type = checker->BuildFunctionSignature(func_, false); + + if (Function()->IsAsyncFunc()) { + auto *ret_type = static_cast(Function()->Signature()->ReturnType()); + if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { + checker->ThrowTypeError("Return type of async lambda must be 'Promise'", Function()->Start()); + } + } + + checker::ScopeContext scope_ctx(checker, func_->Scope()); + + if (checker->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD)) { + /* + example code: + ``` + class A { + prop:number + } + function A.method() { + let a = () => { + console.println(this.prop) + } + } + ``` + here the enclosing class of arrow function should be Class A + */ + checker->Context().SetContainingClass( + checker->Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS).variable->TsType()->AsETSObjectType()); + } + + checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), + checker->Context().ContainingClass()); + checker->AddStatus(checker::CheckerStatus::IN_LAMBDA); + checker->Context().SetContainingSignature(func_type->CallSignatures()[0]); + + auto *body_type = func_->Body()->Check(checker); + + if (func_->Body()->IsExpression()) { + if (func_->ReturnTypeAnnotation() == nullptr) { + func_type->CallSignatures()[0]->SetReturnType(body_type); + } + + checker::AssignmentContext( + checker->Relation(), func_->Body()->AsExpression(), body_type, func_type->CallSignatures()[0]->ReturnType(), + func_->Start(), + {"Return statements return type is not compatible with the containing functions return type"}, + checker::TypeRelationFlag::DIRECT_RETURN); + } + + checker->Context().SetContainingSignature(nullptr); + checker->CheckCapturedVariables(); + + for (auto [var, _] : checker->Context().CapturedVars()) { + (void)_; + captured_vars_.push_back(var); + } + + SetTsType(func_type); + return TsType(); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2d78a104125f5e3f2f1d7ff3e10f53e32ae864f9..5bcefdb81bafc68f1657f7ef856caeb730c6276c 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -18,10 +18,6 @@ #include "ir/expression.h" -namespace panda::es2panda::compiler { -class ETSCompiler; -} // namespace panda::es2panda::compiler - namespace panda::es2panda::ir { class ScriptFunction; @@ -31,8 +27,6 @@ public: : Expression(AstNodeType::ARROW_FUNCTION_EXPRESSION), func_(func), captured_vars_(allocator->Adapter()) { } - // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields - friend class compiler::ETSCompiler; const ScriptFunction *Function() const { @@ -54,12 +48,12 @@ public: return resolved_lambda_; } - ArenaVector &CapturedVars() + ArenaVector &CapturedVars() { return captured_vars_; } - const ArenaVector &CapturedVars() const + const ArenaVector &CapturedVars() const { return captured_vars_; } @@ -77,14 +71,14 @@ 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([[maybe_unused]] 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; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: ScriptFunction *func_; - ArenaVector captured_vars_; + ArenaVector captured_vars_; ir::ClassDefinition *resolved_lambda_ {nullptr}; bool propagate_this_ {false}; }; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index b1e58362d162ec18d73f82e53e7eb916a0329242..bd1d436bc0ca418aae52bf3af3809b9e506475f9 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -274,7 +274,7 @@ checker::Type *AssignmentExpression::Check([[maybe_unused]] checker::ETSChecker case lexer::TokenType::PUNCTUATOR_BITWISE_OR_EQUAL: case lexer::TokenType::PUNCTUATOR_PLUS_EQUAL: { std::tie(std::ignore, operation_type_) = - checker->CheckBinaryOperator(left_, right_, this, operator_, Start(), true); + checker->CheckBinaryOperator(left_, right_, operator_, Start(), true); auto unboxed_left = checker->ETSBuiltinTypeAsPrimitiveType(left_type); source_type = unboxed_left == nullptr ? left_type : unboxed_left; diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 5f14a1c1cff1321beae8fb22326bc89d9c25353a..c16b3780ca2c7a53b29ac486ec018c1a47f7dab0 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -65,16 +65,6 @@ public: return right_; } - [[nodiscard]] const Expression *Result() const noexcept - { - return result_; - } - - [[nodiscard]] Expression *Result() noexcept - { - return result_; - } - [[nodiscard]] lexer::TokenType OperatorType() const noexcept { return operator_; @@ -85,24 +75,12 @@ public: return operator_ = token_type; } - void SetResult(Expression *expr) noexcept - { - left_ = expr; - SetStart(left_->Start()); - } - - [[nodiscard]] bool IsLogicalExtended() const noexcept - { - return operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || - operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR; - } - - [[nodiscard]] varbinder::Variable *Target() noexcept + [[nodiscard]] binder::Variable *Target() noexcept { return target_; } - [[nodiscard]] varbinder::Variable *Target() const noexcept + [[nodiscard]] binder::Variable *Target() const noexcept { return target_; } @@ -132,9 +110,8 @@ protected: private: Expression *left_ = nullptr; Expression *right_ = nullptr; - Expression *result_ = nullptr; lexer::TokenType operator_; - varbinder::Variable *target_ {}; + binder::Variable *target_ {}; checker::Type *operation_type_ {}; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 796a424ee93218bd7f5201e4dc2b6cf5dc4cb154..14c81a3a0aef7d202c6a71d1aa68797e731e4f1e 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -72,7 +72,7 @@ void AwaitExpression::Compile(compiler::ETSGen *etsg) const checker::Type *AwaitExpression::Check([[maybe_unused]] checker::TSChecker *checker) { - // NOTE: aszilagyi + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 8ba6863dc5df42a16b86f85508a7639a8fd1030f..5c041a13fff7fcb6623b34bd93b5e46d9b1f90bc 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -15,14 +15,16 @@ #include "binaryExpression.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/core/function.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "compiler/core/regScope.h" +#include "checker/ETSchecker.h" #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/expressions/identifier.h" +#include "lexer/token/tokenType.h" namespace panda::es2panda::ir { void BinaryExpression::TransformChildren(const NodeTransformer &cb) @@ -147,47 +149,21 @@ void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const { auto *end_label = etsg->AllocLabel(); - if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - left_->Compile(etsg); - etsg->ApplyConversion(left_, operation_type_); - etsg->BranchIfNotNull(this, end_label); - right_->Compile(etsg); - etsg->ApplyConversion(right_, operation_type_); - etsg->SetLabel(this, end_label); - 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()); + etsg->ApplyConversion(left_, operation_type_); - 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); + etsg->BranchIfFalse(this, end_label); + } else if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR) { + etsg->BranchIfTrue(this, end_label); } 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()); + ASSERT(operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING); + etsg->BranchIfNotNull(this, end_label); } + right_->Compile(etsg); + etsg->ApplyConversion(right_, operation_type_); + etsg->SetLabel(this, end_label); } @@ -241,7 +217,7 @@ checker::Type *BinaryExpression::Check(checker::TSChecker *checker) return checker->CheckOrOperator(left_type, right_type, left_); } case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { - // NOTE: Csaba Repasi. Implement checker for nullish coalescing + // TODO(Csaba Repasi): Implement checker for nullish coalescing return checker->GlobalAnyType(); } case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { @@ -263,7 +239,7 @@ checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) return TsType(); } checker::Type *new_ts_type {nullptr}; - std::tie(new_ts_type, operation_type_) = checker->CheckBinaryOperator(left_, right_, this, operator_, Start()); + std::tie(new_ts_type, operation_type_) = checker->CheckBinaryOperator(left_, right_, operator_, Start()); SetTsType(new_ts_type); return TsType(); } diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c2a1a47bbbc2943a56b1b2822cfa2227ecd71963..de4488f0c1571d467b2d6f819e940d131e981ef2 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -53,16 +53,6 @@ public: return right_; } - [[nodiscard]] const Expression *Result() const noexcept - { - return result_; - } - - [[nodiscard]] Expression *Result() noexcept - { - return result_; - } - [[nodiscard]] lexer::TokenType OperatorType() const noexcept { return operator_; @@ -73,24 +63,12 @@ public: return operator_ <= lexer::TokenType::PUNCTUATOR_LOGICAL_AND; } - [[nodiscard]] bool IsLogicalExtended() const noexcept - { - return operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || - operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR; - } - void SetLeft(Expression *expr) noexcept { left_ = expr; SetStart(left_->Start()); } - void SetResult(Expression *expr) noexcept - { - left_ = expr; - SetStart(left_->Start()); - } - void SetOperator(lexer::TokenType operator_type) noexcept { operator_ = operator_type; @@ -128,7 +106,6 @@ public: private: Expression *left_ = nullptr; Expression *right_ = nullptr; - Expression *result_ = nullptr; lexer::TokenType operator_; checker::Type *operation_type_ {}; }; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 4e7595fc061b67763fd063ddfac730819db54f56..715e0706569785690eee7665cbfe1f27d625e376 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -290,7 +290,7 @@ void CallExpression::Compile(compiler::ETSGen *etsg) const if (!obj->IsMemberExpression() && obj->IsIdentifier()) { auto *var = obj->AsIdentifier()->Variable(); - auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); + auto *data = etsg->Binder()->DynamicImportDataForVar(var); if (data != nullptr) { auto *import = data->import; auto *specifier = data->specifier; @@ -358,7 +358,7 @@ checker::Type *CallExpression::Check(checker::TSChecker *checker) { checker::Type *callee_type = callee_->Check(checker); - // NOTE: aszilagyi. handle optional chain + // TODO(aszilagyi): handle optional chain if (callee_type->IsObjectType()) { checker::ObjectType *callee_obj = callee_type->AsObjectType(); return checker->ResolveCallOrNewExpression(callee_obj->CallSignatures(), arguments_, Start()); diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index 1575bad33336ece01ca04a7a3e6877abec9e7e54..a63399fe5ae9ce8a0192644ba33ea90f314864b1 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_EXPRESSION_CALL_EXPRESSION_H #define ES2PANDA_IR_EXPRESSION_CALL_EXPRESSION_H -#include "varbinder/variable.h" +#include "binder/variable.h" #include "checker/types/ets/etsFunctionType.h" #include "ir/expression.h" diff --git a/ets2panda/ir/expressions/directEvalExpression.h b/ets2panda/ir/expressions/directEvalExpression.h index c9ecd693f9ada5612d211a83fc892151df368d63..0e62ab53e8d1ec79b74e4b868823fd62b44997aa 100644 --- a/ets2panda/ir/expressions/directEvalExpression.h +++ b/ets2panda/ir/expressions/directEvalExpression.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 7f9c194231c0aed7c6c2b7a3d46b99df5c074fff..6800ae4017f7e7c745fa1d14e317beaa631063b3 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -51,7 +51,7 @@ void FunctionExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const checker::Type *FunctionExpression::Check(checker::TSChecker *checker) { - varbinder::Variable *func_var = nullptr; + binder::Variable *func_var = nullptr; if (func_->Parent()->Parent() != nullptr && func_->Parent()->Parent()->IsVariableDeclarator() && func_->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index abe13da98b3373b09249ed821d19aa7e49372001..117ff9e3d2e3514179f8b7fbf88d2b7e91d8f93d 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -15,7 +15,7 @@ #include "identifier.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" @@ -134,8 +134,8 @@ void Identifier::Compile(compiler::PandaGen *pg) const void Identifier::Compile(compiler::ETSGen *etsg) const { - auto lambda = etsg->VarBinder()->LambdaObjects().find(this); - if (lambda != etsg->VarBinder()->LambdaObjects().end()) { + auto lambda = etsg->Binder()->LambdaObjects().find(this); + if (lambda != etsg->Binder()->LambdaObjects().end()) { etsg->CreateLambdaObjectFromIdentReference(this, lambda->second.first); return; } @@ -143,7 +143,7 @@ void Identifier::Compile(compiler::ETSGen *etsg) const auto ttctx = compiler::TargetTypeContext(etsg, TsType()); ASSERT(variable_ != nullptr); - if (!variable_->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { + if (!variable_->HasFlag(binder::VariableFlags::TYPE_ALIAS)) { etsg->LoadVar(this, variable_); } else { etsg->LoadVar(this, TsType()->Variable()); @@ -160,7 +160,7 @@ checker::Type *Identifier::Check(checker::TSChecker *checker) checker->ThrowTypeError({"Cannot find name ", name_}, Start()); } - const varbinder::Decl *decl = Variable()->Declaration(); + const binder::Decl *decl = Variable()->Declaration(); if (decl->IsTypeAliasDecl() || decl->IsInterfaceDecl()) { checker->ThrowTypeError({name_, " only refers to a type, but is being used as a value here."}, Start()); diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index a6ee3dd78ef7aaa4e9400a3bb702c9cd6a3ddc0b..e4b7f7122811eb3268a62b134a817e7e5b8f68a3 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -20,9 +20,9 @@ #include "util/ustring.h" #include "ir/validationInfo.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { enum class IdentifierFlags : uint32_t { @@ -165,17 +165,17 @@ public: flags_ |= IdentifierFlags::IGNORE_BOX; } - [[nodiscard]] varbinder::Variable *Variable() const noexcept + [[nodiscard]] binder::Variable *Variable() const noexcept { return variable_; } - void SetVariable(varbinder::Variable *const variable) noexcept + void SetVariable(binder::Variable *const variable) noexcept { variable_ = variable; } - [[nodiscard]] varbinder::Variable *Variable() noexcept + [[nodiscard]] binder::Variable *Variable() noexcept { return variable_; } @@ -202,7 +202,7 @@ private: util::StringView name_; IdentifierFlags flags_ {IdentifierFlags::NONE}; ArenaVector decorators_; - varbinder::Variable *variable_ {}; + binder::Variable *variable_ {}; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index 6596de257711f061e06f4395377b7ac1fea59ac0..be2d9e348820325d104932c0b32f23eaa48dcc8c 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 048d73884fd2e5dad47d59ef47e11306d7af5867..267ad1da12a4a42f32dcf121bbeb1cf8d806d5da 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index d278513f9fe09ca26e43472a2f48dc2ec46a2fbd..33274a71e75d38620723592a6f8b939aed56d4c4 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -15,7 +15,7 @@ #include "regExpLiteral.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" #include "checker/TSchecker.h" @@ -37,6 +37,7 @@ void RegExpLiteral::Compile(compiler::PandaGen *pg) const checker::Type *RegExpLiteral::Check(checker::TSChecker *checker) { + // TODO(aszilagyi); return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index e0167d4363a8b7745b9fb37e1b5cff9d09573609..6789de0bfbd4157634287be1f72030e85efe57d0 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -126,19 +126,27 @@ void MemberExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg obj_r LoadRhs(pg); } -bool MemberExpression::CompileComputed(compiler::ETSGen *etsg) const +void MemberExpression::Compile(compiler::ETSGen *etsg) const { + auto lambda = etsg->Binder()->LambdaObjects().find(this); + if (lambda != etsg->Binder()->LambdaObjects().end()) { + etsg->CreateLambdaObjectFromMemberReference(this, object_, lambda->second.first); + return; + } + + compiler::RegScope rs(etsg); + if (computed_) { auto ottctx = compiler::TargetTypeContext(etsg, object_->TsType()); object_->Compile(etsg); if (etsg->GetAccumulatorType()->IsETSNullType()) { if (optional_) { - return true; + return; } etsg->EmitNullPointerException(this); - return true; + return; } // Helper function to avoid branching in non optional cases @@ -170,21 +178,6 @@ bool MemberExpression::CompileComputed(compiler::ETSGen *etsg) const compile_and_load_elements(); } - return true; - } - return false; -} - -void MemberExpression::Compile(compiler::ETSGen *etsg) const -{ - auto lambda = etsg->VarBinder()->LambdaObjects().find(this); - if (lambda != etsg->VarBinder()->LambdaObjects().end()) { - etsg->CreateLambdaObjectFromMemberReference(this, object_, lambda->second.first); - return; - } - - compiler::RegScope rs(etsg); - if (CompileComputed(etsg)) { return; } @@ -236,7 +229,7 @@ void MemberExpression::Compile(compiler::ETSGen *etsg) const auto ottctx = compiler::TargetTypeContext(etsg, object_->TsType()); object_->Compile(etsg); - // NOTE: rsipka. it should be CTE if object type is non nullable type + // TODO(rsipka): it should be CTE if object type is non nullable type if (etsg->GetAccumulatorType()->IsETSNullType()) { if (optional_) { @@ -263,8 +256,6 @@ void MemberExpression::Compile(compiler::ETSGen *etsg) const } else if (object_->TsType()->IsETSDynamicType()) { auto lang = object_->TsType()->AsETSDynamicType()->Language(); etsg->LoadPropertyDynamic(this, TsType(), obj_reg, prop_name, lang); - } else if (object_->TsType()->IsETSUnionType()) { - etsg->LoadUnionProperty(this, TsType(), obj_reg, prop_name); } else { const auto full_name = etsg->FormClassPropReference(object_->TsType()->AsETSObjectType(), prop_name); etsg->LoadProperty(this, TsType(), obj_reg, full_name); @@ -335,11 +326,11 @@ checker::Type *MemberExpression::Check(checker::TSChecker *checker) } } - varbinder::Variable *prop = checker->GetPropertyOfType(base_type, property_->AsIdentifier()->Name()); + binder::Variable *prop = checker->GetPropertyOfType(base_type, property_->AsIdentifier()->Name()); if (prop != nullptr) { checker::Type *prop_type = checker->GetTypeOfVariable(prop); - if (prop->HasFlag(varbinder::VariableFlags::READONLY)) { + if (prop->HasFlag(binder::VariableFlags::READONLY)) { prop_type->AddTypeFlag(checker::TypeFlag::READONLY); } @@ -364,29 +355,50 @@ checker::Type *MemberExpression::Check(checker::TSChecker *checker) return nullptr; } -checker::Type *MemberExpression::CheckEnumMember(checker::ETSChecker *checker, checker::Type *type) +checker::Type *MemberExpression::Check(checker::ETSChecker *checker) { - auto const *const enum_interface = [type]() -> checker::ETSEnumInterface const * { - if (type->IsETSEnumType()) { - return type->AsETSEnumType(); - } - return type->AsETSStringEnumType(); - }(); + if (TsType() != nullptr) { + return TsType(); + } - if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { - auto *const enum_method_type = enum_interface->LookupMethod(checker, object_, property_->AsIdentifier()); - SetTsType(enum_method_type); + if (computed_) { + SetTsType(checker->CheckArrayElementAccess(this)); return TsType(); } - auto *const enum_literal_type = enum_interface->LookupConstant(checker, object_, property_->AsIdentifier()); - SetTsType(enum_literal_type); - SetPropVar(enum_literal_type->GetMemberVar()); - return TsType(); -} + checker::Type *const base_type = object_->Check(checker); -checker::Type *MemberExpression::CheckObjectMember(checker::ETSChecker *checker) -{ + if (!base_type->IsETSObjectType()) { + if (base_type->IsETSArrayType() && property_->AsIdentifier()->Name().Is("length")) { + SetTsType(checker->GlobalIntType()); + return TsType(); + } + + if (base_type->IsETSEnumType() || base_type->IsETSStringEnumType()) { + auto const *const enum_interface = [base_type]() -> checker::ETSEnumInterface const * { + if (base_type->IsETSEnumType()) { + return base_type->AsETSEnumType(); + } + return base_type->AsETSStringEnumType(); + }(); + + if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { + auto *const enum_method_type = + enum_interface->LookupMethod(checker, object_, property_->AsIdentifier()); + SetTsType(enum_method_type); + return TsType(); + } + + auto *const enum_literal_type = enum_interface->LookupConstant(checker, object_, property_->AsIdentifier()); + SetTsType(enum_literal_type); + SetPropVar(enum_literal_type->GetMemberVar()); + return TsType(); + } + + checker->ThrowTypeError({"Cannot access property of non-object or non-enum type"}, object_->Start()); + } + + obj_type_ = base_type->AsETSObjectType(); auto resolve_res = checker->ResolveMemberReference(this, obj_type_); ASSERT(!resolve_res.empty()); checker::Type *type_to_set = nullptr; @@ -401,7 +413,7 @@ checker::Type *MemberExpression::CheckObjectMember(checker::ETSChecker *checker) } break; } - case 2U: { + case 2: { // ETSExtensionFuncHelperType(class_method_type, extension_method_type) type_to_set = checker->CreateETSExtensionFuncHelperType( checker->GetTypeOfVariable(resolve_res[1]->Variable())->AsETSFunctionType(), @@ -423,61 +435,6 @@ checker::Type *MemberExpression::CheckObjectMember(checker::ETSChecker *checker) return TsType(); } -checker::Type *MemberExpression::Check(checker::ETSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - if (computed_) { - SetTsType(checker->CheckArrayElementAccess(this)); - return TsType(); - } - - checker::Type *const base_type = object_->Check(checker); - - if (!base_type->IsETSObjectType()) { - if (base_type->IsETSArrayType() && property_->AsIdentifier()->Name().Is("length")) { - SetTsType(checker->GlobalIntType()); - return TsType(); - } - - if (base_type->IsETSUnionType()) { - auto *const union_type = base_type->AsETSUnionType(); - checker::Type *member_type = nullptr; - auto check_member_type = [this, checker, &member_type]() { - if (member_type != nullptr && member_type != TsType()) { - checker->ThrowTypeError("Member type must be the same for all union objects.", Start()); - } - member_type = TsType(); - }; - for (auto *type : union_type->ConstituentTypes()) { - if (type->IsETSObjectType()) { - obj_type_ = type->AsETSObjectType(); - CheckObjectMember(checker); - check_member_type(); - } - - if (type->IsETSEnumType() || base_type->IsETSStringEnumType()) { - CheckEnumMember(checker, type); - check_member_type(); - } - } - obj_type_ = union_type->GetLeastUpperBoundType(checker)->AsETSObjectType(); - return TsType(); - } - - if (base_type->IsETSEnumType() || base_type->IsETSStringEnumType()) { - return CheckEnumMember(checker, base_type); - } - - checker->ThrowTypeError({"Cannot access property of non-object or non-enum type"}, object_->Start()); - } - - obj_type_ = base_type->AsETSObjectType(); - return CheckObjectMember(checker); -} - // NOLINTNEXTLINE(google-default-arguments) Expression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 074a218537625cdc8d1bedc631b791ff34b23a7f..4c786300a047026c71d37d898f591a51c82f30e1 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -16,8 +16,7 @@ #ifndef ES2PANDA_IR_EXPRESSION_MEMBER_EXPRESSION_H #define ES2PANDA_IR_EXPRESSION_MEMBER_EXPRESSION_H -#include "varbinder/variable.h" -#include "checker/types/ets/etsObjectType.h" +#include "binder/variable.h" #include "ir/expression.h" #include "ir/irnode.h" @@ -80,12 +79,12 @@ public: return property_; } - [[nodiscard]] varbinder::LocalVariable *PropVar() noexcept + [[nodiscard]] binder::LocalVariable *PropVar() noexcept { return prop_var_; } - [[nodiscard]] const varbinder::LocalVariable *PropVar() const noexcept + [[nodiscard]] const binder::LocalVariable *PropVar() const noexcept { return prop_var_; } @@ -125,7 +124,7 @@ public: return obj_type_; } - void SetPropVar(varbinder::LocalVariable *prop_var) noexcept + void SetPropVar(binder::LocalVariable *prop_var) noexcept { prop_var_ = prop_var; } @@ -147,16 +146,12 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; - checker::Type *CheckEnumMember(checker::ETSChecker *checker, checker::Type *type); - checker::Type *CheckObjectMember(checker::ETSChecker *checker); - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] Expression *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; - bool CompileComputed(compiler::ETSGen *etsg) const; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; void CompileToReg(compiler::PandaGen *pg, compiler::VReg obj_reg) const; @@ -184,7 +179,7 @@ private: bool computed_; bool optional_; bool ignore_box_ {false}; - varbinder::LocalVariable *prop_var_ {}; + binder::LocalVariable *prop_var_ {}; checker::ETSObjectType *obj_type_ {}; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index 565ba8caa42aac382506643a66d32de7706a6e23..d8783c717449b710e11118669494f506468aefab 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -91,7 +91,7 @@ void NewExpression::Compile(compiler::PandaGen *pg) const pg->StoreAccumulator(this, arg); } - pg->NewObject(this, ctor, arguments_.size() + 2U); + pg->NewObject(this, ctor, arguments_.size() + 2); } else { compiler::VReg args_obj = pg->AllocReg(); diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 4722ba826ace0cfcd801799ffbd96a0d46804822..07df2d8c8280e2a938f2d4577a77197d29dbe75f 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -130,7 +130,7 @@ ValidationInfo ObjectExpression::ValidateExpression() bool ObjectExpression::ConvertibleToObjectPattern() { - // NOTE: rsipka. throw more precise messages in case of false results + // TODO(rsipka): throw more precise messages in case of false results bool rest_found = false; bool conv_result = true; @@ -449,9 +449,9 @@ checker::Type *ObjectExpression::CheckPattern(checker::TSChecker *checker) continue; } - varbinder::LocalVariable *found_var = desc->FindProperty(prop->Key()->AsIdentifier()->Name()); + binder::LocalVariable *found_var = desc->FindProperty(prop->Key()->AsIdentifier()->Name()); checker::Type *pattern_param_type = checker->GlobalAnyType(); - varbinder::Variable *binding_var = nullptr; + binder::Variable *binding_var = nullptr; if (prop->IsShorthand()) { switch (prop->Value()->Type()) { @@ -545,12 +545,12 @@ checker::Type *ObjectExpression::CheckPattern(checker::TSChecker *checker) continue; } - varbinder::LocalVariable *pattern_var = varbinder::Scope::CreateVar( - checker->Allocator(), prop->Key()->AsIdentifier()->Name(), varbinder::VariableFlags::PROPERTY, *it); + binder::LocalVariable *pattern_var = binder::Scope::CreateVar( + checker->Allocator(), prop->Key()->AsIdentifier()->Name(), binder::VariableFlags::PROPERTY, *it); pattern_var->SetTsType(pattern_param_type); if (is_optional) { - pattern_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + pattern_var->AddFlag(binder::VariableFlags::OPTIONAL); } desc->properties.insert(desc->properties.begin(), pattern_var); @@ -575,16 +575,16 @@ const util::StringView &GetPropertyName(const ir::Expression *key) return key->AsNumberLiteral()->Str(); } -varbinder::VariableFlags GetFlagsForProperty(const ir::Property *prop) +binder::VariableFlags GetFlagsForProperty(const ir::Property *prop) { if (!prop->IsMethod()) { - return varbinder::VariableFlags::PROPERTY; + return binder::VariableFlags::PROPERTY; } - varbinder::VariableFlags prop_flags = varbinder::VariableFlags::METHOD; + binder::VariableFlags prop_flags = binder::VariableFlags::METHOD; if (prop->IsAccessor() && prop->Kind() == PropertyKind::GET) { - prop_flags |= varbinder::VariableFlags::READONLY; + prop_flags |= binder::VariableFlags::READONLY; } return prop_flags; @@ -642,13 +642,13 @@ checker::Type *ObjectExpression::Check(checker::TSChecker *checker) } checker::Type *prop_type = GetTypeForProperty(prop, checker); - varbinder::VariableFlags flags = GetFlagsForProperty(prop); + binder::VariableFlags flags = GetFlagsForProperty(prop); const util::StringView &prop_name = GetPropertyName(prop->Key()); - auto *member_var = varbinder::Scope::CreateVar(checker->Allocator(), prop_name, flags, it); + auto *member_var = binder::Scope::CreateVar(checker->Allocator(), prop_name, flags, it); if (in_const_context) { - member_var->AddFlag(varbinder::VariableFlags::READONLY); + member_var->AddFlag(binder::VariableFlags::READONLY); } else { prop_type = checker->GetBaseTypeOfLiteralType(prop_type); } @@ -656,10 +656,10 @@ checker::Type *ObjectExpression::Check(checker::TSChecker *checker) member_var->SetTsType(prop_type); if (prop->Key()->IsNumberLiteral()) { - member_var->AddFlag(varbinder::VariableFlags::NUMERIC_NAME); + member_var->AddFlag(binder::VariableFlags::NUMERIC_NAME); } - varbinder::LocalVariable *found_member = desc->FindProperty(prop_name); + binder::LocalVariable *found_member = desc->FindProperty(prop_name); all_properties_map.insert({prop_name, it->Start()}); if (found_member != nullptr) { @@ -676,7 +676,7 @@ checker::Type *ObjectExpression::Check(checker::TSChecker *checker) checker::Type *const spread_type = it->AsSpreadElement()->Argument()->Check(checker); seen_spread = true; - // N OTE: aszilagyi. handle union of object types + // TODO(aszilagyi): handle union of object types if (!spread_type->IsObjectType()) { checker->ThrowTypeError("Spread types may only be created from object types.", it->Start()); } @@ -688,7 +688,7 @@ checker::Type *ObjectExpression::Check(checker::TSChecker *checker) {found->first, " is specified more than once, so this usage will be overwritten."}, found->second); } - varbinder::LocalVariable *found_member = desc->FindProperty(spread_prop->Name()); + binder::LocalVariable *found_member = desc->FindProperty(spread_prop->Name()); if (found_member != nullptr) { found_member->SetTsType(spread_prop->TsType()); @@ -703,7 +703,7 @@ checker::Type *ObjectExpression::Check(checker::TSChecker *checker) for (auto *it : desc->properties) { computed_string_prop_types.push_back(it->TsType()); - if (has_computed_number_property && it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME)) { + if (has_computed_number_property && it->HasFlag(binder::VariableFlags::NUMERIC_NAME)) { computed_number_prop_types.push_back(it->TsType()); } } @@ -838,13 +838,13 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) } else { checker->ThrowTypeError({"key in class composite should be either identifier or string literal"}, Start()); } - varbinder::LocalVariable *lv = obj_type->GetProperty( - pname, checker::PropertySearchFlags::SEARCH_INSTANCE_FIELD | checker::PropertySearchFlags::SEARCH_IN_BASE); + binder::LocalVariable *lv = obj_type->GetProperty(pname, checker::PropertySearchFlags::SEARCH_INSTANCE_FIELD | + checker::PropertySearchFlags::SEARCH_IN_BASE); if (lv == nullptr) { checker->ThrowTypeError({"type ", obj_type->Name(), " has no property named ", pname}, prop_expr->Start()); } checker->ValidatePropertyAccess(lv, obj_type, prop_expr->Start()); - if (lv->HasFlag(varbinder::VariableFlags::READONLY)) { + if (lv->HasFlag(binder::VariableFlags::READONLY)) { checker->ThrowTypeError({"cannot assign to readonly property ", pname}, prop_expr->Start()); } diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index b258313d0b93de38a1d3b55eab3cae03dfbc5123..b0803651c6966355b9c0b9b38743d2dff597eb01 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_EXPRESSION_OBJECT_EXPRESSION_H #define ES2PANDA_IR_EXPRESSION_OBJECT_EXPRESSION_H -#include "varbinder/variable.h" +#include "binder/variable.h" #include "ir/expression.h" #include "ir/validationInfo.h" diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index cde77a042f784b3d3574295e4c64f03e31ef02f6..637dc990cc74985bfaccf2d0aaddbfb8a9752786 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -75,7 +75,7 @@ void SequenceExpression::Compile(compiler::ETSGen *etsg) const checker::Type *SequenceExpression::Check([[maybe_unused]] checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index c70a15e50f7fe4a640774ef7e2c768c52f7e198d..67e4625b59effaa25188e8758da11dadf0cc57e5 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -49,7 +49,7 @@ void SuperExpression::Compile(compiler::ETSGen *etsg) const checker::Type *SuperExpression::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 3960c0d1c3ee7c915b032ecb59f765e754cdf4d2..2422568d44c08b0ddb95907da632ebd5d0bc439c 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -15,7 +15,7 @@ #include "taggedTemplateExpression.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/base/literals.h" #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" @@ -73,7 +73,7 @@ void TaggedTemplateExpression::Compile(compiler::PandaGen *pg) const checker::Type *TaggedTemplateExpression::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 82a52458f67c586989cd81b76cccedc736d56c51..af172b787884fb480c0be8a351ecf661398716e1 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -120,7 +120,7 @@ void TemplateLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const checker::Type *TemplateLiteral::Check([[maybe_unused]] checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 4bfd27544111932efed650ee506898500715312c..0c3b8d5b9b274bffa877452e257fed1000ea13ab 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -16,7 +16,7 @@ #include "thisExpression.h" #include "util/helpers.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" @@ -39,7 +39,7 @@ void ThisExpression::Dump(ir::AstDumper *dumper) const void ThisExpression::Compile(compiler::PandaGen *pg) const { - auto res = pg->Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS); + auto res = pg->Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS); ASSERT(res.variable && res.variable->IsLocalVariable()); pg->LoadAccFromLexEnv(this, res); @@ -58,7 +58,7 @@ void ThisExpression::Compile(compiler::ETSGen *etsg) const checker::Type *ThisExpression::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi + // TODO(aszilagyi) return checker->GlobalAnyType(); } @@ -89,7 +89,7 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) here when "this" is used inside an extension function, we need to bind "this" to the first parameter(MANDATORY_PARAM_THIS), and capture the paramter's variable other than containing class's variable */ - auto *variable = checker->AsETSChecker()->Scope()->Find(varbinder::VarBinder::MANDATORY_PARAM_THIS).variable; + auto *variable = checker->AsETSChecker()->Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS).variable; if (checker->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD)) { ASSERT(variable != nullptr); SetTsType(variable->TsType()); diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index d85b7e9479d1346d8666cc88f5c2eb8456aaecea..4570f0e2b361183929bf586de0a420c167a24e01 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -15,7 +15,7 @@ #include "unaryExpression.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" @@ -24,7 +24,6 @@ #include "ir/expressions/identifier.h" #include "ir/expressions/literals/bigIntLiteral.h" #include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/callExpression.h" #include "ir/expressions/memberExpression.h" namespace panda::es2panda::ir { @@ -127,43 +126,6 @@ void UnaryExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const etsg->Unary(this, operator_); } -checker::Type *UnaryExpression::CheckDeleteKeyword([[maybe_unused]] checker::TSChecker *checker) -{ - checker::Type *prop_type = argument_->Check(checker); - if (!argument_->IsMemberExpression()) { - checker->ThrowTypeError("The operand of a delete operator must be a property reference.", argument_->Start()); - } - if (prop_type->Variable()->HasFlag(varbinder::VariableFlags::READONLY)) { - checker->ThrowTypeError("The operand of a delete operator cannot be a readonly property.", argument_->Start()); - } - if (!prop_type->Variable()->HasFlag(varbinder::VariableFlags::OPTIONAL)) { - checker->ThrowTypeError("The operand of a delete operator must be a optional.", argument_->Start()); - } - return checker->GlobalBooleanType(); -} - -checker::Type *UnaryExpression::CheckLiteral([[maybe_unused]] checker::TSChecker *checker) -{ - if (!argument_->IsLiteral()) { - return nullptr; - } - - const ir::Literal *lit = argument_->AsLiteral(); - if (lit->IsNumberLiteral()) { - auto number_value = lit->AsNumberLiteral()->Number().GetDouble(); - if (operator_ == lexer::TokenType::PUNCTUATOR_PLUS) { - return checker->CreateNumberLiteralType(number_value); - } - if (operator_ == lexer::TokenType::PUNCTUATOR_MINUS) { - return checker->CreateNumberLiteralType(-number_value); - } - } else if (lit->IsBigIntLiteral() && operator_ == lexer::TokenType::PUNCTUATOR_MINUS) { - return checker->CreateBigintLiteralType(lit->AsBigIntLiteral()->Str(), true); - } - - return nullptr; -} - checker::Type *UnaryExpression::Check([[maybe_unused]] checker::TSChecker *checker) { checker::Type *operand_type = argument_->Check(checker); @@ -173,12 +135,40 @@ checker::Type *UnaryExpression::Check([[maybe_unused]] checker::TSChecker *check } if (operator_ == lexer::TokenType::KEYW_DELETE) { - return CheckDeleteKeyword(checker); + checker::Type *prop_type = argument_->Check(checker); + + if (!argument_->IsMemberExpression()) { + checker->ThrowTypeError("The operand of a delete operator must be a property reference.", + argument_->Start()); + } + + if (prop_type->Variable()->HasFlag(binder::VariableFlags::READONLY)) { + checker->ThrowTypeError("The operand of a delete operator cannot be a readonly property.", + argument_->Start()); + } + + if (!prop_type->Variable()->HasFlag(binder::VariableFlags::OPTIONAL)) { + checker->ThrowTypeError("The operand of a delete operator must be a optional.", argument_->Start()); + } + + return checker->GlobalBooleanType(); } - auto *res = CheckLiteral(checker); - if (res != nullptr) { - return res; + if (argument_->IsLiteral()) { + const ir::Literal *lit = argument_->AsLiteral(); + + if (lit->IsNumberLiteral()) { + auto number_value = lit->AsNumberLiteral()->Number().GetDouble(); + if (operator_ == lexer::TokenType::PUNCTUATOR_PLUS) { + return checker->CreateNumberLiteralType(number_value); + } + + if (operator_ == lexer::TokenType::PUNCTUATOR_MINUS) { + return checker->CreateNumberLiteralType(-number_value); + } + } else if (lit->IsBigIntLiteral() && operator_ == lexer::TokenType::PUNCTUATOR_MINUS) { + return checker->CreateBigintLiteralType(lit->AsBigIntLiteral()->Str(), true); + } } switch (operator_) { @@ -186,7 +176,7 @@ checker::Type *UnaryExpression::Check([[maybe_unused]] checker::TSChecker *check case lexer::TokenType::PUNCTUATOR_MINUS: case lexer::TokenType::PUNCTUATOR_TILDE: { checker->CheckNonNullType(operand_type, Start()); - // NOTE: aszilagyi. check Symbol like types + // TODO(aszilagyi): check Symbol like types if (operator_ == lexer::TokenType::PUNCTUATOR_PLUS) { if (checker::TSChecker::MaybeTypeOfKind(operand_type, checker::TypeFlag::BIGINT_LIKE)) { @@ -226,10 +216,8 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) } auto arg_type = argument_->Check(checker); - const auto is_cond_expr = operator_ == lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK; - checker::Type *operand_type = checker->ApplyUnaryOperatorPromotion(arg_type, true, true, is_cond_expr); - auto unboxed_operand_type = is_cond_expr ? checker->ETSBuiltinTypeAsConditionalType(arg_type) - : checker->ETSBuiltinTypeAsPrimitiveType(arg_type); + checker::Type *operand_type = checker->ApplyUnaryOperatorPromotion(arg_type); + auto unboxed_operand_type = checker->ETSBuiltinTypeAsPrimitiveType(arg_type); switch (operator_) { case lexer::TokenType::PUNCTUATOR_MINUS: @@ -263,23 +251,13 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) break; } case lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK: { - if (checker->IsNullOrVoidExpression(argument_)) { - auto ts_type = checker->CreateETSBooleanType(true); - ts_type->AddTypeFlag(checker::TypeFlag::CONSTANT); - SetTsType(ts_type); - break; - } - - if (operand_type == nullptr || !operand_type->IsConditionalExprType()) { + if (operand_type == nullptr || !operand_type->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { checker->ThrowTypeError("Bad operand type, the type of the operand must be boolean type.", argument_->Start()); } - auto expr_res = operand_type->ResolveConditionExpr(); - if (std::get<0>(expr_res)) { - auto ts_type = checker->CreateETSBooleanType(!std::get<1>(expr_res)); - ts_type->AddTypeFlag(checker::TypeFlag::CONSTANT); - SetTsType(ts_type); + if (operand_type->HasTypeFlag(checker::TypeFlag::CONSTANT)) { + SetTsType(checker->CreateETSBooleanType(!operand_type->AsETSBooleanType()->GetValue())); break; } @@ -296,8 +274,7 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) } } - if (arg_type->IsETSObjectType() && (unboxed_operand_type != nullptr) && - unboxed_operand_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + if (arg_type->IsETSObjectType() && (unboxed_operand_type != nullptr)) { argument_->AddBoxingUnboxingFlag(checker->GetUnboxingFlag(unboxed_operand_type)); } diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index 1e2fb24c0b3e260332e46efe3022f22b27dd2987..535f4db84ecc0dbc6c5d09f316b83ea3808e7826 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -63,8 +63,6 @@ public: 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 *CheckDeleteKeyword([[maybe_unused]] checker::TSChecker *checker); - checker::Type *CheckLiteral([[maybe_unused]] checker::TSChecker *checker); private: Expression *argument_; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 6eab97e3ee793141753b3c4e1728ec5c88905405..0df9eafb5efde93e275be2cc452525dc98757447 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -15,7 +15,7 @@ #include "updateExpression.h" -#include "varbinder/variable.h" +#include "binder/variable.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" @@ -127,7 +127,7 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) checker->ValidateUnaryOperatorOperand(argument_->AsIdentifier()->Variable()); } else { ASSERT(argument_->IsMemberExpression()); - varbinder::LocalVariable *prop_var = argument_->AsMemberExpression()->PropVar(); + binder::LocalVariable *prop_var = argument_->AsMemberExpression()->PropVar(); if (prop_var != nullptr) { checker->ValidateUnaryOperatorOperand(prop_var); } diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index f8e8efda91d1651126c5b091605732b7ca84b874..b81c83d4993104aa7238862858bc6f83ca305d64 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -60,7 +60,7 @@ void YieldExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const checker::Type *YieldExpression::Check([[maybe_unused]] checker::TSChecker *checker) { - // NOTE: aszilagyi. + // TODO(aszilagyi) return checker->GlobalAnyType(); } diff --git a/ets2panda/ir/irnode.cpp b/ets2panda/ir/irnode.cpp index 4f2344a4bef6f5fdc49ee1f2fa45d3d5ac7026bd..f89cac364c9c843d92ebff25bfca08c49c768215 100644 --- a/ets2panda/ir/irnode.cpp +++ b/ets2panda/ir/irnode.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/irnode.h b/ets2panda/ir/irnode.h index 5192e38bb87d5b653b8b785efd6a39e6ceb76bdc..a9ff567e24a2b19194966be13247507d267463b1 100644 --- a/ets2panda/ir/irnode.h +++ b/ets2panda/ir/irnode.h @@ -132,7 +132,7 @@ public: if (reg >= VReg::PARAM_START) { new_reg = reg - VReg::PARAM_START + reg_count; - // NOTE: dbatiz. Remove this else if, and fix the regIndexes + // TODO(dbatiz) Remove this else if, and fix the regIndexes } else if (reg <= reg_count + VReg::MANDATORY_PARAM_NUM) { new_reg = VReg::REG_START - total_regs + VReg::MANDATORY_PARAM_NUM + reg; } else { diff --git a/ets2panda/ir/module/importNamespaceSpecifier.cpp b/ets2panda/ir/module/importNamespaceSpecifier.cpp index 9607da9ba6a098627b7b78b4c0d9d03a15096575..466ed4e40798d89c5a66411c09fbe4384d442ec5 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.cpp +++ b/ets2panda/ir/module/importNamespaceSpecifier.cpp @@ -16,7 +16,7 @@ #include "importNamespaceSpecifier.h" #include "checker/ETSchecker.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "ir/astDump.h" #include "ir/expressions/identifier.h" #include "ir/module/importDeclaration.h" @@ -84,9 +84,9 @@ checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::ETSChec 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); + auto *root_decl = checker->Allocator()->New(synthetic_names[0]); + binder::LocalVariable *root_var = + checker->Allocator()->New(root_decl, binder::VariableFlags::NONE); root_var->SetTsType(module_object_type); synthetic_names.erase(synthetic_names.begin()); @@ -97,9 +97,9 @@ checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::ETSChec 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); + auto *class_decl = checker->Allocator()->New(synthetic_name); + binder::LocalVariable *var = + checker->Allocator()->New(class_decl, binder::VariableFlags::CLASS); var->SetTsType(synthetic_obj_type); last_object_type->AddProperty(var); synthetic_obj_type->SetEnclosingType(last_object_type); diff --git a/ets2panda/ir/opaqueTypeNode.cpp b/ets2panda/ir/opaqueTypeNode.cpp index 977e9efd708810ddac5ef099c927c32ec7c8dfe7..fb25acf55ebf9bb22e4b586c3dda00ed2b107087 100644 --- a/ets2panda/ir/opaqueTypeNode.cpp +++ b/ets2panda/ir/opaqueTypeNode.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/opaqueTypeNode.h b/ets2panda/ir/opaqueTypeNode.h index 676f5478d4a703855479052ec88cfb2b6bad9d70..cd3ce28cc3da68d9af39099146c8f98fc7ffd398 100644 --- a/ets2panda/ir/opaqueTypeNode.h +++ b/ets2panda/ir/opaqueTypeNode.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/ir/opcodeMap.h b/ets2panda/ir/opcodeMap.h index a6073bcb99624014b88267f82fd8209eca68440d..8123bc6349291a5ffa5b3e4abbc51c8392f405b2 100644 --- a/ets2panda/ir/opcodeMap.h +++ b/ets2panda/ir/opcodeMap.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/ir/statements/assertStatement.cpp b/ets2panda/ir/statements/assertStatement.cpp index ded0f277170515d97b251becc546cce4d550b822..01181345ae480efc149c7bca0917e2d8f810d940 100644 --- a/ets2panda/ir/statements/assertStatement.cpp +++ b/ets2panda/ir/statements/assertStatement.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -15,7 +15,7 @@ #include "assertStatement.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "compiler/base/condition.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" @@ -71,7 +71,8 @@ void AssertStatement::ThrowError(compiler::ETSGen *const etsg) const void AssertStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - auto res = compiler::Condition::CheckConstantExpr(etsg, test_); + auto res = compiler::Condition::CheckConstantExpr(test_); + if (res == compiler::Condition::Result::CONST_TRUE) { return; } diff --git a/ets2panda/ir/statements/assertStatement.h b/ets2panda/ir/statements/assertStatement.h index 749c5c739be791db07da7efdc043137f83d23f2d..ec70fe0c3382dd99a1f96c7555530ef0e75a7713 100644 --- a/ets2panda/ir/statements/assertStatement.h +++ b/ets2panda/ir/statements/assertStatement.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/ir/statements/blockStatement.cpp b/ets2panda/ir/statements/blockStatement.cpp index 948c0fc83d9bc093bcf44dea5bbd4936efd2ceb9..69a50289a6e59a44e9aa7b0254c2ff911cedcf20 100644 --- a/ets2panda/ir/statements/blockStatement.cpp +++ b/ets2panda/ir/statements/blockStatement.cpp @@ -15,7 +15,7 @@ #include "blockStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/core/regScope.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" diff --git a/ets2panda/ir/statements/blockStatement.h b/ets2panda/ir/statements/blockStatement.h index 2716162ef20cc46ff94cf86713ebf9e7c520eabb..4e02c2296f5c7b6290265a90528ca1248870b447 100644 --- a/ets2panda/ir/statements/blockStatement.h +++ b/ets2panda/ir/statements/blockStatement.h @@ -21,8 +21,7 @@ namespace panda::es2panda::ir { class BlockStatement : public Statement { public: - explicit BlockStatement(ArenaAllocator *allocator, varbinder::Scope *scope, - ArenaVector &&statement_list) + explicit BlockStatement(ArenaAllocator *allocator, binder::Scope *scope, ArenaVector &&statement_list) : Statement(AstNodeType::BLOCK_STATEMENT), scope_(scope), statements_(std::move(statement_list)), @@ -35,12 +34,12 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } - void SetScope(varbinder::Scope *scope) + void SetScope(binder::Scope *scope) { scope_ = scope; } @@ -78,7 +77,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; ArenaVector statements_; ArenaUnorderedMap trailing_blocks_; }; diff --git a/ets2panda/ir/statements/doWhileStatement.cpp b/ets2panda/ir/statements/doWhileStatement.cpp index e36442c438d676836f8e153234cd403a5ea8ac23..d7a875423f3d52aeeab38069de7e109e159e9b53 100644 --- a/ets2panda/ir/statements/doWhileStatement.cpp +++ b/ets2panda/ir/statements/doWhileStatement.cpp @@ -15,7 +15,7 @@ #include "doWhileStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/base/condition.h" #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" diff --git a/ets2panda/ir/statements/doWhileStatement.h b/ets2panda/ir/statements/doWhileStatement.h index 58b970bfdcecebd33c19ab6b66e1d7fcb69ce851..58cf43cfca1af649dd59b60d67b4e6d3ef12fe2c 100644 --- a/ets2panda/ir/statements/doWhileStatement.h +++ b/ets2panda/ir/statements/doWhileStatement.h @@ -18,16 +18,16 @@ #include "ir/statements/loopStatement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LoopScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Expression; class DoWhileStatement : public LoopStatement { public: - explicit DoWhileStatement(varbinder::LoopScope *scope, Statement *body, Expression *test) + explicit DoWhileStatement(binder::LoopScope *scope, Statement *body, Expression *test) : LoopStatement(AstNodeType::DO_WHILE_STATEMENT, scope), body_(body), test_(test) { } diff --git a/ets2panda/ir/statements/forInStatement.cpp b/ets2panda/ir/statements/forInStatement.cpp index b21b387e5d819c361781df5ef246153ef6dd3d6d..2a3a56cce8a51b3a37eee70f2d705d0b77184cf0 100644 --- a/ets2panda/ir/statements/forInStatement.cpp +++ b/ets2panda/ir/statements/forInStatement.cpp @@ -15,7 +15,7 @@ #include "forInStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" diff --git a/ets2panda/ir/statements/forInStatement.h b/ets2panda/ir/statements/forInStatement.h index 1089e3ffa4875d5b9040c3d74c90e07c7c9dc9f0..c8e99fb4fb670336cffa9225866a076bbfdd9f1f 100644 --- a/ets2panda/ir/statements/forInStatement.h +++ b/ets2panda/ir/statements/forInStatement.h @@ -18,16 +18,16 @@ #include "ir/statements/loopStatement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LoopScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Expression; class ForInStatement : public LoopStatement { public: - explicit ForInStatement(varbinder::LoopScope *scope, AstNode *left, Expression *right, Statement *body) + explicit ForInStatement(binder::LoopScope *scope, AstNode *left, Expression *right, Statement *body) : LoopStatement(AstNodeType::FOR_IN_STATEMENT, scope), left_(left), right_(right), body_(body) { } diff --git a/ets2panda/ir/statements/forOfStatement.cpp b/ets2panda/ir/statements/forOfStatement.cpp index 1b7ae5a7cc17222bc20fb1a1eda01b3978f74d1f..0e8fedbbc02c44b26f974ec98bbf08d431a4bd94 100644 --- a/ets2panda/ir/statements/forOfStatement.cpp +++ b/ets2panda/ir/statements/forOfStatement.cpp @@ -15,7 +15,7 @@ #include "forOfStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/base/iterators.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" @@ -168,20 +168,6 @@ checker::Type *ForOfStatement::Check(checker::ETSChecker *checker) 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()) { @@ -192,7 +178,15 @@ checker::Type *ForOfStatement::Check(checker::ETSChecker *checker) 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 (auto const &for_iterator = declarators.front(); for_iterator->TsType() == nullptr) { + if (auto *resolved = checker->FindVariableInFunctionScope(for_iterator->Id()->AsIdentifier()->Name()); + resolved != nullptr) { + resolved->SetTsType(elem_type); + iter_type = elem_type; + } + } else { + iter_type = for_iterator->TsType(); + } } } diff --git a/ets2panda/ir/statements/forOfStatement.h b/ets2panda/ir/statements/forOfStatement.h index 51a99573c8ca30a73b4e6e2a4bb42a9a3e27ea36..9bb2ecf8d51dd132908988e1d8230a0b3c7d32ab 100644 --- a/ets2panda/ir/statements/forOfStatement.h +++ b/ets2panda/ir/statements/forOfStatement.h @@ -18,17 +18,16 @@ #include "ir/statements/loopStatement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LoopScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Expression; class ForOfStatement : public LoopStatement { public: - explicit ForOfStatement(varbinder::LoopScope *scope, AstNode *left, Expression *right, Statement *body, - bool is_await) + explicit ForOfStatement(binder::LoopScope *scope, AstNode *left, Expression *right, Statement *body, bool is_await) : LoopStatement(AstNodeType::FOR_OF_STATEMENT, scope), left_(left), right_(right), diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 8921f4e5cdfdee0ae20deb2409abc6b1318d5fb3..d297b0a52fbcc177e3e6302bccb81c3f16c598a6 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -15,7 +15,7 @@ #include "forUpdateStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" diff --git a/ets2panda/ir/statements/forUpdateStatement.h b/ets2panda/ir/statements/forUpdateStatement.h index f79166695e3efc93d0e6fa272d6def0f8de14a68..d6a1c001a7311e6754a6d13401c44fdc0d563b33 100644 --- a/ets2panda/ir/statements/forUpdateStatement.h +++ b/ets2panda/ir/statements/forUpdateStatement.h @@ -18,16 +18,16 @@ #include "ir/statements/loopStatement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LoopScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Expression; class ForUpdateStatement : public LoopStatement { public: - explicit ForUpdateStatement(varbinder::LoopScope *scope, AstNode *init, Expression *test, Expression *update, + explicit ForUpdateStatement(binder::LoopScope *scope, AstNode *init, Expression *test, Expression *update, Statement *body) : LoopStatement(AstNodeType::FOR_UPDATE_STATEMENT, scope), init_(init), diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index 578a8b1e7883d21a2eeafba08f3a00431f5c3245..5eb8b27490ede291508d662466151fe01679f93d 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -15,8 +15,8 @@ #include "functionDeclaration.h" -#include "varbinder/variable.h" -#include "varbinder/scope.h" +#include "binder/variable.h" +#include "binder/scope.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index 91736420b75736618e78decbc7f615ace7edb5e9..b931fe18b8e94cd6a346990c5a22145b11176b11 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -72,7 +72,7 @@ void IfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const void IfStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const { - auto res = compiler::Condition::CheckConstantExpr(etsg, test_); + auto res = compiler::Condition::CheckConstantExpr(test_); if (res == compiler::Condition::Result::CONST_TRUE) { consequent_->Compile(etsg); diff --git a/ets2panda/ir/statements/loopStatement.cpp b/ets2panda/ir/statements/loopStatement.cpp index fc49dd6a7e00920a6a1f3fde3e9c126406ec41e6..4b547874af9f890240cc480a30346742e5945214 100644 --- a/ets2panda/ir/statements/loopStatement.cpp +++ b/ets2panda/ir/statements/loopStatement.cpp @@ -15,7 +15,7 @@ #include "loopStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" namespace panda::es2panda::ir { } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/loopStatement.h b/ets2panda/ir/statements/loopStatement.h index 469f163ef5a0f86621c05486178bf9903fd549e0..1bd9e38af3c26a6fc626d8fc8c100654578788ce 100644 --- a/ets2panda/ir/statements/loopStatement.h +++ b/ets2panda/ir/statements/loopStatement.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_STATEMENT_LOOP_STATEMENT_H #define ES2PANDA_IR_STATEMENT_LOOP_STATEMENT_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" namespace panda::es2panda::ir { @@ -27,7 +27,7 @@ public: return true; } - varbinder::LoopScope *Scope() const override + binder::LoopScope *Scope() const override { return scope_; } @@ -64,10 +64,10 @@ public: } protected: - explicit LoopStatement(AstNodeType type, varbinder::LoopScope *scope) : Statement(type), scope_(scope) {} + explicit LoopStatement(AstNodeType type, binder::LoopScope *scope) : Statement(type), scope_(scope) {} private: - varbinder::LoopScope *scope_; + binder::LoopScope *scope_; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/returnStatement.cpp b/ets2panda/ir/statements/returnStatement.cpp index 8e7f1dfc75630d34a148922143b73101b0a2a18b..b025e9f80d72585923613189269320de901f66b2 100644 --- a/ets2panda/ir/statements/returnStatement.cpp +++ b/ets2panda/ir/statements/returnStatement.cpp @@ -75,6 +75,7 @@ void ReturnStatement::SetReturnType(checker::ETSChecker *checker, checker::Type if (argument_type == nullptr) { checker->ThrowTypeError("Invalid return statement expression", argument_->Start()); } + // argument_->SetTsType(argument_type); argument_->AddBoxingUnboxingFlag(checker->GetBoxingFlag(argument_type)); relation->SetNode(nullptr); diff --git a/ets2panda/ir/statements/returnStatement.h b/ets2panda/ir/statements/returnStatement.h index cacaf713a77d7b33281721073dea6680f01c6cff..6d612b64a22d6af682b73facc5ff0dfbc84a06cf 100644 --- a/ets2panda/ir/statements/returnStatement.h +++ b/ets2panda/ir/statements/returnStatement.h @@ -32,7 +32,7 @@ public: explicit ReturnStatement() : ReturnStatement(nullptr) {} explicit ReturnStatement(Expression *argument) : Statement(AstNodeType::RETURN_STATEMENT), argument_(argument) {} - // NOTE: csabahurton. these friend relationships can be removed once there are getters for private fields + // TODO (csabahurton): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; diff --git a/ets2panda/ir/statements/switchStatement.cpp b/ets2panda/ir/statements/switchStatement.cpp index 4bc685e3b2ba20fc3c0f25c67c3d0a36e1eb8300..88b9b7151ca911fb29284b2b500c3481ce954a3d 100644 --- a/ets2panda/ir/statements/switchStatement.cpp +++ b/ets2panda/ir/statements/switchStatement.cpp @@ -15,7 +15,7 @@ #include "switchStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/core/labelTarget.h" #include "compiler/core/switchBuilder.h" #include "compiler/core/pandagen.h" @@ -134,7 +134,7 @@ checker::Type *SwitchStatement::Check(checker::ETSChecker *const checker) discriminant_->Check(checker); checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(checker->Relation(), checker::TypeRelationFlag::NONE); - // NOTE: check exhaustive Switch + // TODO(user): check exhaustive Switch checker->CheckSwitchDiscriminant(discriminant_); auto *compared_expr_type = discriminant_->TsType(); auto unboxed_disc_type = (Discriminant()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U diff --git a/ets2panda/ir/statements/switchStatement.h b/ets2panda/ir/statements/switchStatement.h index 70a0fab7466e5818c6861ecb5897de991b770dc2..847f426da372597214fb733e03ddabd5a05c4bac 100644 --- a/ets2panda/ir/statements/switchStatement.h +++ b/ets2panda/ir/statements/switchStatement.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_STATEMENT_SWITCH_STATEMENT_H #define ES2PANDA_IR_STATEMENT_SWITCH_STATEMENT_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" namespace panda::es2panda::ir { @@ -25,7 +25,7 @@ class SwitchCaseStatement; class SwitchStatement : public Statement { public: - explicit SwitchStatement(varbinder::LocalScope *scope, Expression *discriminant, + explicit SwitchStatement(binder::LocalScope *scope, Expression *discriminant, ArenaVector &&cases) : Statement(AstNodeType::SWITCH_STATEMENT), scope_(scope), discriminant_(discriminant), cases_(std::move(cases)) { @@ -46,7 +46,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -62,7 +62,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; Expression *discriminant_; ArenaVector cases_; }; diff --git a/ets2panda/ir/statements/tryStatement.h b/ets2panda/ir/statements/tryStatement.h index af69c1eb9d91f8f33a9ee79f4244c548b90e706b..74b955c87aca3f798585faf0c83457db28d74159 100644 --- a/ets2panda/ir/statements/tryStatement.h +++ b/ets2panda/ir/statements/tryStatement.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_STATEMENT_TRY_STATEMENT_H #define ES2PANDA_IR_STATEMENT_TRY_STATEMENT_H -#include "compiler/core/labelPair.h" +#include "compiler/core/ETSGen.h" #include "ir/statement.h" namespace panda::es2panda::compiler { diff --git a/ets2panda/ir/statements/variableDeclaration.cpp b/ets2panda/ir/statements/variableDeclaration.cpp index a8a79bc6d75392af96ed070c1f4b5b895c57d02a..79ced21cc653c268a13804cff7b0ca5ff85ef242 100644 --- a/ets2panda/ir/statements/variableDeclaration.cpp +++ b/ets2panda/ir/statements/variableDeclaration.cpp @@ -15,8 +15,8 @@ #include "variableDeclaration.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "ir/astDump.h" diff --git a/ets2panda/ir/statements/variableDeclarator.cpp b/ets2panda/ir/statements/variableDeclarator.cpp index 07e42b92209119afa39faac8605c4efae9ee9a09..7c2cf8a007b110e00acc45731dbef1744b0bd37a 100644 --- a/ets2panda/ir/statements/variableDeclarator.cpp +++ b/ets2panda/ir/statements/variableDeclarator.cpp @@ -15,7 +15,7 @@ #include "variableDeclarator.h" -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" @@ -80,7 +80,7 @@ void VariableDeclarator::Compile(compiler::ETSGen *etsg) const auto lref = compiler::ETSLReference::Create(etsg, id_, true); auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - if (id_->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::BOXED)) { + if (id_->AsIdentifier()->Variable()->HasFlag(binder::VariableFlags::BOXED)) { etsg->EmitLocalBoxCtor(id_); etsg->StoreAccumulator(this, lref.Variable()->AsLocalVariable()->Vreg()); } @@ -100,7 +100,7 @@ void VariableDeclarator::Compile(compiler::ETSGen *etsg) const static void CheckSimpleVariableDeclaration(checker::TSChecker *checker, ir::VariableDeclarator *declarator) { - varbinder::Variable *const binding_var = declarator->Id()->AsIdentifier()->Variable(); + binder::Variable *const binding_var = declarator->Id()->AsIdentifier()->Variable(); checker::Type *previous_type = binding_var->TsType(); auto *const type_annotation = declarator->Id()->AsIdentifier()->TypeAnnotation(); auto *const initializer = declarator->Init(); diff --git a/ets2panda/ir/statements/whileStatement.cpp b/ets2panda/ir/statements/whileStatement.cpp index 7accd4a83125afb9bf8a9d94db396cc4822dcc6d..ebfaa2a8c3a42018a2c5789414cc9acf5919d918 100644 --- a/ets2panda/ir/statements/whileStatement.cpp +++ b/ets2panda/ir/statements/whileStatement.cpp @@ -15,7 +15,7 @@ #include "whileStatement.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "compiler/base/condition.h" #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" diff --git a/ets2panda/ir/statements/whileStatement.h b/ets2panda/ir/statements/whileStatement.h index 465a5ecb82aadd604733265b76678f1d3979ed6d..7ecf3c147d7214204da0f3bbc973b8ff00b321b5 100644 --- a/ets2panda/ir/statements/whileStatement.h +++ b/ets2panda/ir/statements/whileStatement.h @@ -18,16 +18,16 @@ #include "ir/statements/loopStatement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class LoopScope; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Expression; class WhileStatement : public LoopStatement { public: - explicit WhileStatement(varbinder::LoopScope *scope, Expression *test, Statement *body) + explicit WhileStatement(binder::LoopScope *scope, Expression *test, Statement *body) : LoopStatement(AstNodeType::WHILE_STATEMENT, scope), test_(test), body_(body) { } diff --git a/ets2panda/ir/ts/tsAsExpression.cpp b/ets2panda/ir/ts/tsAsExpression.cpp index 052d2d6761a10beb9cba60382729e5eeba226e86..98823f75ad4181c5b073dfa02b24b613b1779685 100644 --- a/ets2panda/ir/ts/tsAsExpression.cpp +++ b/ets2panda/ir/ts/tsAsExpression.cpp @@ -15,10 +15,9 @@ #include "tsAsExpression.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/ets/castingContext.h" -#include "checker/types/ets/etsUnionType.h" #include "compiler/core/ETSGen.h" #include "ir/expressions/identifier.h" #include "ir/expressions/literal.h" @@ -59,7 +58,7 @@ void TSAsExpression::Dump(ir::AstDumper *dumper) const void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void TSAsExpression::Compile(compiler::ETSGen *etsg) const +void TSAsExpression::Compile(compiler::ETSGen *const etsg) const { if (!etsg->TryLoadConstantExpression(expression_)) { expression_->Compile(etsg); @@ -67,12 +66,7 @@ void TSAsExpression::Compile(compiler::ETSGen *etsg) const etsg->ApplyConversion(expression_, nullptr); - auto *target_type = TsType(); - if (target_type->IsETSUnionType()) { - target_type = target_type->AsETSUnionType()->FindTypeIsCastableToThis(expression_, etsg->Checker()->Relation(), - expression_->TsType()); - } - const auto target_type_kind = checker::ETSChecker::TypeKind(target_type); + const auto target_type_kind = checker::ETSChecker::TypeKind(TsType()); switch (target_type_kind) { case checker::TypeFlag::ETS_BOOLEAN: { etsg->CastToBoolean(this); @@ -109,7 +103,7 @@ void TSAsExpression::Compile(compiler::ETSGen *etsg) const case checker::TypeFlag::ETS_ARRAY: case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_DYNAMIC_TYPE: { - etsg->CastToArrayOrObject(this, target_type, is_unchecked_cast_); + etsg->CastToArrayOrObject(this, TsType(), is_unchecked_cast_); break; } case checker::TypeFlag::ETS_STRING_ENUM: @@ -215,7 +209,7 @@ checker::Type *TSAsExpression::Check(checker::ETSChecker *const checker) {"Cannot cast type '", source_type, "' to '", target_type, "'"}); if (source_type->IsETSDynamicType() && target_type->IsLambdaObject()) { - // NOTE: itrubachev. change target_type to created lambdaobject type. + // TODO(itrubachev) change target_type to created lambdaobject type. // Now target_type is not changed, only construct signature is added to it checker->BuildLambdaObjectClass(target_type->AsETSObjectType(), TypeAnnotation()->AsETSFunctionType()->ReturnType()); diff --git a/ets2panda/ir/ts/tsConstructorType.cpp b/ets2panda/ir/ts/tsConstructorType.cpp index 0b720e9834e9bb124e3bd731ce63d9bd67ff9c37..becd2bbb917b5af56476f22cd6f33bde2ca5dc2b 100644 --- a/ets2panda/ir/ts/tsConstructorType.cpp +++ b/ets2panda/ir/ts/tsConstructorType.cpp @@ -15,7 +15,7 @@ #include "tsConstructorType.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/types/signature.h" #include "ir/astDump.h" diff --git a/ets2panda/ir/ts/tsConstructorType.h b/ets2panda/ir/ts/tsConstructorType.h index c3e7d0e085b2b0e1e1b65d10c2b851d6ec9bfdca..2d84aebc7c89d8f90e8854c1a94d7f65acb3da75 100644 --- a/ets2panda/ir/ts/tsConstructorType.h +++ b/ets2panda/ir/ts/tsConstructorType.h @@ -23,7 +23,7 @@ class TSTypeParameterDeclaration; class TSConstructorType : public TypeNode { public: - explicit TSConstructorType(varbinder::Scope *scope, ArenaVector &¶ms, + explicit TSConstructorType(binder::Scope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, TypeNode *return_type, bool abstract) : TypeNode(AstNodeType::TS_CONSTRUCTOR_TYPE), scope_(scope), @@ -39,7 +39,7 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } @@ -73,7 +73,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; ArenaVector params_; TSTypeParameterDeclaration *type_params_; TypeNode *return_type_; diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index c1bb84f23b05aace5810caed65fa8ba22a0ed144..628d4914550b572d73bd97575e1e11764c9aacb1 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -15,7 +15,7 @@ #include "tsEnumDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "util/helpers.h" #include "ir/astDump.h" #include "ir/base/decorator.h" @@ -76,7 +76,7 @@ int32_t ToInt(double num) return static_cast(num); } - // NOTE: aszilagyi. Perform ECMA defined toInt conversion + // TODO(aszilagyi): Perform ECMA defined toInt conversion return 0; } @@ -87,13 +87,13 @@ uint32_t ToUInt(double num) return static_cast(num); } - // NOTE: aszilagyi. Perform ECMA defined toInt conversion + // TODO(aszilagyi): Perform ECMA defined toInt conversion return 0; } -varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::Identifier *expr) +binder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, binder::EnumVariable *enum_var, + const ir::Identifier *expr) { if (expr->Name() == "NaN") { return std::nan(""); @@ -102,7 +102,7 @@ varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varb return std::numeric_limits::infinity(); } - varbinder::Variable *enum_member = expr->AsIdentifier()->Variable(); + binder::Variable *enum_member = expr->AsIdentifier()->Variable(); if (enum_member == nullptr) { checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, @@ -110,7 +110,7 @@ varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varb } if (enum_member->IsEnumVariable()) { - varbinder::EnumVariable *expr_enum_var = enum_member->AsEnumVariable(); + binder::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, " @@ -125,10 +125,10 @@ varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varb return false; } -varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::UnaryExpression *expr) +binder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, binder::EnumVariable *enum_var, + const ir::UnaryExpression *expr) { - varbinder::EnumMemberResult value = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->Argument()); + binder::EnumMemberResult value = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->Argument()); if (!std::holds_alternative(value)) { return false; } @@ -151,9 +151,9 @@ varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, return false; } -varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker, - [[maybe_unused]] varbinder::EnumVariable *enum_var, - ir::MemberExpression *expr) +binder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker, + [[maybe_unused]] binder::EnumVariable *enum_var, + ir::MemberExpression *expr) { if (checker::TSChecker::IsConstantMemberAccess(expr->AsExpression())) { if (expr->Check(checker)->TypeFlags() == checker::TypeFlag::ENUM) { @@ -165,19 +165,19 @@ varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker name = reinterpret_cast(expr->Property())->Str(); } - // NOTE: aszilagyi. + // TODO(aszilagyi) } } return false; } -varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::BinaryExpression *expr) +binder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, binder::EnumVariable *enum_var, + const ir::BinaryExpression *expr) { - varbinder::EnumMemberResult left = + binder::EnumMemberResult left = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Left()); - varbinder::EnumMemberResult right = + binder::EnumMemberResult right = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Right()); if (std::holds_alternative(left) && std::holds_alternative(right)) { switch (expr->AsBinaryExpression()->OperatorType()) { @@ -237,9 +237,8 @@ varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker return false; } -varbinder::EnumMemberResult TSEnumDeclaration::EvaluateEnumMember(checker::TSChecker *checker, - varbinder::EnumVariable *enum_var, - const ir::AstNode *expr) +binder::EnumMemberResult TSEnumDeclaration::EvaluateEnumMember(checker::TSChecker *checker, + binder::EnumVariable *enum_var, const ir::AstNode *expr) { switch (expr->Type()) { case ir::AstNodeType::UNARY_EXPRESSION: { @@ -280,21 +279,21 @@ bool IsComputedEnumMember(const ir::Expression *init) return true; } -void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVariable *variable) +void AddEnumValueDeclaration(checker::TSChecker *checker, double number, binder::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; + binder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + binder::Variable *res = enum_scope->FindLocal(member_str); + binder::EnumVariable *enum_var = nullptr; if (res == nullptr) { - auto *decl = checker->Allocator()->New(member_str); + 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); + res = enum_scope->FindLocal(member_str); ASSERT(res && res->IsEnumVariable()); enum_var = res->AsEnumVariable(); enum_var->AsEnumVariable()->SetBackReference(); @@ -302,7 +301,7 @@ void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbind } else { ASSERT(res->IsEnumVariable()); enum_var = res->AsEnumVariable(); - auto *decl = checker->Allocator()->New(member_str); + auto *decl = checker->Allocator()->New(member_str); decl->BindNode(variable->Declaration()->Node()); enum_var->ResetDecl(decl); } @@ -310,9 +309,8 @@ void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbind 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) +void InferEnumVariableType(checker::TSChecker *checker, binder::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(); @@ -337,7 +335,7 @@ void InferEnumVariableType(checker::TSChecker *checker, varbinder::EnumVariable computed_expr = init; } - varbinder::EnumMemberResult res = TSEnumDeclaration::EvaluateEnumMember(checker, variable, init); + binder::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.", @@ -386,7 +384,7 @@ checker::Type *TSEnumDeclaration::InferType(checker::TSChecker *checker, bool is { double value = -1.0; - varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + binder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); bool init_next = false; bool is_literal_enum = false; @@ -395,8 +393,7 @@ checker::Type *TSEnumDeclaration::InferType(checker::TSChecker *checker, bool is 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); + binder::Variable *current_var = enum_scope->FindLocal(current_name); ASSERT(current_var && current_var->IsEnumVariable()); InferEnumVariableType(checker, current_var->AsEnumVariable(), &value, &init_next, &is_literal_enum, is_const, computed_expr); @@ -412,7 +409,7 @@ checker::Type *TSEnumDeclaration::InferType(checker::TSChecker *checker, bool is checker::Type *TSEnumDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) { - varbinder::Variable *enum_var = key_->Variable(); + binder::Variable *enum_var = key_->Variable(); ASSERT(enum_var); if (enum_var->TsType() == nullptr) { @@ -427,7 +424,7 @@ checker::Type *TSEnumDeclaration::Check([[maybe_unused]] checker::TSChecker *che checker::Type *TSEnumDeclaration::Check(checker::ETSChecker *const checker) { - varbinder::Variable *enum_var = key_->Variable(); + binder::Variable *enum_var = key_->Variable(); ASSERT(enum_var != nullptr); if (enum_var->TsType() == nullptr) { diff --git a/ets2panda/ir/ts/tsEnumDeclaration.h b/ets2panda/ir/ts/tsEnumDeclaration.h index 72a6d0870e70927c208743b2179173baf897b3e6..7661f213950e3f9d819dc497096eb8e2006ca26e 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.h +++ b/ets2panda/ir/ts/tsEnumDeclaration.h @@ -16,13 +16,13 @@ #ifndef ES2PANDA_IR_TS_ENUM_DECLARATION_H #define ES2PANDA_IR_TS_ENUM_DECLARATION_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" -#include "varbinder/enumMemberResult.h" +#include "binder/enumMemberResult.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class EnumVariable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Identifier; @@ -30,7 +30,7 @@ class TSEnumMember; class TSEnumDeclaration : public TypedStatement { public: - explicit TSEnumDeclaration(ArenaAllocator *allocator, varbinder::LocalScope *scope, Identifier *key, + explicit TSEnumDeclaration(ArenaAllocator *allocator, binder::LocalScope *scope, Identifier *key, ArenaVector &&members, bool is_const, bool is_static = false) : TypedStatement(AstNodeType::TS_ENUM_DECLARATION), scope_(scope), @@ -49,7 +49,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -99,8 +99,8 @@ public: return !in_ts; } - static varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, - varbinder::EnumVariable *enum_var, const ir::AstNode *expr); + static binder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, binder::EnumVariable *enum_var, + const ir::AstNode *expr); checker::Type *InferType(checker::TSChecker *checker, bool is_const) const; void TransformChildren(const NodeTransformer &cb) override; @@ -111,7 +111,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; ArenaVector decorators_; Identifier *key_; ArenaVector members_; diff --git a/ets2panda/ir/ts/tsFunctionType.cpp b/ets2panda/ir/ts/tsFunctionType.cpp index b58d0c2dcb746fe4f702e627028e5937234df5ac..9bee18d5db802e1d645cc3dedb5c5f66caf0475b 100644 --- a/ets2panda/ir/ts/tsFunctionType.cpp +++ b/ets2panda/ir/ts/tsFunctionType.cpp @@ -15,7 +15,7 @@ #include "tsFunctionType.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "checker/types/signature.h" diff --git a/ets2panda/ir/ts/tsFunctionType.h b/ets2panda/ir/ts/tsFunctionType.h index cebf62ad5f697a7db9c114de0ddb2b6d422b7c0e..8f8d3f16a69b8ff96c692a43886bb8a78b1db789 100644 --- a/ets2panda/ir/ts/tsFunctionType.h +++ b/ets2panda/ir/ts/tsFunctionType.h @@ -23,7 +23,7 @@ class TSTypeParameterDeclaration; class TSFunctionType : public TypeNode { public: - explicit TSFunctionType(varbinder::Scope *scope, ArenaVector &¶ms, + explicit TSFunctionType(binder::Scope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, TypeNode *return_type) : TypeNode(AstNodeType::TS_FUNCTION_TYPE), scope_(scope), @@ -38,7 +38,7 @@ public: return true; } - varbinder::Scope *Scope() const override + binder::Scope *Scope() const override { return scope_; } @@ -73,7 +73,7 @@ public: checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::Scope *scope_; + binder::Scope *scope_; ArenaVector params_; TSTypeParameterDeclaration *type_params_; TypeNode *return_type_; diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp index 3740664b32e6f4fac4323668bfee774085bc99af..aee881e77409ad3778b238721dd0da3736103fe9 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -15,9 +15,9 @@ #include "tsInterfaceDeclaration.h" -#include "varbinder/declaration.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/declaration.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "ir/astDump.h" @@ -99,7 +99,7 @@ void CheckInheritedPropertiesAreIdentical(checker::TSChecker *checker, checker:: for (auto *base : type->Bases()) { checker->ResolveStructuredTypeMembers(base); - ArenaVector inherited_properties(checker->Allocator()->Adapter()); + ArenaVector inherited_properties(checker->Allocator()->Adapter()); base->AsInterfaceType()->CollectProperties(&inherited_properties); for (auto *inherited_prop : inherited_properties) { @@ -120,7 +120,7 @@ void CheckInheritedPropertiesAreIdentical(checker::TSChecker *checker, checker:: checker::Type *TSInterfaceDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) { - varbinder::Variable *var = id_->Variable(); + binder::Variable *var = id_->Variable(); ASSERT(var->Declaration()->Node() && var->Declaration()->Node()->IsTSInterfaceDeclaration()); if (this == var->Declaration()->Node()) { diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.h b/ets2panda/ir/ts/tsInterfaceDeclaration.h index e209324087ebff6e72b4d94dd77acfee8c52eb2d..be5c2d258cb966ab756f82d7befe38a115db23fc 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.h +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.h @@ -16,13 +16,13 @@ #ifndef ES2PANDA_IR_TS_INTERFACE_DECLARATION_H #define ES2PANDA_IR_TS_INTERFACE_DECLARATION_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" #include "util/language.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Identifier; @@ -32,7 +32,7 @@ class TSTypeParameterDeclaration; class TSInterfaceDeclaration : public TypedStatement { public: - explicit TSInterfaceDeclaration(ArenaAllocator *allocator, varbinder::LocalScope *scope, Identifier *id, + explicit TSInterfaceDeclaration(ArenaAllocator *allocator, binder::LocalScope *scope, Identifier *id, TSTypeParameterDeclaration *type_params, TSInterfaceBody *body, ArenaVector &&extends, bool is_static, Language lang) : TypedStatement(AstNodeType::TS_INTERFACE_DECLARATION), @@ -55,7 +55,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -142,11 +142,11 @@ public: 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; - checker::Type *InferType(checker::TSChecker *checker, varbinder::Variable *binding_var) const; + checker::Type *InferType(checker::TSChecker *checker, binder::Variable *binding_var) const; private: ArenaVector decorators_; - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; Identifier *id_; TSTypeParameterDeclaration *type_params_; TSInterfaceBody *body_; diff --git a/ets2panda/ir/ts/tsInterfaceHeritage.cpp b/ets2panda/ir/ts/tsInterfaceHeritage.cpp index fe81446c5cf6e7273f6e45febf853ef16a75a009..19e92cbdc8ee8a07da21f8e09da820fe4342dc89 100644 --- a/ets2panda/ir/ts/tsInterfaceHeritage.cpp +++ b/ets2panda/ir/ts/tsInterfaceHeritage.cpp @@ -15,7 +15,7 @@ #include "tsInterfaceHeritage.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/expressions/identifier.h" diff --git a/ets2panda/ir/ts/tsIntersectionType.cpp b/ets2panda/ir/ts/tsIntersectionType.cpp index 2e96dbb3fffee08d5a902213a6c4c311b662543d..4acbc734d18597e926e3f113cd0000df05624b8f 100644 --- a/ets2panda/ir/ts/tsIntersectionType.cpp +++ b/ets2panda/ir/ts/tsIntersectionType.cpp @@ -52,7 +52,7 @@ checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::TSChecker * checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::ETSChecker *checker) { - // NOTE: validate + // TODO(): validate return checker->GlobalETSObjectType(); } diff --git a/ets2panda/ir/ts/tsModuleBlock.cpp b/ets2panda/ir/ts/tsModuleBlock.cpp index 9c7b5a802983ce8b999ff0ffc33be970ed2f08aa..4715d9bf3feac1e2bd876e5e0257a82304363d5d 100644 --- a/ets2panda/ir/ts/tsModuleBlock.cpp +++ b/ets2panda/ir/ts/tsModuleBlock.cpp @@ -15,7 +15,7 @@ #include "tsModuleBlock.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/astDump.h" namespace panda::es2panda::ir { diff --git a/ets2panda/ir/ts/tsModuleBlock.h b/ets2panda/ir/ts/tsModuleBlock.h index 8154d30a82e187972d685df1cd8462ad02202d24..66c99a269f782bf1ea220a0197de60436258c543 100644 --- a/ets2panda/ir/ts/tsModuleBlock.h +++ b/ets2panda/ir/ts/tsModuleBlock.h @@ -16,13 +16,13 @@ #ifndef ES2PANDA_IR_TS_MODULE_BLOCK_H #define ES2PANDA_IR_TS_MODULE_BLOCK_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" namespace panda::es2panda::ir { class TSModuleBlock : public Statement { public: - explicit TSModuleBlock(varbinder::LocalScope *scope, ArenaVector &&statements) + explicit TSModuleBlock(binder::LocalScope *scope, ArenaVector &&statements) : Statement(AstNodeType::TS_MODULE_BLOCK), scope_(scope), statements_(std::move(statements)) { } @@ -32,7 +32,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -50,7 +50,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; ArenaVector statements_; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsModuleDeclaration.cpp b/ets2panda/ir/ts/tsModuleDeclaration.cpp index bc8abb3a0cf3d338c3934fd73af2b133fbeadaa1..beb7f336171cc024b9f0e88714294f0c581ad863 100644 --- a/ets2panda/ir/ts/tsModuleDeclaration.cpp +++ b/ets2panda/ir/ts/tsModuleDeclaration.cpp @@ -15,7 +15,7 @@ #include "tsModuleDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/astDump.h" #include "ir/base/decorator.h" #include "ir/expression.h" diff --git a/ets2panda/ir/ts/tsModuleDeclaration.h b/ets2panda/ir/ts/tsModuleDeclaration.h index e8f28c207fb66db398e1ccccea8005bf81ebf4a1..e29019df0dd134f0b968517f2abdfb47640faf51 100644 --- a/ets2panda/ir/ts/tsModuleDeclaration.h +++ b/ets2panda/ir/ts/tsModuleDeclaration.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_TS_MODULE_DECLARATION_H #define ES2PANDA_IR_TS_MODULE_DECLARATION_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/statement.h" namespace panda::es2panda::ir { @@ -24,7 +24,7 @@ class Expression; class TSModuleDeclaration : public Statement { public: - explicit TSModuleDeclaration(ArenaAllocator *allocator, varbinder::LocalScope *scope, Expression *name, + explicit TSModuleDeclaration(ArenaAllocator *allocator, binder::LocalScope *scope, Expression *name, Statement *body, bool declare, bool global) : Statement(AstNodeType::TS_MODULE_DECLARATION), decorators_(allocator->Adapter()), @@ -41,7 +41,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -85,7 +85,7 @@ public: private: ArenaVector decorators_; - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; Expression *name_; Statement *body_; bool declare_; diff --git a/ets2panda/ir/ts/tsQualifiedName.cpp b/ets2panda/ir/ts/tsQualifiedName.cpp index cf72fa5f727e7be2f033ac105acb73b86c2836a7..0c1d5d4307dffa4cddeb88934562a1b89debb0a2 100644 --- a/ets2panda/ir/ts/tsQualifiedName.cpp +++ b/ets2panda/ir/ts/tsQualifiedName.cpp @@ -43,7 +43,7 @@ void TSQualifiedName::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} checker::Type *TSQualifiedName::Check([[maybe_unused]] checker::TSChecker *checker) { checker::Type *base_type = checker->CheckNonNullType(left_->Check(checker), left_->Start()); - varbinder::Variable *prop = checker->GetPropertyOfType(base_type, right_->Name()); + binder::Variable *prop = checker->GetPropertyOfType(base_type, right_->Name()); if (prop != nullptr) { return checker->GetTypeOfVariable(prop); @@ -65,7 +65,7 @@ checker::Type *TSQualifiedName::Check(checker::ETSChecker *checker) { checker::Type *base_type = left_->Check(checker); if (base_type->IsETSObjectType()) { - varbinder::Variable *prop = + binder::Variable *prop = base_type->AsETSObjectType()->GetProperty(right_->Name(), checker::PropertySearchFlags::SEARCH_DECL); if (prop != nullptr) { diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index ac326b46595d7ff437e9aa4800465bbfb93fc519..6eebdc76a0c6dcd6078e364b485d21b54388223b 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -16,7 +16,7 @@ #include "tsTupleType.h" #include "util/helpers.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "checker/types/ts/indexInfo.h" #include "ir/astDump.h" @@ -62,7 +62,7 @@ checker::Type *TSTupleType::GetType(checker::TSChecker *checker) util::StringView member_index = util::Helpers::ToStringView(checker->Allocator(), index); auto *member_var = - varbinder::Scope::CreateVar(checker->Allocator(), member_index, varbinder::VariableFlags::PROPERTY, it); + binder::Scope::CreateVar(checker->Allocator(), member_index, binder::VariableFlags::PROPERTY, it); checker::ElementFlags member_flag = checker::ElementFlags::NO_OPTS; if (it->IsTSNamedTupleMember()) { @@ -70,7 +70,7 @@ checker::Type *TSTupleType::GetType(checker::TSChecker *checker) checker::Type *member_type = named_member->ElementType()->GetType(checker); if (named_member->IsOptional()) { - member_var->AddFlag(varbinder::VariableFlags::OPTIONAL); + member_var->AddFlag(binder::VariableFlags::OPTIONAL); member_flag = checker::ElementFlags::OPTIONAL; } else { member_flag = checker::ElementFlags::REQUIRED; diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp index 52028ef4fb687df6365785a0bb53b093e958ced6..d08e3640552262ae13dbc6578f85bcabbb805a89 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -15,7 +15,7 @@ #include "tsTypeAliasDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/typeNode.h" diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.h b/ets2panda/ir/ts/tsTypeAliasDeclaration.h index 5dc000528a098a4fca951d7e7431644d01f39082..f38a2cb58c7d4c4a76954f37695eb08a9546952b 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.h +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.h @@ -18,9 +18,9 @@ #include "ir/statement.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class Identifier; diff --git a/ets2panda/ir/ts/tsTypeLiteral.cpp b/ets2panda/ir/ts/tsTypeLiteral.cpp index 48fdf07d8633f6b9a13e972b5d695efcee0a6810..17838b7a0c1b6263a155106bda4ce93dec743f6b 100644 --- a/ets2panda/ir/ts/tsTypeLiteral.cpp +++ b/ets2panda/ir/ts/tsTypeLiteral.cpp @@ -17,8 +17,8 @@ #include "ir/astDump.h" -#include "varbinder/variable.h" -#include "varbinder/declaration.h" +#include "binder/variable.h" +#include "binder/declaration.h" #include "checker/TSchecker.h" #include "checker/types/signature.h" diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp index a84b6d16cb7a6a8f6c21be72ea6df82aad1978aa..4039d1f16aba424b5392f040887da1fbe7ee4ce4 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -15,7 +15,7 @@ #include "tsTypeParameterDeclaration.h" -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/astDump.h" #include "ir/ts/tsTypeParameter.h" diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.h b/ets2panda/ir/ts/tsTypeParameterDeclaration.h index 6e203679adc7e041816cf6af1c97fc13b9de56f3..d5c5b926ad6ec2d2b71165e1ecf5cec73c0b1f57 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_IR_TS_TYPE_PARAMETER_DECLARATION_H #define ES2PANDA_IR_TS_TYPE_PARAMETER_DECLARATION_H -#include "varbinder/scope.h" +#include "binder/scope.h" #include "ir/expression.h" namespace panda::es2panda::ir { @@ -24,7 +24,7 @@ class TSTypeParameter; class TSTypeParameterDeclaration : public Expression { public: - explicit TSTypeParameterDeclaration(varbinder::LocalScope *scope, ArenaVector &¶ms, + explicit TSTypeParameterDeclaration(binder::LocalScope *scope, ArenaVector &¶ms, size_t required_params) : Expression(AstNodeType::TS_TYPE_PARAMETER_DECLARATION), scope_(scope), @@ -38,7 +38,7 @@ public: return true; } - varbinder::LocalScope *Scope() const override + binder::LocalScope *Scope() const override { return scope_; } @@ -61,7 +61,7 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: - varbinder::LocalScope *scope_; + binder::LocalScope *scope_; ArenaVector params_; size_t required_params_; }; diff --git a/ets2panda/ir/ts/tsTypeReference.cpp b/ets2panda/ir/ts/tsTypeReference.cpp index df1c13a9c392748f8e7f154a71ad92cf1ad06ecb..a1ccefd3968dc4bda2262c75d8d246c9bcdea35a 100644 --- a/ets2panda/ir/ts/tsTypeReference.cpp +++ b/ets2panda/ir/ts/tsTypeReference.cpp @@ -15,9 +15,9 @@ #include "tsTypeReference.h" -#include "varbinder/declaration.h" -#include "varbinder/scope.h" -#include "varbinder/variable.h" +#include "binder/declaration.h" +#include "binder/scope.h" +#include "binder/variable.h" #include "checker/TSchecker.h" #include "ir/astDump.h" #include "ir/expressions/identifier.h" @@ -86,7 +86,7 @@ checker::Type *TSTypeReference::GetType([[maybe_unused]] checker::TSChecker *che } ASSERT(type_name_->IsIdentifier()); - varbinder::Variable *var = type_name_->AsIdentifier()->Variable(); + binder::Variable *var = type_name_->AsIdentifier()->Variable(); if (var == nullptr) { checker->ThrowTypeError({"Cannot find name ", type_name_->AsIdentifier()->Name()}, Start()); diff --git a/ets2panda/ir/ts/tsTypeReference.h b/ets2panda/ir/ts/tsTypeReference.h index 2f96fd8a6bb3875eb72a5f7a7d91e7a6440f5e3f..29c745bb74511f99403454315fa4fc6e02c1cb7e 100644 --- a/ets2panda/ir/ts/tsTypeReference.h +++ b/ets2panda/ir/ts/tsTypeReference.h @@ -18,9 +18,9 @@ #include "ir/typeNode.h" -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::ir { class TSTypeParameterInstantiation; diff --git a/ets2panda/ir/ts/tsUnionType.cpp b/ets2panda/ir/ts/tsUnionType.cpp index 6a55683ea6a051026af1846a669efbd3171eb8f2..c833b7f5b2858830ac29e5328676775c9235fa42 100644 --- a/ets2panda/ir/ts/tsUnionType.cpp +++ b/ets2panda/ir/ts/tsUnionType.cpp @@ -50,11 +50,6 @@ checker::Type *TSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) return nullptr; } -checker::Type *TSUnionType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return nullptr; -} - checker::Type *TSUnionType::GetType(checker::TSChecker *checker) { if (TsType() != nullptr) { @@ -70,4 +65,9 @@ checker::Type *TSUnionType::GetType(checker::TSChecker *checker) SetTsType(checker->CreateUnionType(std::move(types))); return TsType(); } + +checker::Type *TSUnionType::Check([[maybe_unused]] checker::ETSChecker *checker) +{ + return nullptr; +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnionType.h b/ets2panda/ir/ts/tsUnionType.h index feaa03b28268044c85a438751015bda6aded7c34..65343e59e6483344f321f2c9c7d59ffed59f63c7 100644 --- a/ets2panda/ir/ts/tsUnionType.h +++ b/ets2panda/ir/ts/tsUnionType.h @@ -36,8 +36,8 @@ public: 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; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; private: ArenaVector types_; diff --git a/ets2panda/lexer/ASLexer.cpp b/ets2panda/lexer/ASLexer.cpp index 188161e89b4a1ac400d5d3a72ef30b0852113f0c..4b97ca7f17a3e7b117f661786ae664278376eb7a 100644 --- a/ets2panda/lexer/ASLexer.cpp +++ b/ets2panda/lexer/ASLexer.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/ASLexer.h b/ets2panda/lexer/ASLexer.h index 6fe3ec048afbb67bdec5bf014cdfac416f65b910..de0e800cd4999a6de8ade4252770264a0e705810 100644 --- a/ets2panda/lexer/ASLexer.h +++ b/ets2panda/lexer/ASLexer.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/ETSLexer.cpp b/ets2panda/lexer/ETSLexer.cpp index 935daba8028c3c453b7379daff0c8e805d0d97a0..562aff1cf0b0efde73e3336d82f37ae9e00742ae 100644 --- a/ets2panda/lexer/ETSLexer.cpp +++ b/ets2panda/lexer/ETSLexer.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. @@ -81,19 +81,7 @@ void ETSLexer::CheckUtf16Compatible(char32_t cp) const void ETSLexer::SkipMultiLineComment() { - uint32_t depth = 1U; - - // Just to reduce extra nested level(s) - auto const check_asterisk = [this, &depth]() -> bool { - if (Iterator().Peek() == LEX_CHAR_SLASH) { - Iterator().Forward(1); - - if (--depth == 0U) { - return false; - } - } - return true; - }; + uint32_t depth = 1; while (true) { switch (Iterator().Next()) { @@ -109,8 +97,12 @@ void ETSLexer::SkipMultiLineComment() continue; } case LEX_CHAR_ASTERISK: { - if (!check_asterisk()) { - return; + if (Iterator().Peek() == LEX_CHAR_SLASH) { + Iterator().Forward(1); + + if (--depth == 0) { + return; + } } break; } diff --git a/ets2panda/lexer/ETSLexer.h b/ets2panda/lexer/ETSLexer.h index 32a4c4147ad7b452abb49ee5e4f2c6e00af4d4a6..55b860374218246c4c02c03a82236f4894c18039 100644 --- a/ets2panda/lexer/ETSLexer.h +++ b/ets2panda/lexer/ETSLexer.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/TSLexer.cpp b/ets2panda/lexer/TSLexer.cpp index c2f3cc5cf0d7b85f964d44566bcb23c3ed35e2de..b29bd9dbb40e9a1925b36d17758a11f683859fed 100644 --- a/ets2panda/lexer/TSLexer.cpp +++ b/ets2panda/lexer/TSLexer.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/TSLexer.h b/ets2panda/lexer/TSLexer.h index b4c1aa307da2fd0f5f697ec0c0a7d83b8b23f2c8..2c729f2a594482fbe10d1fdf8c41d990ae9031f3 100644 --- a/ets2panda/lexer/TSLexer.h +++ b/ets2panda/lexer/TSLexer.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/keywords.cpp b/ets2panda/lexer/keywords.cpp index c5ea702c238f120d93e62ea512b3685cd5bf9095..644732012505f7ff065925d498912d1f97879476 100644 --- a/ets2panda/lexer/keywords.cpp +++ b/ets2panda/lexer/keywords.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/lexer/keywordsBase.h b/ets2panda/lexer/keywordsBase.h index a7d1d0f4764d6a60dba4530d69cfe04cfcbfdabd..f601167e8dbd45b699ebe0c03fab36b1d5b089f0 100644 --- a/ets2panda/lexer/keywordsBase.h +++ b/ets2panda/lexer/keywordsBase.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021 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. diff --git a/ets2panda/lexer/keywordsUtil.cpp b/ets2panda/lexer/keywordsUtil.cpp index 9daadafb8513417253666300c424d1da72928251..1f6013579e2db0a9abb70f02b6967dc6959e96b2 100644 --- a/ets2panda/lexer/keywordsUtil.cpp +++ b/ets2panda/lexer/keywordsUtil.cpp @@ -215,7 +215,7 @@ void KeywordsUtil::ScanIdContinue() auto escape_end = start_pos; - while (true) { + do { if (Iterator().Peek() == LEX_CHAR_BACKSLASH) { ident.Append(lexer_->SourceView(escape_end, Iterator().Index())); @@ -236,7 +236,7 @@ void KeywordsUtil::ScanIdContinue() } Iterator().Forward(cp_size); - } + } while (true); lexer_->GetToken().type_ = TokenType::LITERAL_IDENT; lexer_->GetToken().keyword_type_ = TokenType::LITERAL_IDENT; @@ -278,7 +278,7 @@ void KeywordsUtil::ScanIdContinueMaybeKeyword(const Keywords *kws, Span= end) { return; diff --git a/ets2panda/lexer/lexer.cpp b/ets2panda/lexer/lexer.cpp index 0b26a83a572ab5f91fd822575265418f1b88cc2b..b31c00f28a8258bf678a81e3c5814c445761e2db 100644 --- a/ets2panda/lexer/lexer.cpp +++ b/ets2panda/lexer/lexer.cpp @@ -265,7 +265,7 @@ void Lexer::ScanDecimalNumbers() } GetToken().flags_ |= TokenFlags::NUMBER_HAS_UNDERSCORE; - Iterator().Forward(2U); + Iterator().Forward(2); allow_numeric_on_next = false; break; } @@ -410,19 +410,7 @@ void Lexer::ScanTemplateStringEnd() LexerTemplateString Lexer::ScanTemplateString() { LexerTemplateString template_str(Allocator()); - size_t cp_size = 0U; - - auto const check_octal_digit = [this](char32_t const next_cp) -> void { - if (IsOctalDigit(next_cp)) { - Iterator().Forward(1); - - if (Iterator().Peek() != LEX_CHAR_BACK_TICK) { - ThrowError("Octal escape sequences are not allowed in template strings"); - } - - Iterator().Backward(1); - } - }; + size_t cp_size = 0; while (true) { char32_t cp = Iterator().PeekCp(&cp_size); @@ -455,7 +443,15 @@ LexerTemplateString Lexer::ScanTemplateString() Iterator().Forward(1); char32_t next_cp = Iterator().Peek(); - check_octal_digit(next_cp); + if (IsOctalDigit(next_cp)) { + Iterator().Forward(1); + + if (Iterator().Peek() != LEX_CHAR_BACK_TICK) { + ThrowError("Octal escape sequences are not allowed in template strings"); + } + + Iterator().Backward(1); + } if (next_cp == LEX_CHAR_BACK_TICK || next_cp == LEX_CHAR_BACKSLASH) { template_str.str.Append(cp); @@ -560,7 +556,7 @@ char32_t Lexer::ScanUnicodeCharacter() } case LEX_CHAR_LOWERCASE_X: { Iterator().Forward(1); - cp = ScanHexEscape<2U>(); + cp = ScanHexEscape<2>(); return cp; } case LEX_CHAR_LOWERCASE_U: { @@ -1507,32 +1503,6 @@ void Lexer::NextToken(Keywords *kws) SkipWhiteSpaces(); } -void Lexer::ScanNumberLeadingZeroImplNonAllowedCases() -{ - switch (Iterator().Peek()) { - case LEX_CHAR_0: - case LEX_CHAR_1: - case LEX_CHAR_2: - case LEX_CHAR_3: - case LEX_CHAR_4: - case LEX_CHAR_5: - case LEX_CHAR_6: - case LEX_CHAR_7: { - ThrowError("Implicit octal literal not allowed"); - } - case LEX_CHAR_8: - case LEX_CHAR_9: { - ThrowError("NonOctalDecimalIntegerLiteral is not enabled in strict mode code"); - } - case LEX_CHAR_UNDERSCORE: { - ThrowError("Numeric separator '_' is not allowed in numbers that start with '0'."); - } - default: { - break; - } - } -} - LexerPosition &Lexer::Pos() { return pos_; diff --git a/ets2panda/lexer/lexer.h b/ets2panda/lexer/lexer.h index 2a36059a2b794a8adc91a9e1157818af3cdaa925..65951cee7e10b8f1186c9814257075e926fca4be 100644 --- a/ets2panda/lexer/lexer.h +++ b/ets2panda/lexer/lexer.h @@ -257,12 +257,9 @@ protected: template void ScanNumberLeadingZeroImpl(); - void ScanNumberLeadingZeroImplNonAllowedCases(); template void ScanNumberRadix(bool allow_numeric_separator = true); void ScanNumber(bool allow_big_int = true); - template - void ScanTooLargeNumber(RadixType number); virtual void ConvertNumber(const std::string &utf8, NumberFlags flags); void ScanDecimalLiteral(); void ScanDecimalDigits(bool allow_numeric_separator); @@ -480,8 +477,24 @@ void Lexer::ScanNumberLeadingZeroImpl() CheckNumberLiteralEnd(); return; } + case LEX_CHAR_0: + case LEX_CHAR_1: + case LEX_CHAR_2: + case LEX_CHAR_3: + case LEX_CHAR_4: + case LEX_CHAR_5: + case LEX_CHAR_6: + case LEX_CHAR_7: { + ThrowError("Implicit octal literal not allowed"); + } + case LEX_CHAR_8: + case LEX_CHAR_9: { + ThrowError("NonOctalDecimalIntegerLiteral is not enabled in strict mode code"); + } + case LEX_CHAR_UNDERSCORE: { + ThrowError("Numeric separator '_' is not allowed in numbers that start with '0'."); + } default: { - ScanNumberLeadingZeroImplNonAllowedCases(); break; } } @@ -489,16 +502,6 @@ void Lexer::ScanNumberLeadingZeroImpl() ScanNumber(); } -template -void Lexer::ScanTooLargeNumber([[maybe_unused]] RadixType number) -{ - if constexpr (std::is_arithmetic_v) { - if (number > std::numeric_limits::max() / RADIX) { - ThrowError("Number is too large"); - } - } -} - template void Lexer::ScanNumberRadix(bool allow_numeric_separator) { @@ -516,7 +519,11 @@ void Lexer::ScanNumberRadix(bool allow_numeric_separator) if (RANGE_CHECK(cp)) { auto digit = HexValue(cp); - ScanTooLargeNumber(number); + if constexpr (std::is_arithmetic_v) { + if (number > std::numeric_limits::max() / RADIX) { + ThrowError("Number is too large"); + } + } number = number * RADIX + digit; Iterator().Forward(1); diff --git a/ets2panda/lexer/regexp/regexp.cpp b/ets2panda/lexer/regexp/regexp.cpp index a2e1af635ba8093a75c643a589398b33b986719b..1febe12059d19f458accb93e374eb295244595f0 100644 --- a/ets2panda/lexer/regexp/regexp.cpp +++ b/ets2panda/lexer/regexp/regexp.cpp @@ -572,7 +572,7 @@ uint32_t RegExpParser::ParseLegacyOctalEscape() return octal_value; } - octal_value = octal_value * 8U + DigitValue(Next()); + octal_value = octal_value * 8 + DigitValue(Next()); if (!IsOctalDigit(Peek())) { return octal_value; @@ -653,18 +653,18 @@ uint32_t RegExpParser::ParseUnicodeEscape() Next(); } else { value = ParseUnicodeDigits(); - if (!util::StringView::IsHighSurrogate(value)) { - return value; - } + if (util::StringView::IsHighSurrogate(value)) { + auto pos = iter_; - auto pos = iter_; - if (Next() == LEX_CHAR_BACKSLASH && Next() == LEX_CHAR_LOWERCASE_U) { - uint32_t next = ParseUnicodeDigits(); - if (util::StringView::IsLowSurrogate(next)) { - return util::StringView::DecodeSurrogates(value, next); + if (Next() == LEX_CHAR_BACKSLASH && Next() == LEX_CHAR_LOWERCASE_U) { + uint32_t next = ParseUnicodeDigits(); + if (util::StringView::IsLowSurrogate(next)) { + return util::StringView::DecodeSurrogates(value, next); + } } + + iter_ = pos; } - iter_ = pos; } return value; @@ -692,7 +692,7 @@ void RegExpParser::ParseUnicodePropertyEscape() break; } - /* NOTE: Parse and validate Unicode property names */ + /* TODO(dbatyai): Parse and validate Unicode property names */ } } diff --git a/ets2panda/lexer/token/number.cpp b/ets2panda/lexer/token/number.cpp index 3cbb8bc542581699dac8f4751376cbb9e96fd8d7..3a91ee864a025c6cae5b8431fe90d52c3a6daf9a 100644 --- a/ets2panda/lexer/token/number.cpp +++ b/ets2panda/lexer/token/number.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/lexer/token/number.h b/ets2panda/lexer/token/number.h index 840285f60c8f6bfe8b9da01532b1a005bbe70685..4ea4a7f52ce6d4a75dd933c97a15eb87823fc0fc 100644 --- a/ets2panda/lexer/token/number.h +++ b/ets2panda/lexer/token/number.h @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/parser/ASparser.cpp b/ets2panda/parser/ASparser.cpp index 76c303061c3079b5dba668324850b34d116c91e0..dc50f020435f33ec5d12e78e86c95a6afc2bd188 100644 --- a/ets2panda/parser/ASparser.cpp +++ b/ets2panda/parser/ASparser.cpp @@ -16,9 +16,9 @@ #include "ASparser.h" #include "util/helpers.h" -#include "varbinder/privateBinding.h" -#include "varbinder/scope.h" -#include "varbinder/tsBinding.h" +#include "binder/privateBinding.h" +#include "binder/scope.h" +#include "binder/tsBinding.h" #include "lexer/ASLexer.h" #include "ir/base/decorator.h" #include "ir/base/property.h" @@ -121,14 +121,14 @@ ir::TSTypeAliasDeclaration *ASParser::ParseTypeAliasDeclaration() } const util::StringView &ident = Lexer()->GetToken().Ident(); - varbinder::TSBinding ts_binding(Allocator(), ident); - auto *decl = VarBinder()->AddTsDecl(Lexer()->GetToken().Start(), ts_binding.View()); + binder::TSBinding ts_binding(Allocator(), ident); + auto *decl = Binder()->AddTsDecl(Lexer()->GetToken().Start(), ts_binding.View()); auto *id = AllocNode(ident, Allocator()); id->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -270,7 +270,7 @@ ParserStatus ASParser::ValidateArrowParameter(ir::Expression *expr, bool *seen_o } ArrowFunctionDescriptor ASParser::ConvertToArrowParameter(ir::Expression *expr, bool is_async, - varbinder::FunctionParamScope *param_scope) + binder::FunctionParamScope *param_scope) { auto arrow_status = is_async ? ParserStatus::ASYNC_FUNCTION : ParserStatus::NO_OPTS; ArenaVector params(Allocator()->Adapter()); @@ -320,7 +320,7 @@ ArrowFunctionDescriptor ASParser::ConvertToArrowParameter(ir::Expression *expr, } for (auto *param : params) { - VarBinder()->AddParamDecl(param); + Binder()->AddParamDecl(param); } return ArrowFunctionDescriptor {std::move(params), param_scope, expr->Start(), arrow_status}; @@ -491,7 +491,7 @@ bool ASParser::CurrentIsBasicType() ir::TypeNode *ASParser::ParseFunctionType(lexer::SourcePosition start_loc) { - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -1021,7 +1021,7 @@ ir::AstNode *ASParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { @@ -1029,7 +1029,7 @@ ir::AstNode *ASParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio type_param_decl = ParseTypeParameterDeclaration(&options); } - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -1327,7 +1327,7 @@ std::tuple ASParser::ParseComputedClassFieldOrIndexSignature(i std::tuple ASParser::ParseFunctionBody( [[maybe_unused]] const ArenaVector ¶ms, [[maybe_unused]] ParserStatus new_status, - ParserStatus context_status, varbinder::FunctionScope *func_scope) + ParserStatus context_status, binder::FunctionScope *func_scope) { bool is_declare = InAmbientContext(); bool is_overload = false; @@ -1540,7 +1540,7 @@ ir::ExportDefaultDeclaration *ASParser::ParseExportDefaultDeclaration(const lexe ir::AstNode *decl_node = nullptr; bool eat_semicolon = false; - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (Lexer()->GetToken().Type()) { case lexer::TokenType::KEYW_FUNCTION: { @@ -1607,7 +1607,7 @@ ir::ExportNamedDeclaration *ASParser::ParseNamedExportDeclaration(const lexer::S flags |= ir::ModifierFlags::ABSTRACT; } - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (Lexer()->GetToken().KeywordType()) { case lexer::TokenType::KEYW_VAR: { @@ -1690,7 +1690,7 @@ ir::AstNode *ASParser::ParseImportSpecifiers(ArenaVector *specifi ir::Statement *ASParser::ParseImportDeclaration([[maybe_unused]] StatementParsingFlags flags) { - ImportDeclarationContext import_ctx(VarBinder()); + ImportDeclarationContext import_ctx(Binder()); char32_t next_char = Lexer()->Lookahead(); if (next_char == lexer::LEX_CHAR_LEFT_PAREN || next_char == lexer::LEX_CHAR_DOT) { diff --git a/ets2panda/parser/ASparser.h b/ets2panda/parser/ASparser.h index aec8632ee20c916c11b0fa9fea9d40b4c7834cca..bf52ca32dc8f2f347a4a146fa01a6c72716a20c0 100644 --- a/ets2panda/parser/ASparser.h +++ b/ets2panda/parser/ASparser.h @@ -72,7 +72,7 @@ private: std::tuple ParseComputedClassFieldOrIndexSignature(ir::Expression **prop_name) override; std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, - varbinder::FunctionScope *func_scope) override; + binder::FunctionScope *func_scope) override; ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers) override; std::tuple ParseInterfacePropertyKey() override; ir::Expression *ParseCoverParenthesizedExpressionAndArrowParameterList() override; @@ -91,7 +91,7 @@ private: void ParseOptionalClassElement(ClassElementDescriptor *desc) override; void ValidateIndexSignatureTypeAnnotation(ir::TypeNode *type_annotation) override; ArrowFunctionDescriptor ConvertToArrowParameter(ir::Expression *expr, bool is_async, - varbinder::FunctionParamScope *param_scope) override; + binder::FunctionParamScope *param_scope) override; ParserStatus ValidateArrowParameter(ir::Expression *expr, bool *seen_optional) override; void ThrowIllegalBreakError() override; void ThrowIllegalContinueError() override; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 736173af5a6ed0d3feb07fc69f0cef8a06e35907..bccc01c60a7dcc0bb5a8881908654e9ad0fc4ca9 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -19,10 +19,10 @@ #include "util/arktsconfig.h" #include "util/helpers.h" #include "util/language.h" -#include "varbinder/varbinder.h" -#include "varbinder/privateBinding.h" -#include "varbinder/scope.h" -#include "varbinder/ETSBinder.h" +#include "binder/binder.h" +#include "binder/privateBinding.h" +#include "binder/scope.h" +#include "binder/ETSBinder.h" #include "lexer/lexer.h" #include "lexer/ETSLexer.h" #include "checker/types/ets/etsEnumType.h" @@ -91,7 +91,6 @@ #include "ir/ets/etsScript.h" #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsUnionType.h" #include "ir/ets/etsImportSource.h" #include "ir/ets/etsImportDeclaration.h" #include "ir/ets/etsStructDeclaration.h" @@ -179,9 +178,8 @@ void ETSParser::ParseETSGlobalScript(lexer::SourcePosition start_loc, ArenaVecto ParseSources(paths, false); ParseTopLevelDeclaration(statements); - auto *ets_script = - AllocNode(Allocator(), VarBinder()->GetScope(), std::move(statements), GetProgram()); - VarBinder()->GetScope()->BindNode(ets_script); + auto *ets_script = AllocNode(Allocator(), Binder()->GetScope(), std::move(statements), GetProgram()); + Binder()->GetScope()->BindNode(ets_script); ets_script->SetRange({start_loc, Lexer()->GetToken().End()}); GetProgram()->SetAst(ets_script); } @@ -189,10 +187,10 @@ void ETSParser::ParseETSGlobalScript(lexer::SourcePosition start_loc, ArenaVecto void ETSParser::CreateGlobalClass() { auto *ident = AllocNode(compiler::Signatures::ETS_GLOBAL, Allocator()); - auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); + auto [decl, var] = Binder()->NewVarDecl(ident->Start(), ident->Name()); ident->SetVariable(var); - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); auto *class_def = AllocNode(Allocator(), class_ctx.GetScope(), ident, ir::ClassDefinitionModifiers::GLOBAL, ir::ModifierFlags::ABSTRACT, Language(Language::Id::ETS)); @@ -234,7 +232,7 @@ ArenaVector ETSParser::PrepareExternalGlobalClass([[maybe_unuse } if (res == ext_sources.end()) { - VarBinder()->InitTopScope(); + Binder()->InitTopScope(); CreateGlobalClass(); auto ins_res = ext_sources.emplace(GetProgram()->SourceFilePath(), Allocator()->Adapter()); ins_res.first->second.push_back(GetProgram()); @@ -244,7 +242,7 @@ ArenaVector ETSParser::PrepareExternalGlobalClass([[maybe_unuse GetProgram()->SetGlobalClass(ext_prog->GlobalClass()); // TODO(user): check nullptr cases and handle recursive imports if (ext_prog->Ast() != nullptr) { - VarBinder()->ResetTopScope(ext_prog->GlobalScope()); + Binder()->ResetTopScope(ext_prog->GlobalScope()); } } @@ -507,7 +505,7 @@ void ETSParser::ParseSources(const std::vector &paths, bool is_exte void ETSParser::ParseDefaultSources() { auto isp = InnerSourceParser(this); - SourceFile source(varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE_FILE, varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE); + SourceFile source(binder::ETSBinder::DEFAULT_IMPORT_SOURCE_FILE, binder::ETSBinder::DEFAULT_IMPORT_SOURCE); auto lexer = InitLexer(source); ArenaVector statements(Allocator()->Adapter()); @@ -525,7 +523,7 @@ void ETSParser::ParseDefaultSources() void ETSParser::ParseSource(const SourceFile &source_file) { - auto *program = Allocator()->New(Allocator(), VarBinder()); + auto *program = Allocator()->New(Allocator(), Binder()); auto esp = ExternalSourceParser(this, program); auto lexer = InitLexer(source_file); @@ -550,15 +548,14 @@ ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &global_ ir::ScriptFunction *init_func; { - varbinder::FunctionParamScope *func_param_scope; + binder::FunctionParamScope *func_param_scope; ArenaVector params(Allocator()->Adapter()); { - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); func_param_scope = func_param_context.LexicalScope().GetScope(); } - auto param_ctx = - varbinder::LexicalScope::Enter(VarBinder(), func_param_scope, false); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope::Enter(Binder(), func_param_scope, false); + auto function_ctx = binder::LexicalScope(Binder()); auto *function_scope = function_ctx.GetScope(); function_scope->BindParamScope(func_param_scope); func_param_scope->BindFunctionScope(function_scope); @@ -584,8 +581,7 @@ ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &global_ return std::make_pair(init_func, init_method); }; - auto class_ctx = - varbinder::LexicalScope::Enter(VarBinder(), GetProgram()->GlobalClassScope()); + auto class_ctx = binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); // Create public method for module re-initialization. The assignments and statements are sequentially called inside. auto [init_func, init_method] = create_function(compiler::Signatures::INIT_METHOD, ir::ScriptFunctionFlags::NONE, @@ -608,7 +604,7 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector::Enter(VarBinder(), GetProgram()->GlobalClassScope()); + binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); node = parser_function(this); if (node != nullptr) { if (current_pos != std::numeric_limits::max()) { @@ -666,8 +662,8 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVectorNextToken(); auto *member_name = ExpectIdentifier(); - auto class_ctx = varbinder::LexicalScope::Enter( - VarBinder(), GetProgram()->GlobalClassScope()); + auto class_ctx = + binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); ParseClassFieldDefiniton(member_name, member_modifiers, &global_properties, init_function); break; } @@ -699,8 +695,8 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector::Enter( - VarBinder(), GetProgram()->GlobalClassScope()); + auto class_ctx = + binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); auto *class_method = ParseClassMethodDefinition(member_name, member_modifiers, class_name); class_method->SetStart(start_loc); if (!class_method->Function()->IsOverload()) { @@ -735,8 +731,8 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector::Enter( - VarBinder(), GetProgram()->GlobalClassScope()); + auto class_ctx = + binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); if (auto *const statement = ParseTopLevelStatement(); statement != nullptr) { statement->SetParent(init_function->Body()); init_function->Body()->AsBlockStatement()->Statements().emplace_back(statement); @@ -752,14 +748,14 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVectorAsETSBinder()->DefaultExport() != nullptr || + if (Binder()->AsETSBinder()->DefaultExport() != nullptr || global_properties.size() - current_pos != 1) { ThrowSyntaxError("Only one default export is allowed in a module"); } auto current_export = global_properties[current_pos++]; current_export->AddModifier(ir::ModifierFlags::DEFAULT_EXPORT); - VarBinder()->AsETSBinder()->SetDefaultExport(current_export); + Binder()->AsETSBinder()->SetDefaultExport(current_export); default_export = false; } else { global_properties[current_pos++]->AddModifier(ir::ModifierFlags::EXPORT); @@ -843,36 +839,36 @@ void ETSParser::AddGlobalDeclaration(ir::AstNode *node) switch (node->Type()) { case ir::AstNodeType::CLASS_DECLARATION: { auto *ident = node->AsClassDeclaration()->Definition()->Ident(); - VarBinder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); + Binder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { // IN_EXTERNAL - ident->Variable()->AddFlag(varbinder::VariableFlags::BUILTIN_TYPE); + ident->Variable()->AddFlag(binder::VariableFlags::BUILTIN_TYPE); } break; } case ir::AstNodeType::STRUCT_DECLARATION: { auto *ident = node->AsETSStructDeclaration()->Definition()->Ident(); - VarBinder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); + Binder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { // IN_EXTERNAL - ident->Variable()->AddFlag(varbinder::VariableFlags::BUILTIN_TYPE); + ident->Variable()->AddFlag(binder::VariableFlags::BUILTIN_TYPE); } break; } case ir::AstNodeType::TS_INTERFACE_DECLARATION: { auto *ident = node->AsTSInterfaceDeclaration()->Id(); - VarBinder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); + Binder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { - ident->Variable()->AddFlag(varbinder::VariableFlags::BUILTIN_TYPE); + ident->Variable()->AddFlag(binder::VariableFlags::BUILTIN_TYPE); } break; } case ir::AstNodeType::TS_ENUM_DECLARATION: { auto *ident = node->AsTSEnumDeclaration()->Key(); - VarBinder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); + Binder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); break; } case ir::AstNodeType::TS_TYPE_ALIAS_DECLARATION: { auto *ident = node->AsTSTypeAliasDeclaration()->Id(); - VarBinder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); + Binder()->TopScope()->InsertBinding(ident->Name(), ident->Variable()); break; } default: { @@ -906,7 +902,7 @@ void ETSParser::ParseTopLevelDeclaration(ArenaVector &statement } // NOLINTNEXTLINE(google-default-arguments) -void ETSParser::CreateCCtor(varbinder::LocalScope *class_scope, ArenaVector &properties, +void ETSParser::CreateCCtor(binder::LocalScope *class_scope, ArenaVector &properties, const lexer::SourcePosition &loc, const bool in_global_class) { bool has_static_field = false; @@ -930,13 +926,12 @@ void ETSParser::CreateCCtor(varbinder::LocalScope *class_scope, ArenaVector::Enter(VarBinder(), class_scope); + auto class_ctx = binder::LexicalScope::Enter(Binder(), class_scope); ArenaVector params(Allocator()->Adapter()); - auto *param_scope = - VarBinder()->Allocator()->New(Allocator(), VarBinder()->GetScope()); - auto *scope = VarBinder()->Allocator()->New(Allocator(), param_scope); + auto *param_scope = Binder()->Allocator()->New(Allocator(), Binder()->GetScope()); + auto *scope = Binder()->Allocator()->New(Allocator(), param_scope); auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); @@ -978,9 +973,9 @@ void ETSParser::CreateCCtor(varbinder::LocalScope *class_scope, ArenaVector(func_expr, Allocator()); static_block->AddModifier(ir::ModifierFlags::STATIC); static_block->SetRange({loc, loc}); - auto [_, var] = VarBinder()->NewVarDecl(loc, Allocator(), id->Name(), static_block); + auto [_, var] = Binder()->NewVarDecl(loc, Allocator(), id->Name(), static_block); (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); id->SetVariable(var); properties.push_back(static_block); } @@ -1274,7 +1269,7 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie // performed multiple times. if (init_function != nullptr && (modifiers & ir::ModifierFlags::CONST) == 0U && initializer != nullptr && !initializer->IsArrowFunctionExpression()) { - ASSERT(VarBinder()->GetScope()->Parent()->IsGlobalScope()); + ASSERT(Binder()->GetScope()->Parent()->IsGlobalScope()); if (auto *const func_body = init_function->Body(); func_body != nullptr && func_body->IsBlockStatement()) { auto *ident = AllocNode(field_name->Name(), Allocator()); ident->SetReference(); @@ -1301,13 +1296,13 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie auto *field = AllocNode(field_name, initializer, type_annotation, modifiers, Allocator(), false); if ((modifiers & ir::ModifierFlags::CONST) != 0) { - ASSERT(VarBinder()->GetScope()->Parent() != nullptr); - if (initializer == nullptr && VarBinder()->GetScope()->Parent()->IsGlobalScope() && !is_declare) { + ASSERT(Binder()->GetScope()->Parent() != nullptr); + if (initializer == nullptr && Binder()->GetScope()->Parent()->IsGlobalScope() && !is_declare) { ThrowSyntaxError("Missing initializer in const declaration"); } - VarBinder()->AddDecl(field_name->Start(), field_name->Name(), field); + Binder()->AddDecl(field_name->Start(), field_name->Name(), field); } else { - VarBinder()->AddDecl(field_name->Start(), field_name->Name(), field); + Binder()->AddDecl(field_name->Start(), field_name->Name(), field); } declarations->push_back(field); @@ -1322,10 +1317,10 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *method_name, ir::ModifierFlags modifiers, ir::Identifier *class_name, ir::Identifier *ident_node) { - auto *cur_scope = VarBinder()->GetScope(); - auto res = cur_scope->Find(method_name->Name(), varbinder::ResolveBindingOptions::ALL); + auto *cur_scope = Binder()->GetScope(); + auto res = cur_scope->Find(method_name->Name(), binder::ResolveBindingOptions::ALL); if (res.variable != nullptr && !res.variable->Declaration()->IsFunctionDecl() && res.scope == cur_scope) { - VarBinder()->ThrowRedeclaration(method_name->Start(), res.name); + Binder()->ThrowRedeclaration(method_name->Start(), res.name); } auto new_status = ParserStatus::NEED_RETURN_TYPE | ParserStatus::ALLOW_SUPER; @@ -1370,8 +1365,8 @@ ir::ScriptFunction *ETSParser::ParseFunction(ParserStatus new_status, ir::Identi auto [typeParamDecl, params, returnTypeAnnotation, funcParamScope, throw_marker] = ParseFunctionSignature(new_status, class_name); - auto param_ctx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope::Enter(Binder(), funcParamScope, false); + auto function_ctx = binder::LexicalScope(Binder()); auto *function_scope = function_ctx.GetScope(); function_scope->BindParamScope(funcParamScope); funcParamScope->BindFunctionScope(function_scope); @@ -1449,7 +1444,7 @@ ir::MethodDefinition *ETSParser::ParseClassMethod(ClassElementDescriptor *desc, std::tuple ETSParser::ParseFunctionBody( [[maybe_unused]] const ArenaVector ¶ms, [[maybe_unused]] ParserStatus new_status, - [[maybe_unused]] ParserStatus context_status, varbinder::FunctionScope *func_scope) + [[maybe_unused]] ParserStatus context_status, binder::FunctionScope *func_scope) { ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE); @@ -1766,11 +1761,11 @@ ir::TSTypeAliasDeclaration *ETSParser::ParseTypeAliasDeclaration() id->SetRange(Lexer()->GetToken().Loc()); auto *type_alias_decl = AllocNode(Allocator(), id); - VarBinder()->AddDecl(Lexer()->GetToken().Start(), ident, type_alias_decl); + Binder()->AddDecl(Lexer()->GetToken().Start(), ident, type_alias_decl); Lexer()->NextToken(); // eat alias name - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::ALLOW_DECLARATION_SITE_VARIANCE; @@ -1798,7 +1793,7 @@ ir::TSInterfaceDeclaration *ETSParser::ParseInterfaceBody(ir::Identifier *name, { GetContext().Status() |= ParserStatus::ALLOW_THIS_TYPE; - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = @@ -1811,7 +1806,7 @@ ir::TSInterfaceDeclaration *ETSParser::ParseInterfaceBody(ir::Identifier *name, extends = ParseInterfaceExtendsClause(); } - auto local_scope = varbinder::LexicalScope(VarBinder()); + auto local_scope = binder::LexicalScope(Binder()); lexer::SourcePosition body_start = Lexer()->GetToken().Start(); auto members = ParseTypeLiteralOrInterface(); @@ -1852,8 +1847,7 @@ ir::Statement *ETSParser::ParseInterfaceDeclaration(bool is_static) auto *decl_node = ParseInterfaceBody(id, is_static); - auto *decl = - VarBinder()->AddDecl(Lexer()->GetToken().Start(), Allocator(), ident, decl_node); + auto *decl = Binder()->AddDecl(Lexer()->GetToken().Start(), Allocator(), ident, decl_node); decl->AsInterfaceDecl()->Add(decl_node); decl_node->SetRange({interface_start, Lexer()->GetToken().End()}); return decl_node; @@ -1875,8 +1869,7 @@ ir::Statement *ETSParser::ParseEnumDeclaration(bool is_const, bool is_static) util::StringView ident = FormInterfaceOrEnumDeclarationIdBinding(key); auto *decl_node = ParseEnumMembers(key, enum_start, is_const, is_static); - auto *decl = - VarBinder()->AddDecl(Lexer()->GetToken().Start(), ident, decl_node, is_const); + auto *decl = Binder()->AddDecl(Lexer()->GetToken().Start(), ident, decl_node, is_const); decl->BindScope(decl_node->Scope()); return decl_node; @@ -1905,7 +1898,7 @@ ir::ClassDefinition *ETSParser::ParseClassDefinition(ir::ClassDefinitionModifier ir::Identifier *ident_node = ParseClassIdent(modifiers); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = @@ -1913,7 +1906,7 @@ ir::ClassDefinition *ETSParser::ParseClassDefinition(ir::ClassDefinitionModifier type_param_decl = ParseTypeParameterDeclaration(&options); } - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); // Parse SuperClass auto [superClass, superTypeParams] = ParseSuperClass(); @@ -2033,7 +2026,7 @@ ir::ClassProperty *ETSParser::ParseInterfaceField(const lexer::SourcePosition &s auto *field = AllocNode(name, initializer, type_annotation, field_modifiers, Allocator(), false); field->SetEnd(Lexer()->GetToken().End()); - auto *decl = VarBinder()->AddDecl(start_loc, field->Id()->Name(), field); + auto *decl = Binder()->AddDecl(start_loc, field->Id()->Name(), field); decl->BindNode(field); return field; @@ -2053,8 +2046,8 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags) auto [typeParamDecl, params, returnTypeAnnotation, funcParamScope, throw_marker] = ParseFunctionSignature(ParserStatus::NEED_RETURN_TYPE); - auto param_ctx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope::Enter(Binder(), funcParamScope, false); + auto function_ctx = binder::LexicalScope(Binder()); auto *function_scope = function_ctx.GetScope(); function_scope->BindParamScope(funcParamScope); funcParamScope->BindFunctionScope(function_scope); @@ -2102,31 +2095,31 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags) void ETSParser::CreateClassFunctionDeclaration(ir::MethodDefinition *method) { - ASSERT(VarBinder()->GetScope()->IsClassScope()); - auto *const cls_scope = VarBinder()->GetScope()->AsClassScope(); + ASSERT(Binder()->GetScope()->IsClassScope()); + auto *const cls_scope = Binder()->GetScope()->AsClassScope(); auto *const method_name = method->Id(); - if (cls_scope->FindLocal(method_name->Name(), varbinder::ResolveBindingOptions::VARIABLES | - varbinder::ResolveBindingOptions::DECLARATION) != nullptr) { - VarBinder()->ThrowRedeclaration(method_name->Start(), method_name->Name()); + if (cls_scope->FindLocal(method_name->Name(), binder::ResolveBindingOptions::VARIABLES | + binder::ResolveBindingOptions::DECLARATION) != nullptr) { + Binder()->ThrowRedeclaration(method_name->Start(), method_name->Name()); } - varbinder::LocalScope *target_scope {}; + binder::LocalScope *target_scope {}; if (method->IsStatic() || method->IsConstructor()) { target_scope = cls_scope->StaticMethodScope(); } else { target_scope = cls_scope->InstanceMethodScope(); } - auto *found = target_scope->FindLocal(method_name->Name(), varbinder::ResolveBindingOptions::BINDINGS); + auto *found = target_scope->FindLocal(method_name->Name()); if (found == nullptr) { - auto class_ctx = varbinder::LexicalScope::Enter(VarBinder(), target_scope); - auto [_, var] = VarBinder()->NewVarDecl(method_name->Start(), Allocator(), - method_name->Name(), method); + auto class_ctx = binder::LexicalScope::Enter(Binder(), target_scope); + auto [_, var] = + Binder()->NewVarDecl(method_name->Start(), Allocator(), method_name->Name(), method); (void)_; var->SetScope(cls_scope); - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); method_name->SetVariable(var); return; } @@ -2147,8 +2140,14 @@ void ETSParser::CreateClassFunctionDeclaration(ir::MethodDefinition *method) method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); } -bool ETSParser::HasDefaultParam(const ir::ScriptFunction *const function) +void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node) { + if (method->IsConstructor()) { + return; // TODO(szd): Fix constructors not working with default params + } + + const auto *const function = method->Function(); + bool has_default_parameter = false; bool has_rest_parameter = false; @@ -2174,7 +2173,7 @@ bool ETSParser::HasDefaultParam(const ir::ScriptFunction *const function) } if (!has_default_parameter) { - return false; + return; } if (has_rest_parameter) { @@ -2182,12 +2181,11 @@ bool ETSParser::HasDefaultParam(const ir::ScriptFunction *const function) function->Start()); } - return true; -} + auto *const cls_scope = Binder()->GetScope()->AsClassScope(); + binder::LocalScope *target_scope = + method->IsStatic() ? cls_scope->StaticMethodScope() : cls_scope->InstanceMethodScope(); + auto *const found = target_scope->FindLocal(method->Id()->Name()); -std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const function, ir::MethodDefinition *method, - ir::Identifier *ident_node, varbinder::ClassScope *const cls_scope) -{ std::string proxy_method = function->Id()->Name().Mutf8() + "_proxy("; for (const auto *const it : function->Params()) { @@ -2228,30 +2226,7 @@ std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const fun proxy_method.pop_back(); proxy_method += ") }"; - return proxy_method; -} - -void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node) -{ - if (method->IsConstructor()) { - return; // TODO(szd): Fix constructors not working with default params - } - - const auto *const function = method->Function(); - - if (!HasDefaultParam(function)) { - return; - } - - auto *const cls_scope = VarBinder()->GetScope()->AsClassScope(); - varbinder::LocalScope *target_scope = - method->IsStatic() ? cls_scope->StaticMethodScope() : cls_scope->InstanceMethodScope(); - auto *const found = target_scope->FindLocal(method->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); - - std::string proxy_method = CreateProxyMethodName(function, method, ident_node, cls_scope); - - auto class_ctx = - varbinder::LexicalScope::Enter(VarBinder(), GetProgram()->GlobalClassScope()); + auto class_ctx = binder::LexicalScope::Enter(Binder(), GetProgram()->GlobalClassScope()); auto *const proxy_method_def = CreateMethodDefinition(method->Modifiers(), proxy_method, ".ets"); proxy_method_def->Function()->SetDefaultParamProxy(); @@ -2263,15 +2238,10 @@ void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition * proxy_method_def->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); } -std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) +std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *const type_annotation) { const std::string optional_nullable = type_annotation->IsNullable() ? "|null" : ""; - // NOTE(aakmaev): Support nullable types as unions - if (type_annotation->IsNullable() && type_annotation->IsETSUnionType()) { - type_annotation = type_annotation->AsETSUnionType()->Types().front(); - } - if (type_annotation->IsETSPrimitiveType()) { switch (type_annotation->AsETSPrimitiveType()->GetPrimitiveType()) { case ir::PrimitiveType::BYTE: @@ -2494,42 +2464,6 @@ ir::TypeNode *ETSParser::ParsePrimitiveType(TypeAnnotationParsingOptions *option return type_annotation; } -ir::ETSUnionType *ETSParser::ParseUnionType(ir::Expression *type) -{ - TypeAnnotationParsingOptions options = - TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::DISALLOW_UNION; - lexer::SourcePosition start_loc = type->Start(); - ArenaVector types(Allocator()->Adapter()); - ASSERT(type->IsTypeNode()); - types.push_back(type->AsTypeNode()); - - bool is_nullable {false}; - while (true) { - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_BITWISE_OR) { - break; - } - - Lexer()->NextToken(); // eat '|' - - if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_NULL) { - Lexer()->NextToken(); // eat 'null' - type->AddModifier(ir::ModifierFlags::NULLABLE); - is_nullable = true; - continue; - } - - types.push_back(ParseTypeAnnotation(&options)); - } - - lexer::SourcePosition end_loc = types.back()->End(); - auto *union_type = AllocNode(std::move(types)); - union_type->SetRange({start_loc, end_loc}); - if (is_nullable) { - union_type->AddModifier(ir::ModifierFlags::NULLABLE); - } - return union_type; -} - ir::TSIntersectionType *ETSParser::ParseIntersectionType(ir::Expression *type) { auto start_loc = type->Start(); @@ -2577,8 +2511,8 @@ ir::TypeNode *ETSParser::ParseWildcardType(TypeAnnotationParsingOptions *options ir::TypeNode *ETSParser::ParseFunctionType() { auto start_loc = Lexer()->GetToken().Start(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -2720,9 +2654,19 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio type_annotation->SetRange({start_pos, Lexer()->GetToken().End()}); } - if (((*options) & TypeAnnotationParsingOptions::DISALLOW_UNION) == 0 && - Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { - return ParseUnionType(type_annotation); + while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { + Lexer()->NextToken(); // eat '|' + + if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_NULL) { + if (throw_error) { + ThrowExpectedToken(lexer::TokenType::LITERAL_NULL); + } + + return nullptr; + } + Lexer()->NextToken(); // eat 'null' + + type_annotation->AddModifier(ir::ModifierFlags::NULLABLE); } return type_annotation; @@ -2874,7 +2818,7 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVectorSetRange({start_loc, end_loc}); if (import_declaration->Language().IsDynamic()) { - VarBinder()->AsETSBinder()->AddDynamicImport(import_declaration); + Binder()->AsETSBinder()->AddDynamicImport(import_declaration); } ConsumeSemicolon(import_declaration); @@ -2890,7 +2834,7 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVector(VarBinder())->SetDefaultImports(std::move(imports)); + static_cast(Binder())->SetDefaultImports(std::move(imports)); } sort(all_user_paths.begin(), all_user_paths.end()); @@ -2977,7 +2921,7 @@ void ETSParser::ParseNameSpaceImport(ArenaVector *specifiers) specifier->SetRange({namespace_start, Lexer()->GetToken().End()}); specifiers->push_back(specifier); - VarBinder()->AddDecl(local->Start(), local->Name(), local->Name(), specifier); + Binder()->AddDecl(local->Start(), local->Name(), local->Name(), specifier); Lexer()->NextToken(); // eat local name } @@ -3166,16 +3110,16 @@ ir::Expression *ETSParser::ParseFunctionParameter() param_expression->SetRange({param_ident->Start(), param_ident->End()}); } - auto *const var = std::get<1>(VarBinder()->AddParamDecl(param_expression)); + auto *const var = std::get<1>(Binder()->AddParamDecl(param_expression)); param_expression->Ident()->SetVariable(var); - var->SetScope(VarBinder()->GetScope()); + var->SetScope(Binder()->GetScope()); return param_expression; } ir::Expression *ETSParser::CreateParameterThis(const util::StringView class_name) { - auto *param_ident = AllocNode(varbinder::TypedBinder::MANDATORY_PARAM_THIS, Allocator()); + auto *param_ident = AllocNode(binder::TypedBinder::MANDATORY_PARAM_THIS, Allocator()); param_ident->SetRange(Lexer()->GetToken().Loc()); ir::Expression *class_type_name = AllocNode(class_name, Allocator()); @@ -3191,9 +3135,9 @@ ir::Expression *ETSParser::CreateParameterThis(const util::StringView class_name auto *param_expression = AllocNode(param_ident, nullptr); param_expression->SetRange({param_ident->Start(), param_ident->End()}); - auto *const var = std::get<1>(VarBinder()->AddParamDecl(param_expression)); + auto *const var = std::get<1>(Binder()->AddParamDecl(param_expression)); param_ident->AsIdentifier()->SetVariable(var); - var->SetScope(VarBinder()->GetScope()); + var->SetScope(Binder()->GetScope()); return param_expression; } @@ -3204,18 +3148,18 @@ void ETSParser::AddVariableDeclarationBindings(ir::Expression *init, lexer::Sour std::vector bindings = util::Helpers::CollectBindingNames(init); for (auto *binding : bindings) { - varbinder::Decl *decl {}; - varbinder::Variable *var {}; + binder::Decl *decl {}; + binder::Variable *var {}; if ((flags & VariableParsingFlags::LET) != 0U) { - std::tie(decl, var) = VarBinder()->NewVarDecl(start_loc, binding->Name()); + std::tie(decl, var) = Binder()->NewVarDecl(start_loc, binding->Name()); } else { - std::tie(decl, var) = VarBinder()->NewVarDecl(start_loc, binding->Name()); + std::tie(decl, var) = Binder()->NewVarDecl(start_loc, binding->Name()); } binding->SetVariable(var); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::LOCAL); + var->SetScope(Binder()->GetScope()); + var->AddFlag(binder::VariableFlags::LOCAL); decl->BindNode(init); } } @@ -3362,7 +3306,7 @@ ir::Expression *ETSParser::ParseCatchParam() ThrowSyntaxError("Unexpected token in catch parameter, expected an identifier"); } - auto param_decl = VarBinder()->AddParamDecl(param); + auto param_decl = Binder()->AddParamDecl(param); if (param->IsIdentifier()) { param->AsIdentifier()->SetVariable(std::get<1>(param_decl)); @@ -3439,7 +3383,7 @@ ir::Statement *ETSParser::ParseTryStatement() ir::Statement *ETSParser::ParseImportDeclaration([[maybe_unused]] StatementParsingFlags flags) { - ImportDeclarationContext import_ctx(VarBinder()); + ImportDeclarationContext import_ctx(Binder()); char32_t next_char = Lexer()->Lookahead(); if (next_char == lexer::LEX_CHAR_LEFT_PAREN || next_char == lexer::LEX_CHAR_DOT) { @@ -3472,7 +3416,7 @@ ir::Statement *ETSParser::ParseImportDeclaration([[maybe_unused]] StatementParsi import_declaration->SetRange({start_loc, end_loc}); if (import_declaration->Language().IsDynamic()) { - VarBinder()->AsETSBinder()->AddDynamicImport(import_declaration); + Binder()->AsETSBinder()->AddDynamicImport(import_declaration); } ConsumeSemicolon(import_declaration); @@ -3548,39 +3492,6 @@ ir::Expression *ETSParser::ParseUnaryOrPrefixUpdateExpression(ExpressionParseFla return return_expr; } -// NOLINTNEXTLINE(google-default-arguments) -ir::Expression *ETSParser::ParseDefaultPrimaryExpression(ExpressionParseFlags flags) -{ - auto start_loc = Lexer()->GetToken().Start(); - auto saved_pos = Lexer()->Save(); - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::POTENTIAL_CLASS_LITERAL | - TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE | - TypeAnnotationParsingOptions::DISALLOW_UNION; - ir::TypeNode *potential_type = ParseTypeAnnotation(&options); - - if (potential_type != nullptr) { - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { - Lexer()->NextToken(); // eat '.' - } - - if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword()) { - Lexer()->NextToken(); // eat 'class' and 'struct' - auto *class_literal = AllocNode(potential_type); - class_literal->SetRange({start_loc, Lexer()->GetToken().End()}); - return class_literal; - } - } - - Lexer()->Rewind(saved_pos); - - if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { - return ParsePrimaryExpressionIdent(flags); - } - - ThrowSyntaxError({"Unexpected token '", lexer::TokenToString(Lexer()->GetToken().Type()), "'."}); - return nullptr; -} - // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) { @@ -3632,9 +3543,37 @@ ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) ThrowSyntaxError("Type alias is allowed only as top-level declaration"); } default: { - return ParseDefaultPrimaryExpression(flags); + auto start_loc = Lexer()->GetToken().Start(); + auto saved_pos = Lexer()->Save(); + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::POTENTIAL_CLASS_LITERAL | + TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE; + ir::TypeNode *potential_type = ParseTypeAnnotation(&options); + + if (potential_type != nullptr) { + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { + Lexer()->NextToken(); // eat '.' + } + + if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword()) { + Lexer()->NextToken(); // eat 'class' and 'struct' + auto *class_literal = AllocNode(potential_type); + class_literal->SetRange({start_loc, Lexer()->GetToken().End()}); + return class_literal; + } + } + + Lexer()->Rewind(saved_pos); + + if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { + return ParsePrimaryExpressionIdent(flags); + } + + break; } } + + ThrowSyntaxError({"Unexpected token '", lexer::TokenToString(Lexer()->GetToken().Type()), "'."}); + return nullptr; } bool ETSParser::IsArrowFunctionExpressionStart() @@ -3921,13 +3860,13 @@ ir::Expression *ETSParser::ParseNewExpression() ir::ClassDefinition *class_definition {}; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - auto *parent_class_scope = VarBinder()->GetScope(); + auto *parent_class_scope = Binder()->GetScope(); while (!parent_class_scope->IsClassScope()) { ASSERT(parent_class_scope->Parent()); parent_class_scope = parent_class_scope->Parent(); } - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); ArenaVector implements(Allocator()->Adapter()); auto modifiers = ir::ClassDefinitionModifiers::ANONYMOUS | ir::ClassDefinitionModifiers::HAS_SUPER; auto [ctor, properties, bodyRange] = ParseClassBody(modifiers); @@ -4013,10 +3952,10 @@ ir::TSTypeParameter *ETSParser::ParseTypeParameter([[maybe_unused]] TypeAnnotati }(); auto *param_ident = ExpectIdentifier(); - auto [decl, var] = VarBinder()->NewVarDecl(param_ident->Start(), param_ident->Name()); + auto [decl, var] = Binder()->NewVarDecl(param_ident->Start(), param_ident->Name()); param_ident->SetVariable(var); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::TYPE_PARAMETER); + var->SetScope(Binder()->GetScope()); + var->AddFlag(binder::VariableFlags::TYPE_PARAMETER); ir::TypeNode *constraint = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_EXTENDS) { @@ -4078,7 +4017,7 @@ ir::TSEnumDeclaration *ETSParser::ParseEnumMembers(ir::Identifier *const key, co Lexer()->Rewind(pos); ArenaVector members(Allocator()->Adapter()); - const auto enum_ctx = varbinder::LexicalScope(VarBinder()); + const auto enum_ctx = binder::LexicalScope(Binder()); if (string_type_enum) { ParseStringEnum(members); @@ -4086,8 +4025,8 @@ ir::TSEnumDeclaration *ETSParser::ParseEnumMembers(ir::Identifier *const key, co ParseNumberEnum(members); } - auto *const enum_declaration = AllocNode( - Allocator(), VarBinder()->GetScope()->AsLocalScope(), key, std::move(members), is_const, is_static); + auto *const enum_declaration = AllocNode(Allocator(), Binder()->GetScope()->AsLocalScope(), + key, std::move(members), is_const, is_static); enum_declaration->SetRange({enum_start, Lexer()->GetToken().End()}); Lexer()->NextToken(); // eat '}' @@ -4103,9 +4042,9 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) // Lambda to parse enum member (maybe with initializer) auto const parse_member = [this, &members, &enum_values, ¤t_value]() { auto *const ident = ExpectIdentifier(); - auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::STATIC); + auto [decl, var] = Binder()->NewVarDecl(ident->Start(), ident->Name()); + var->SetScope(Binder()->GetScope()); + var->AddFlag(binder::VariableFlags::STATIC); ident->SetVariable(var); auto const add_value = [this, &enum_values](checker::ETSEnumType::ValueType const new_value) { @@ -4187,9 +4126,9 @@ void ETSParser::ParseStringEnum(ArenaVector &members) // Lambda to parse enum member (maybe with initializer) auto const parse_member = [this, &members, &enum_values]() { auto *const ident = ExpectIdentifier(); - auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::STATIC); + auto [decl, var] = Binder()->NewVarDecl(ident->Start(), ident->Name()); + var->SetScope(Binder()->GetScope()); + var->AddFlag(binder::VariableFlags::STATIC); ident->SetVariable(var); ir::StringLiteral *item_value; @@ -4295,14 +4234,14 @@ bool ETSParser::CheckClassElement(ir::AstNode *property, [[maybe_unused]] ir::Me ThrowSyntaxError("Only one static block is allowed", property->Start()); } - ASSERT(VarBinder()->GetScope()->IsClassScope()); - auto class_ctx = varbinder::LexicalScope::Enter( - VarBinder(), VarBinder()->GetScope()->AsClassScope()->StaticMethodScope()); + ASSERT(Binder()->GetScope()->IsClassScope()); + auto class_ctx = binder::LexicalScope::Enter( + Binder(), Binder()->GetScope()->AsClassScope()->StaticMethodScope()); auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); auto [_, var] = - VarBinder()->NewVarDecl(property->Start(), Allocator(), id->Name(), property); + Binder()->NewVarDecl(property->Start(), Allocator(), id->Name(), property); (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); id->SetVariable(var); property->AsClassStaticBlock()->Function()->SetIdent(id); } @@ -4332,13 +4271,13 @@ void ETSParser::CreateImplicitConstructor([[maybe_unused]] ir::MethodDefinition auto *method_def = BuildImplicitConstructor(ir::ClassDefinitionModifiers::SET_CTOR_ID, start_loc); properties.push_back(method_def); - ASSERT(VarBinder()->GetScope()->IsClassScope()); - auto class_ctx = varbinder::LexicalScope::Enter( - VarBinder(), VarBinder()->GetScope()->AsClassScope()->StaticMethodScope()); - auto [_, var] = VarBinder()->NewVarDecl(method_def->Start(), Allocator(), - method_def->Id()->Name(), method_def); + ASSERT(Binder()->GetScope()->IsClassScope()); + auto class_ctx = binder::LexicalScope::Enter( + Binder(), Binder()->GetScope()->AsClassScope()->StaticMethodScope()); + auto [_, var] = Binder()->NewVarDecl(method_def->Start(), Allocator(), + method_def->Id()->Name(), method_def); (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); + var->AddFlag(binder::VariableFlags::METHOD); method_def->Function()->Id()->SetVariable(var); } @@ -4466,7 +4405,7 @@ ir::Statement *ETSParser::CreateStatement(std::string_view const source_code, st return statements[0U]; } - auto const local_ctx = varbinder::LexicalScope(VarBinder()); + auto const local_ctx = binder::LexicalScope(Binder()); auto *const scope = local_ctx.GetScope(); auto *const block_stmt = AllocNode(Allocator(), scope, std::move(statements)); @@ -4543,7 +4482,7 @@ ExternalSourceParser::ExternalSourceParser(ETSParser *parser, Program *new_progr : parser_(parser), saved_program_(parser_->GetProgram()), saved_lexer_(parser_->Lexer()), - saved_top_scope_(parser_->VarBinder()->TopScope()) + saved_top_scope_(parser_->Binder()->TopScope()) { parser_->SetProgram(new_program); parser_->GetContext().SetProgram(new_program); @@ -4554,7 +4493,7 @@ ExternalSourceParser::~ExternalSourceParser() parser_->SetLexer(saved_lexer_); parser_->SetProgram(saved_program_); parser_->GetContext().SetProgram(saved_program_); - parser_->VarBinder()->ResetTopScope(saved_top_scope_); + parser_->Binder()->ResetTopScope(saved_top_scope_); } //================================================================================================// diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 9d8892c6b672d7146d201b7e82e49055d561f44c..87d1fbc9800bc10fbf2d939ca74c8ece6e7d46cd 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -96,7 +96,7 @@ private: ir::Expression *prop_name, lexer::SourcePosition *prop_end) override; std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, - varbinder::FunctionScope *func_scope) override; + binder::FunctionScope *func_scope) override; ir::TypeNode *ParseFunctionReturnType(ParserStatus status) override; ir::ScriptFunctionFlags ParseFunctionThrowMarker(bool is_rethrows_allowed) override; ir::Expression *CreateParameterThis(util::StringView class_name) override; @@ -110,14 +110,10 @@ private: ir::TypeNode *ParseTypeReference(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseBaseTypeReference(TypeAnnotationParsingOptions *options); ir::TypeNode *ParsePrimitiveType(TypeAnnotationParsingOptions *options, ir::PrimitiveType type); - ir::ETSUnionType *ParseUnionType(ir::Expression *type); ir::TSIntersectionType *ParseIntersectionType(ir::Expression *type); ir::TypeNode *ParseWildcardType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseFunctionType(); void CreateClassFunctionDeclaration(ir::MethodDefinition *method); - bool HasDefaultParam(const ir::ScriptFunction *function); - std::string CreateProxyMethodName(const ir::ScriptFunction *function, ir::MethodDefinition *method, - ir::Identifier *ident_node, varbinder::ClassScope *cls_scope); void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node = nullptr); std::string GetNameForTypeNode(const ir::TypeNode *type_annotation); ir::TSInterfaceDeclaration *ParseInterfaceBody(ir::Identifier *name, bool is_static); @@ -151,8 +147,6 @@ private: ir::Expression *ParseUnaryOrPrefixUpdateExpression( ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; // NOLINTNEXTLINE(google-default-arguments) - ir::Expression *ParseDefaultPrimaryExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); - // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ParsePrimaryExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; ir::Expression *ParsePostPrimaryExpression(ir::Expression *primary_expr, lexer::SourcePosition start_loc, bool ignore_call_expression, bool *is_chain_expression) override; @@ -199,7 +193,7 @@ private: bool CheckClassElement(ir::AstNode *property, ir::MethodDefinition *&ctor, ArenaVector &properties) override; // NOLINTNEXTLINE(google-default-arguments) - void CreateCCtor(varbinder::LocalScope *class_scope, ArenaVector &properties, + void CreateCCtor(binder::LocalScope *class_scope, ArenaVector &properties, const lexer::SourcePosition &loc, bool in_global_class = false) override; void CreateImplicitConstructor(ir::MethodDefinition *&ctor, ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, @@ -208,7 +202,7 @@ private: const lexer::SourcePosition &start_loc, bool ignore_call_expression) override; bool ParsePotentialNonNullExpression(ir::Expression **expression, lexer::SourcePosition start_loc) override; - varbinder::Decl *BindClassName([[maybe_unused]] ir::Identifier *ident_node) override + binder::Decl *BindClassName([[maybe_unused]] ir::Identifier *ident_node) override { return nullptr; } @@ -280,7 +274,7 @@ private: ETSParser *parser_; Program *saved_program_; lexer::Lexer *saved_lexer_; - varbinder::GlobalScope *saved_top_scope_; + binder::GlobalScope *saved_top_scope_; }; class InnerSourceParser { diff --git a/ets2panda/parser/TSparser.cpp b/ets2panda/parser/TSparser.cpp index e42e9a05173a70377e90a485604c7baed8fb5ef1..8a36b79c499bba94f6fba1b8fbe4b3104fecd257 100644 --- a/ets2panda/parser/TSparser.cpp +++ b/ets2panda/parser/TSparser.cpp @@ -16,9 +16,9 @@ #include "TSparser.h" #include "util/helpers.h" -#include "varbinder/privateBinding.h" -#include "varbinder/scope.h" -#include "varbinder/tsBinding.h" +#include "binder/privateBinding.h" +#include "binder/scope.h" +#include "binder/tsBinding.h" #include "lexer/TSLexer.h" #include "ir/base/spreadElement.h" #include "ir/base/decorator.h" @@ -194,14 +194,14 @@ ir::TSTypeAliasDeclaration *TSParser::ParseTypeAliasDeclaration() } const util::StringView &ident = Lexer()->GetToken().Ident(); - varbinder::TSBinding ts_binding(Allocator(), ident); - auto *decl = VarBinder()->AddTsDecl(Lexer()->GetToken().Start(), ts_binding.View()); + binder::TSBinding ts_binding(Allocator(), ident); + auto *decl = Binder()->AddTsDecl(Lexer()->GetToken().Start(), ts_binding.View()); auto *id = AllocNode(ident, Allocator()); id->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1098,7 +1098,7 @@ ir::TypeNode *TSParser::ParseTypeLiteralOrMappedType(ir::TypeNode *type_annotati Lexer()->NextToken(); auto *literal_type = AllocNode(std::move(members)); - auto *type_var = varbinder::Scope::CreateVar(Allocator(), "__type", varbinder::VariableFlags::TYPE, literal_type); + auto *type_var = binder::Scope::CreateVar(Allocator(), "__type", binder::VariableFlags::TYPE, literal_type); literal_type->SetVariable(type_var); literal_type->SetRange({body_start, body_end}); return literal_type; @@ -1182,7 +1182,7 @@ ir::TSUnionType *TSParser::ParseUnionType(ir::TypeNode *type, bool restrict_exte lexer::SourcePosition end_loc = types.back()->End(); auto *union_type = AllocNode(std::move(types)); - auto *type_var = varbinder::Scope::CreateVar(Allocator(), "__type", varbinder::VariableFlags::TYPE, union_type); + auto *type_var = binder::Scope::CreateVar(Allocator(), "__type", binder::VariableFlags::TYPE, union_type); union_type->SetVariable(type_var); union_type->SetRange({start_loc, end_loc}); @@ -1225,8 +1225,7 @@ ir::TSIntersectionType *TSParser::ParseIntersectionType(ir::Expression *type, bo lexer::SourcePosition end_loc = types.back()->End(); auto *intersection_type = AllocNode(std::move(types)); - auto *type_var = - varbinder::Scope::CreateVar(Allocator(), "__type", varbinder::VariableFlags::TYPE, intersection_type); + auto *type_var = binder::Scope::CreateVar(Allocator(), "__type", binder::VariableFlags::TYPE, intersection_type); intersection_type->SetVariable(type_var); intersection_type->SetRange({start_loc, end_loc}); @@ -1429,7 +1428,7 @@ ir::TypeNode *TSParser::ParseParenthesizedOrFunctionType(ir::TypeNode *type_anno ir::TypeNode *TSParser::ParseFunctionType(lexer::SourcePosition start_loc, bool is_construction_type, bool throw_error, bool abstract_constructor) { - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { @@ -1445,7 +1444,7 @@ ir::TypeNode *TSParser::ParseFunctionType(lexer::SourcePosition start_loc, bool } } - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -1639,7 +1638,7 @@ ir::ArrowFunctionExpression *TSParser::ParsePotentialArrowExpression(ir::Express case lexer::TokenType::PUNCTUATOR_LESS_THAN: { const auto saved_pos = Lexer()->Save(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); auto options = TypeAnnotationParsingOptions::NO_OPTS; type_param_decl = ParseTypeParameterDeclaration(&options); if (type_param_decl == nullptr) { @@ -1783,7 +1782,7 @@ ir::TSSignatureDeclaration *TSParser::ParseSignatureMember(bool is_call_signatur Lexer()->NextToken(); // eat 'new' keyword } - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1794,7 +1793,7 @@ ir::TSSignatureDeclaration *TSParser::ParseSignatureMember(bool is_call_signatur } } - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -1924,10 +1923,10 @@ std::tuple TSParser::ParseInterfacePropertyKey() return {key, is_computed}; } -void TSParser::CreateTSVariableForProperty(ir::AstNode *node, const ir::Expression *key, varbinder::VariableFlags flags) +void TSParser::CreateTSVariableForProperty(ir::AstNode *node, const ir::Expression *key, binder::VariableFlags flags) { - varbinder::Variable *prop_var = nullptr; - bool is_method = (flags & varbinder::VariableFlags::METHOD) != 0; + binder::Variable *prop_var = nullptr; + bool is_method = (flags & binder::VariableFlags::METHOD) != 0; util::StringView prop_name = "__computed"; switch (key->Type()) { @@ -1937,7 +1936,7 @@ void TSParser::CreateTSVariableForProperty(ir::AstNode *node, const ir::Expressi } case ir::AstNodeType::NUMBER_LITERAL: { prop_name = key->AsNumberLiteral()->Str(); - flags |= varbinder::VariableFlags::NUMERIC_NAME; + flags |= binder::VariableFlags::NUMERIC_NAME; break; } case ir::AstNodeType::STRING_LITERAL: { @@ -1945,13 +1944,13 @@ void TSParser::CreateTSVariableForProperty(ir::AstNode *node, const ir::Expressi break; } default: { - flags |= varbinder::VariableFlags::COMPUTED; + flags |= binder::VariableFlags::COMPUTED; break; } } - prop_var = is_method ? varbinder::Scope::CreateVar(Allocator(), prop_name, flags, node) - : varbinder::Scope::CreateVar(Allocator(), prop_name, flags, node); + prop_var = is_method ? binder::Scope::CreateVar(Allocator(), prop_name, flags, node) + : binder::Scope::CreateVar(Allocator(), prop_name, flags, node); node->SetVariable(prop_var); } @@ -1966,14 +1965,14 @@ ir::AstNode *TSParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio Lexer()->NextToken(); // eat '?' } - varbinder::VariableFlags flags = varbinder::VariableFlags::NONE; + binder::VariableFlags flags = binder::VariableFlags::NONE; if (is_optional) { - flags |= varbinder::VariableFlags::OPTIONAL; + flags |= binder::VariableFlags::OPTIONAL; } if (is_readonly) { - flags |= varbinder::VariableFlags::READONLY; + flags |= binder::VariableFlags::READONLY; } if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS || @@ -1983,7 +1982,7 @@ ir::AstNode *TSParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio start_loc); } - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1994,7 +1993,7 @@ ir::AstNode *TSParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); } - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto *func_param_scope = func_param_context.LexicalScope().GetScope(); auto params = ParseFunctionParams(); @@ -2009,7 +2008,7 @@ ir::AstNode *TSParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio auto *method_signature = AllocNode( func_param_scope, key, type_param_decl, std::move(params), return_type, isComputed, is_optional); func_param_scope->BindNode(method_signature); - CreateTSVariableForProperty(method_signature, key, flags | varbinder::VariableFlags::METHOD); + CreateTSVariableForProperty(method_signature, key, flags | binder::VariableFlags::METHOD); method_signature->SetRange({start_loc, Lexer()->GetToken().End()}); return method_signature; } @@ -2024,7 +2023,7 @@ ir::AstNode *TSParser::ParsePropertyOrMethodSignature(const lexer::SourcePositio auto *property_signature = AllocNode(key, type_annotation, isComputed, is_optional, is_readonly); - CreateTSVariableForProperty(property_signature, key, flags | varbinder::VariableFlags::PROPERTY); + CreateTSVariableForProperty(property_signature, key, flags | binder::VariableFlags::PROPERTY); property_signature->SetRange({start_loc, Lexer()->GetToken().End()}); return property_signature; } @@ -2216,7 +2215,7 @@ ir::Expression *TSParser::ParseFunctionParameter() {parameter_start, function_parameter->AsTSParameterProperty()->Parameter()->End()}); } - VarBinder()->AddParamDecl(function_parameter); + Binder()->AddParamDecl(function_parameter); return function_parameter; } @@ -2460,7 +2459,7 @@ void TSParser::ValidateFunctionOverloadParams(const ArenaVector TSParser::ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, - varbinder::FunctionScope *func_scope) + binder::FunctionScope *func_scope) { bool is_declare = InAmbientContext(); bool is_overload = false; @@ -2546,7 +2545,7 @@ ir::AstNode *TSParser::ParseImportDefaultSpecifier(ArenaVector *s specifier->SetRange(specifier->Local()->Range()); specifiers->push_back(specifier); - VarBinder()->AddDecl(local->Start(), "default", local->Name(), specifier); + Binder()->AddDecl(local->Start(), "default", local->Name(), specifier); Lexer()->NextToken(); // eat specifier name @@ -2799,22 +2798,22 @@ void TSParser::ThrowIfBodyEmptyError(ir::Statement *consequent) void TSParser::CreateFunctionDeclaration(ir::Identifier *ident_node, util::StringView &name, ir::ScriptFunction *func, const lexer::SourcePosition &start_loc) { - const auto &bindings = VarBinder()->GetScope()->Bindings(); + const auto &bindings = Binder()->GetScope()->Bindings(); auto res = bindings.find(name); - varbinder::FunctionDecl *decl {}; + binder::FunctionDecl *decl {}; if (res == bindings.end()) { - decl = VarBinder()->AddDecl(ident_node->Start(), Allocator(), name, func); + decl = Binder()->AddDecl(ident_node->Start(), Allocator(), name, func); } else { - varbinder::Decl *current_decl = res->second->Declaration(); + binder::Decl *current_decl = res->second->Declaration(); if (!current_decl->IsFunctionDecl()) { - VarBinder()->ThrowRedeclaration(start_loc, current_decl->Name()); + Binder()->ThrowRedeclaration(start_loc, current_decl->Name()); } decl = current_decl->AsFunctionDecl(); if (!decl->Node()->AsScriptFunction()->IsOverload()) { - VarBinder()->ThrowRedeclaration(start_loc, current_decl->Name()); + Binder()->ThrowRedeclaration(start_loc, current_decl->Name()); } } @@ -2830,7 +2829,7 @@ ir::ExportDefaultDeclaration *TSParser::ParseExportDefaultDeclaration(const lexe ir::AstNode *decl_node = nullptr; bool eat_semicolon = false; - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (Lexer()->GetToken().KeywordType()) { case lexer::TokenType::KEYW_FUNCTION: { @@ -2887,7 +2886,7 @@ ir::ExportNamedDeclaration *TSParser::ParseNamedExportDeclaration(const lexer::S flags |= ir::ModifierFlags::ABSTRACT; } - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (Lexer()->GetToken().KeywordType()) { case lexer::TokenType::KEYW_VAR: { @@ -2952,7 +2951,7 @@ ir::ExportNamedDeclaration *TSParser::ParseNamedExportDeclaration(const lexer::S ir::Statement *TSParser::ParseImportDeclaration([[maybe_unused]] StatementParsingFlags flags) { - ImportDeclarationContext import_ctx(VarBinder()); + ImportDeclarationContext import_ctx(Binder()); char32_t next_char = Lexer()->Lookahead(); if (next_char == lexer::LEX_CHAR_LEFT_PAREN || next_char == lexer::LEX_CHAR_DOT) { diff --git a/ets2panda/parser/TSparser.h b/ets2panda/parser/TSparser.h index 7acd0b288c5ba578cc3efcf225f9fd9a49b9fcf9..75da1c6da798595f7cab3ba847e22e5dd1e28631 100644 --- a/ets2panda/parser/TSparser.h +++ b/ets2panda/parser/TSparser.h @@ -65,7 +65,7 @@ private: bool throw_error); ir::TSSignatureDeclaration *ParseSignatureMember(bool is_call_signature); bool IsPotentiallyIndexSignature(); - void CreateTSVariableForProperty(ir::AstNode *node, const ir::Expression *key, varbinder::VariableFlags flags); + void CreateTSVariableForProperty(ir::AstNode *node, const ir::Expression *key, binder::VariableFlags flags); void ValidateFunctionParam(const ArenaVector ¶ms, const ir::Expression *parameter, bool *seen_optional); ir::TSParameterProperty *CreateParameterProperty(ir::Expression *parameter, ir::ModifierFlags modifiers); @@ -121,7 +121,7 @@ private: ir::TypeNode *ParseFunctionReturnType(ParserStatus status) override; std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, - varbinder::FunctionScope *func_scope) override; + binder::FunctionScope *func_scope) override; ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers) override; ir::Statement *ParseExportDeclaration(StatementParsingFlags flags) override; ir::Expression *ParseCoverParenthesizedExpressionAndArrowParameterList() override; diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 63be3a152ccb4ce39d2b35934e677ffee30d45c2..c550911bb5fc25219abe4a64082c715b2c781ba3 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -15,8 +15,8 @@ #include "TypedParser.h" -#include "varbinder/privateBinding.h" -#include "varbinder/tsBinding.h" +#include "binder/privateBinding.h" +#include "binder/tsBinding.h" #include "lexer/lexer.h" #include "ir/base/classDefinition.h" #include "ir/base/decorator.h" @@ -202,7 +202,7 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction() ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); lexer::SourcePosition start_loc = Lexer()->GetToken().Start(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); auto type_param_decl_options = TypeAnnotationParsingOptions::NO_OPTS; ir::TSTypeParameterDeclaration *type_param_decl = ParseTypeParameterDeclaration(&type_param_decl_options); @@ -211,7 +211,7 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction() return nullptr; } - FunctionParameterContext func_param_context(&GetContext(), VarBinder()); + FunctionParameterContext func_param_context(&GetContext(), Binder()); auto params = ParseFunctionParams(); ParserStatus arrow_status = ParserStatus::NO_OPTS; @@ -234,7 +234,7 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction() ArrowFunctionDescriptor desc(std::move(params), func_param_context.LexicalScope().GetScope(), start_loc, arrow_status); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto function_ctx = binder::LexicalScope(Binder()); return ParseArrowFunctionExpressionBody(&arrow_function_context, function_ctx.GetScope(), &desc, type_param_decl, return_type_annotation); } @@ -261,7 +261,7 @@ ir::TSModuleDeclaration *TypedParser::ParseAmbientExternalModuleDeclaration(cons Lexer()->NextToken(); - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); ir::Statement *body = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { @@ -286,7 +286,7 @@ ir::TSModuleDeclaration *TypedParser::ParseModuleOrNamespaceDeclaration(const le ThrowSyntaxError("Identifier expected"); } - auto *decl = VarBinder()->AddDecl(Lexer()->GetToken().Start(), Lexer()->GetToken().Ident()); + auto *decl = Binder()->AddDecl(Lexer()->GetToken().Start(), Lexer()->GetToken().Ident()); auto *ident_node = AllocNode(Lexer()->GetToken().Ident(), Allocator()); ident_node->SetRange(Lexer()->GetToken().Loc()); @@ -294,7 +294,7 @@ ir::TSModuleDeclaration *TypedParser::ParseModuleOrNamespaceDeclaration(const le Lexer()->NextToken(); ir::Statement *body = nullptr; - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { Lexer()->NextToken(); @@ -315,7 +315,7 @@ ir::TSModuleDeclaration *TypedParser::ParseModuleOrNamespaceDeclaration(const le ir::TSModuleBlock *TypedParser::ParseTsModuleBlock() { - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { ThrowSyntaxError("'{' expected."); } @@ -452,7 +452,7 @@ ir::TSTypeParameterDeclaration *TypedParser::ParseFunctionTypeParameters() util::StringView TypedParser::FormInterfaceOrEnumDeclarationIdBinding(ir::Identifier *id) { - varbinder::TSBinding ts_binding(Allocator(), id->Name()); + binder::TSBinding ts_binding(Allocator(), id->Name()); return ts_binding.View(); } @@ -462,17 +462,17 @@ TypedParser::InterfaceId TypedParser::ParseInterfaceDeclarationId() util::StringView ident = FormInterfaceOrEnumDeclarationIdBinding(id); - const auto &bindings = VarBinder()->GetScope()->Bindings(); + const auto &bindings = Binder()->GetScope()->Bindings(); auto res = bindings.find(ident); - varbinder::InterfaceDecl *decl {}; + binder::InterfaceDecl *decl {}; bool already_exists {}; if (res == bindings.end()) { - decl = VarBinder()->AddTsDecl(Lexer()->GetToken().Start(), Allocator(), ident); + decl = Binder()->AddTsDecl(Lexer()->GetToken().Start(), Allocator(), ident); } else if (!AllowInterfaceRedeclaration()) { ThrowSyntaxError("Interface redeclaration is not allowed"); } else if (!res->second->Declaration()->IsInterfaceDecl()) { - VarBinder()->ThrowRedeclaration(Lexer()->GetToken().Start(), id->Name()); + Binder()->ThrowRedeclaration(Lexer()->GetToken().Start(), id->Name()); } else { decl = res->second->Declaration()->AsInterfaceDecl(); already_exists = true; @@ -481,7 +481,7 @@ TypedParser::InterfaceId TypedParser::ParseInterfaceDeclarationId() return {id, decl, already_exists}; } -void TypedParser::BindInterfaceDeclarationId(varbinder::InterfaceDecl *decl, bool already_exists, +void TypedParser::BindInterfaceDeclarationId(binder::InterfaceDecl *decl, bool already_exists, ir::TSInterfaceDeclaration *interface_decl) { if (!already_exists) { @@ -501,7 +501,7 @@ ir::Statement *TypedParser::ParseInterfaceDeclaration(bool is_static) auto [id, decl, alreadyExists] = ParseInterfaceDeclarationId(); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -513,8 +513,8 @@ ir::Statement *TypedParser::ParseInterfaceDeclaration(bool is_static) extends = ParseInterfaceExtendsClause(); } - auto local_scope = varbinder::LexicalScope(VarBinder()); - auto *ident_decl = VarBinder()->AddDecl(id->Start(), id->Name()); + auto local_scope = binder::LexicalScope(Binder()); + auto *ident_decl = Binder()->AddDecl(id->Start(), id->Name()); lexer::SourcePosition body_start = Lexer()->GetToken().Start(); auto members = ParseTypeLiteralOrInterface(); @@ -657,15 +657,15 @@ ir::TSEnumDeclaration *TypedParser::ParseEnumMembers(ir::Identifier *key, const while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { ir::Expression *member_key = nullptr; const auto key_start_loc = Lexer()->GetToken().Start(); - varbinder::EnumDecl *decl {}; + binder::EnumDecl *decl {}; if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { member_key = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - decl = VarBinder()->AddDecl(key_start_loc, Lexer()->GetToken().Ident()); + decl = Binder()->AddDecl(key_start_loc, Lexer()->GetToken().Ident()); member_key->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); } else if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_STRING) { - decl = VarBinder()->AddDecl(key_start_loc, Lexer()->GetToken().String()); + decl = Binder()->AddDecl(key_start_loc, Lexer()->GetToken().String()); member_key = AllocNode(Lexer()->GetToken().String()); member_key->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); @@ -692,10 +692,10 @@ ir::TSEnumDeclaration *TypedParser::ParseEnumMembers(ir::Identifier *key, const } } - auto *enum_declaration = AllocNode(Allocator(), VarBinder()->GetScope()->AsLocalScope(), key, + auto *enum_declaration = AllocNode(Allocator(), Binder()->GetScope()->AsLocalScope(), key, std::move(members), is_const); enum_declaration->SetRange({enum_start, Lexer()->GetToken().End()}); - VarBinder()->GetScope()->BindNode(enum_declaration); + Binder()->GetScope()->BindNode(enum_declaration); Lexer()->NextToken(); // eat '}' return enum_declaration; @@ -711,13 +711,13 @@ ir::Statement *TypedParser::ParseEnumDeclaration(bool is_const, [[maybe_unused]] auto *key = ExpectIdentifier(true); util::StringView ident = FormInterfaceOrEnumDeclarationIdBinding(key); - const auto &bindings = VarBinder()->GetScope()->Bindings(); + const auto &bindings = Binder()->GetScope()->Bindings(); auto res = bindings.find(ident); - varbinder::EnumLiteralDecl *decl {}; + binder::EnumLiteralDecl *decl {}; if (res == bindings.end()) { - decl = VarBinder()->AddTsDecl(Lexer()->GetToken().Start(), ident, is_const); - varbinder::LexicalScope enum_ctx = varbinder::LexicalScope(VarBinder()); + decl = Binder()->AddTsDecl(Lexer()->GetToken().Start(), ident, is_const); + binder::LexicalScope enum_ctx = binder::LexicalScope(Binder()); decl->BindScope(enum_ctx.GetScope()); auto *decl_node = ParseEnumMembers(key, enum_start, is_const, false); decl->BindNode(decl_node); @@ -726,12 +726,12 @@ ir::Statement *TypedParser::ParseEnumDeclaration(bool is_const, [[maybe_unused]] if (!res->second->Declaration()->IsEnumLiteralDecl() || (is_const ^ res->second->Declaration()->AsEnumLiteralDecl()->IsConst()) != 0) { - VarBinder()->ThrowRedeclaration(Lexer()->GetToken().Start(), key->Name()); + Binder()->ThrowRedeclaration(Lexer()->GetToken().Start(), key->Name()); } decl = res->second->Declaration()->AsEnumLiteralDecl(); - auto scope_ctx = varbinder::LexicalScope::Enter(VarBinder(), decl->Scope()); + auto scope_ctx = binder::LexicalScope::Enter(Binder(), decl->Scope()); auto *decl_node = ParseEnumMembers(key, enum_start, is_const, false); decl->BindNode(decl_node); return decl_node; @@ -757,10 +757,10 @@ ir::TSTypeParameter *TypedParser::ParseTypeParameter(TypeAnnotationParsingOption const auto &ident = Lexer()->GetToken().Ident(); auto *param_ident = AllocNode(ident, Allocator()); - varbinder::Decl *decl = nullptr; + binder::Decl *decl = nullptr; if (add_binding) { - decl = VarBinder()->AddDecl(Lexer()->GetToken().Start(), param_ident->Name()); + decl = Binder()->AddDecl(Lexer()->GetToken().Start(), param_ident->Name()); } param_ident->SetRange({Lexer()->GetToken().Start(), Lexer()->GetToken().End()}); @@ -846,10 +846,10 @@ ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeA lexer::SourcePosition end_loc = Lexer()->GetToken().End(); Lexer()->NextToken(); // eat '>' - auto *type_param_decl = AllocNode(VarBinder()->GetScope()->AsLocalScope(), + auto *type_param_decl = AllocNode(Binder()->GetScope()->AsLocalScope(), std::move(params), required_params); type_param_decl->SetRange({start_loc, end_loc}); - VarBinder()->GetScope()->BindNode(type_param_decl); + Binder()->GetScope()->BindNode(type_param_decl); return type_param_decl; } @@ -956,18 +956,18 @@ ir::ClassDefinition *TypedParser::ParseClassDefinition(ir::ClassDefinitionModifi ir::Identifier *ident_node = ParseClassIdent(modifiers); - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { auto options = TypeAnnotationParsingOptions::THROW_ERROR; type_param_decl = ParseTypeParameterDeclaration(&options); } - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); auto *ident_decl = BindClassName(ident_node); - varbinder::PrivateBinding private_binding(Allocator(), ClassId()++); - VarBinder()->AddDecl(start_loc, private_binding.View()); + binder::PrivateBinding private_binding(Allocator(), ClassId()++); + Binder()->AddDecl(start_loc, private_binding.View()); // Parse SuperClass auto [superClass, superTypeParams] = ParseSuperClass(); @@ -1273,7 +1273,7 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *type_name, if ((flags & ExpressionParseFlags::IMPORT) != 0 && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { Lexer()->NextToken(); // eat '*' - prop_name = AllocNode(varbinder::VarBinder::STAR_IMPORT, Allocator()); + prop_name = AllocNode(binder::Binder::STAR_IMPORT, Allocator()); } 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/TypedParser.h b/ets2panda/parser/TypedParser.h index 55386f4581c9b7e1e92a04bc18fe88d0812b0da7..ad1ab308a8a505c79a8728963371e6977f760f4d 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -139,10 +139,10 @@ protected: virtual util::StringView FormInterfaceOrEnumDeclarationIdBinding(ir::Identifier *id); - using InterfaceId = std::tuple; + using InterfaceId = std::tuple; InterfaceId ParseInterfaceDeclarationId(); - void BindInterfaceDeclarationId(varbinder::InterfaceDecl *decl, bool already_exists, + void BindInterfaceDeclarationId(binder::InterfaceDecl *decl, bool already_exists, ir::TSInterfaceDeclaration *interface_decl); virtual bool AllowInterfaceRedeclaration() @@ -151,7 +151,7 @@ protected: } // NOLINTNEXTLINE(google-default-arguments) - virtual void CreateCCtor([[maybe_unused]] varbinder::LocalScope *class_scope, + virtual void CreateCCtor([[maybe_unused]] binder::LocalScope *class_scope, [[maybe_unused]] ArenaVector &properties, [[maybe_unused]] const lexer::SourcePosition &loc, [[maybe_unused]] bool in_global_class = false) diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 9627a16b39b2b5da02412283c624a38776d8e20d..7849e38ab8a1a8955a0d4501feef5c9fe56019c0 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -291,9 +291,8 @@ ParserStatus ParserImpl::ValidateArrowParameter(ir::Expression *expr, [[maybe_un } ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpressionBody( - ArrowFunctionContext *arrow_function_context, varbinder::FunctionScope *function_scope, - ArrowFunctionDescriptor *desc, ir::TSTypeParameterDeclaration *type_param_decl, - ir::TypeNode *return_type_annotation) + ArrowFunctionContext *arrow_function_context, binder::FunctionScope *function_scope, ArrowFunctionDescriptor *desc, + ir::TSTypeParameterDeclaration *type_param_decl, ir::TypeNode *return_type_annotation) { context_.Status() |= desc->new_status; @@ -339,7 +338,7 @@ ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpressionBody( } ArrowFunctionDescriptor ParserImpl::ConvertToArrowParameter(ir::Expression *expr, bool is_async, - varbinder::FunctionParamScope *param_scope) + binder::FunctionParamScope *param_scope) { auto arrow_status = is_async ? ParserStatus::ASYNC_FUNCTION : ParserStatus::NO_OPTS; ArenaVector params(Allocator()->Adapter()); @@ -397,7 +396,7 @@ ArrowFunctionDescriptor ParserImpl::ConvertToArrowParameter(ir::Expression *expr } for (auto *param : params) { - VarBinder()->AddParamDecl(param); + Binder()->AddParamDecl(param); } return ArrowFunctionDescriptor {std::move(params), param_scope, expr->Start(), arrow_status}; @@ -417,11 +416,11 @@ ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpression(ir::Expres } ArrowFunctionContext arrow_function_context(this, is_async); - FunctionParameterContext function_param_context(&context_, VarBinder()); + FunctionParameterContext function_param_context(&context_, Binder()); ArrowFunctionDescriptor desc = ConvertToArrowParameter(expr, is_async, function_param_context.LexicalScope().GetScope()); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto function_ctx = binder::LexicalScope(Binder()); return ParseArrowFunctionExpressionBody(&arrow_function_context, function_ctx.GetScope(), &desc, type_param_decl, return_type_annotation); } @@ -1287,7 +1286,7 @@ ir::CallExpression *ParserImpl::ParseCallExpression(ir::Expression *callee, bool call_expr = AllocNode(callee, std::move(arguments), nullptr, is_optional_chain, parser_status); - VarBinder()->PropagateDirectEval(); + Binder()->PropagateDirectEval(); } else { call_expr = AllocNode(callee, std::move(arguments), nullptr, is_optional_chain, trailing_comma); @@ -2154,7 +2153,7 @@ ir::Expression *ParserImpl::ParseImportExpression() if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { if (!context_.IsModule()) { ThrowSyntaxError("'import.Meta' may appear only with 'sourceType: module'"); - } else if (VarBinder()->GetCompilerContext()->IsDirectEval()) { + } else if (Binder()->GetCompilerContext()->IsDirectEval()) { ThrowSyntaxError("'import.Meta' is not allowed in direct eval in module code."); } diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 13ef8c672976b2ef8786568abdee101277b7b224..14cc653c31d644c63277ce8ac1d0b659b3285a8f 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -15,9 +15,9 @@ #include "parserImpl.h" -#include "varbinder/privateBinding.h" -#include "varbinder/scope.h" -#include "varbinder/tsBinding.h" +#include "binder/privateBinding.h" +#include "binder/scope.h" +#include "binder/tsBinding.h" #include "ir/astDump.h" #include "ir/astNode.h" #include "ir/base/classDefinition.h" @@ -77,7 +77,7 @@ void ParserImpl::ParseScript(const SourceFile &source_file, bool gen_std_lib) context_.Status() |= (ParserStatus::MODULE); ParseProgram(ScriptKind::MODULE); - if (!VarBinder()->TopScope()->AsModuleScope()->ExportAnalysis()) { + if (!Binder()->TopScope()->AsModuleScope()->ExportAnalysis()) { ThrowSyntaxError("Invalid exported binding"); } } else if (gen_std_lib) { @@ -95,8 +95,8 @@ void ParserImpl::ParseProgram(ScriptKind kind) auto statements = ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); - auto *block_stmt = AllocNode(Allocator(), VarBinder()->GetScope(), std::move(statements)); - VarBinder()->GetScope()->BindNode(block_stmt); + auto *block_stmt = AllocNode(Allocator(), Binder()->GetScope(), std::move(statements)); + Binder()->GetScope()->BindNode(block_stmt); block_stmt->SetRange({start_loc, lexer_->GetToken().End()}); program_->SetAst(block_stmt); @@ -569,9 +569,9 @@ ir::ClassElement *ParserImpl::ParseClassStaticBlock() ArenaVector params(Allocator()->Adapter()); - auto func_param_ctx = varbinder::LexicalScope(VarBinder()); + auto func_param_ctx = binder::LexicalScope(Binder()); auto *func_param_scope = func_param_ctx.GetScope(); - auto func_ctx = varbinder::LexicalScope(VarBinder()); + auto func_ctx = binder::LexicalScope(Binder()); auto *func_scope = func_ctx.GetScope(); func_scope->BindParamScope(func_param_scope); @@ -654,9 +654,8 @@ ir::MethodDefinition *ParserImpl::BuildImplicitConstructor(ir::ClassDefinitionMo ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); - auto *param_scope = - VarBinder()->Allocator()->New(Allocator(), VarBinder()->GetScope()); - auto *scope = VarBinder()->Allocator()->New(Allocator(), param_scope); + auto *param_scope = Binder()->Allocator()->New(Allocator(), Binder()->GetScope()); + auto *scope = Binder()->Allocator()->New(Allocator(), param_scope); if ((modifiers & ir::ClassDefinitionModifiers::HAS_SUPER) != 0U) { util::StringView args_str = "args"; @@ -762,13 +761,13 @@ std::tuple ParserImpl::Par return {ParseSuperClassReference(), nullptr}; } -varbinder::Decl *ParserImpl::BindClassName(ir::Identifier *ident_node) +binder::Decl *ParserImpl::BindClassName(ir::Identifier *ident_node) { if (ident_node == nullptr) { return nullptr; } - return VarBinder()->AddDecl(lexer_->GetToken().Start(), ident_node->Name()); + return Binder()->AddDecl(lexer_->GetToken().Start(), ident_node->Name()); } // NOLINTNEXTLINE(google-default-arguments) @@ -777,17 +776,17 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(ir::ClassDefinitionModifie lexer::SourcePosition start_loc = lexer_->GetToken().Start(); lexer_->NextToken(); - auto class_ctx = varbinder::LexicalScope(VarBinder()); + auto class_ctx = binder::LexicalScope(Binder()); ir::Identifier *ident_node = ParseClassIdent(modifiers); if (ident_node == nullptr && (modifiers & ir::ClassDefinitionModifiers::DECLARATION) != 0U) { ThrowSyntaxError("Unexpected token, expected an identifier."); } - varbinder::Decl *ident_decl = BindClassName(ident_node); + binder::Decl *ident_decl = BindClassName(ident_node); - varbinder::PrivateBinding private_binding(Allocator(), class_id_++); - VarBinder()->AddDecl(start_loc, private_binding.View()); + binder::PrivateBinding private_binding(Allocator(), class_id_++); + Binder()->AddDecl(start_loc, private_binding.View()); // Parse SuperClass auto [superClass, superTypeParams] = ParseSuperClass(); @@ -898,7 +897,7 @@ ir::Expression *ParserImpl::CreateParameterThis([[maybe_unused]] util::StringVie std::tuple ParserImpl::ParseFunctionBody( [[maybe_unused]] const ArenaVector ¶ms, [[maybe_unused]] ParserStatus new_status, - [[maybe_unused]] ParserStatus context_status, varbinder::FunctionScope *func_scope) + [[maybe_unused]] ParserStatus context_status, binder::FunctionScope *func_scope) { if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { ThrowSyntaxError("Unexpected token, expected '{'"); @@ -911,7 +910,7 @@ std::tuple ParserImpl:: FunctionSignature ParserImpl::ParseFunctionSignature(ParserStatus status, ir::Identifier *class_name) { - auto type_params_ctx = varbinder::LexicalScope(VarBinder()); + auto type_params_ctx = binder::LexicalScope(Binder()); ir::TSTypeParameterDeclaration *type_param_decl = ParseFunctionTypeParameters(); @@ -919,7 +918,7 @@ FunctionSignature ParserImpl::ParseFunctionSignature(ParserStatus status, ir::Id ThrowSyntaxError("Unexpected token, expected '('"); } - FunctionParameterContext func_param_context(&context_, VarBinder()); + FunctionParameterContext func_param_context(&context_, Binder()); ir::Expression *parameter_this = nullptr; if (class_name != nullptr) { @@ -953,8 +952,8 @@ ir::ScriptFunction *ParserImpl::ParseFunction(ParserStatus new_status) auto [typeParamDecl, params, returnTypeAnnotation, funcParamScope, throw_marker] = ParseFunctionSignature(new_status); - auto param_ctx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); - auto function_ctx = varbinder::LexicalScope(VarBinder()); + auto param_ctx = binder::LexicalScope::Enter(Binder(), funcParamScope, false); + auto function_ctx = binder::LexicalScope(Binder()); auto *function_scope = function_ctx.GetScope(); function_scope->BindParamScope(funcParamScope); funcParamScope->BindFunctionScope(function_scope); @@ -1040,7 +1039,7 @@ ir::Expression *ParserImpl::ParseFunctionParameter() } ir::Expression *function_parameter = ParsePatternElement(ExpressionParseFlags::NO_OPTS, true); - VarBinder()->AddParamDecl(function_parameter); + Binder()->AddParamDecl(function_parameter); return function_parameter; } @@ -1222,49 +1221,48 @@ bool ParserImpl::CheckModuleAsModifier() void ExportDeclarationContext::BindExportDecl(ir::AstNode *export_decl) { - if (VarBinder() == nullptr) { + if (Binder() == nullptr) { return; } - varbinder::ModuleScope::ExportDeclList decl_list(Allocator()->Adapter()); + binder::ModuleScope::ExportDeclList decl_list(Allocator()->Adapter()); if (export_decl->IsExportDefaultDeclaration()) { auto *decl = export_decl->AsExportDefaultDeclaration(); auto *rhs = decl->Decl(); - if (VarBinder()->GetScope()->Bindings().size() == SavedBindings().size()) { + if (Binder()->GetScope()->Bindings().size() == SavedBindings().size()) { if (rhs->IsFunctionDeclaration()) { - VarBinder()->AddDecl(rhs->Start(), VarBinder()->Allocator(), - util::StringView(DEFAULT_EXPORT), - rhs->AsFunctionDeclaration()->Function()); + Binder()->AddDecl(rhs->Start(), Binder()->Allocator(), + util::StringView(DEFAULT_EXPORT), + rhs->AsFunctionDeclaration()->Function()); } else { - VarBinder()->AddDecl(rhs->Start(), util::StringView(DEFAULT_EXPORT)); + Binder()->AddDecl(rhs->Start(), util::StringView(DEFAULT_EXPORT)); } } } - for (const auto &[name, variable] : VarBinder()->GetScope()->Bindings()) { + for (const auto &[name, variable] : Binder()->GetScope()->Bindings()) { if (SavedBindings().find(name) != SavedBindings().end()) { continue; } util::StringView export_name(export_decl->IsExportDefaultDeclaration() ? "default" : name); - variable->AddFlag(varbinder::VariableFlags::LOCAL_EXPORT); - auto *decl = - VarBinder()->AddDecl(variable->Declaration()->Node()->Start(), export_name, name); + variable->AddFlag(binder::VariableFlags::LOCAL_EXPORT); + auto *decl = Binder()->AddDecl(variable->Declaration()->Node()->Start(), export_name, name); decl_list.push_back(decl); } - auto *module_scope = VarBinder()->GetScope()->AsModuleScope(); + auto *module_scope = Binder()->GetScope()->AsModuleScope(); module_scope->AddExportDecl(export_decl, std::move(decl_list)); } void ImportDeclarationContext::BindImportDecl(ir::ImportDeclaration *import_decl) { - varbinder::ModuleScope::ImportDeclList decl_list(Allocator()->Adapter()); + binder::ModuleScope::ImportDeclList decl_list(Allocator()->Adapter()); - for (const auto &[name, variable] : VarBinder()->GetScope()->Bindings()) { + for (const auto &[name, variable] : Binder()->GetScope()->Bindings()) { if (SavedBindings().find(name) != SavedBindings().end()) { continue; } @@ -1272,6 +1270,6 @@ void ImportDeclarationContext::BindImportDecl(ir::ImportDeclaration *import_decl decl_list.push_back(variable->Declaration()->AsImportDecl()); } - VarBinder()->GetScope()->AsModuleScope()->AddImportDecl(import_decl, std::move(decl_list)); + Binder()->GetScope()->AsModuleScope()->AddImportDecl(import_decl, std::move(decl_list)); } } // namespace panda::es2panda::parser diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 790d03d574ea1ae5c1cec218de5d10d37e4d46f2..66d5d46710a956e48b68dc4457956c0c06558c82 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_PARSER_CORE_PARSER_IMPL_H #define ES2PANDA_PARSER_CORE_PARSER_IMPL_H -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "es2panda.h" #include "ir/astNode.h" #include "lexer/token/sourceLocation.h" @@ -102,7 +102,7 @@ enum class CatchClauseType; namespace panda::es2panda::parser { using FunctionSignature = std::tuple, ir::TypeNode *, - varbinder::FunctionParamScope *, panda::es2panda::ir::ScriptFunctionFlags>; + binder::FunctionParamScope *, panda::es2panda::ir::ScriptFunctionFlags>; class ClassElementDescriptor { public: @@ -123,16 +123,16 @@ public: bool is_index_signature {}; bool class_method {}; bool class_field {}; - varbinder::LocalScope *static_field_scope {}; - varbinder::LocalScope *static_method_scope {}; - varbinder::LocalScope *instance_field_scope {}; - varbinder::LocalScope *instance_method_scope {}; + binder::LocalScope *static_field_scope {}; + binder::LocalScope *static_method_scope {}; + binder::LocalScope *instance_field_scope {}; + binder::LocalScope *instance_method_scope {}; // NOLINTEND(misc-non-private-member-variables-in-classes) }; class ArrowFunctionDescriptor { public: - explicit ArrowFunctionDescriptor(ArenaVector &&p, varbinder::FunctionParamScope *ps, + explicit ArrowFunctionDescriptor(ArenaVector &&p, binder::FunctionParamScope *ps, lexer::SourcePosition sl, ParserStatus ns) : params(p), param_scope(ps), start_loc(sl), new_status(ns) { @@ -140,7 +140,7 @@ public: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) ArenaVector params; - varbinder::FunctionParamScope *param_scope; + binder::FunctionParamScope *param_scope; lexer::SourcePosition start_loc; ParserStatus new_status; // NOLINTEND(misc-non-private-member-variables-in-classes) @@ -163,7 +163,6 @@ enum class TypeAnnotationParsingOptions : uint32_t { ALLOW_WILDCARD = 1U << 12U, IGNORE_FUNCTION_TYPE = 1U << 13U, ALLOW_DECLARATION_SITE_VARIANCE = 1U << 14U, - DISALLOW_UNION = 1U << 15U, }; DEFINE_BITOPS(TypeAnnotationParsingOptions) @@ -282,9 +281,9 @@ protected: return program_->Allocator(); } - varbinder::VarBinder *VarBinder() + binder::Binder *Binder() { - return program_->VarBinder(); + return program_->Binder(); } bool CheckModuleAsModifier(); @@ -298,7 +297,7 @@ protected: ir::YieldExpression *ParseYieldExpression(); virtual ir::Expression *ParsePotentialExpressionSequence(ir::Expression *expr, ExpressionParseFlags flags); ir::ArrowFunctionExpression *ParseArrowFunctionExpressionBody(ArrowFunctionContext *arrow_function_context, - varbinder::FunctionScope *function_scope, + binder::FunctionScope *function_scope, ArrowFunctionDescriptor *desc, ir::TSTypeParameterDeclaration *type_param_decl, ir::TypeNode *return_type_annotation); @@ -335,7 +334,7 @@ protected: virtual ir::Statement *ParseAssertStatement(); virtual void ValidateLabeledStatement(lexer::TokenType type); ir::BlockStatement *ParseBlockStatement(); - ir::BlockStatement *ParseBlockStatement(varbinder::Scope *scope); + ir::BlockStatement *ParseBlockStatement(binder::Scope *scope); ir::EmptyStatement *ParseEmptyStatement(); ir::Statement *ParseForStatement(); ir::IfStatement *ParseIfStatement(); @@ -483,7 +482,7 @@ protected: virtual ir::ClassElement *ParseClassStaticBlock(); virtual ParserStatus ValidateArrowParameter(ir::Expression *expr, bool *seen_optional); virtual ArrowFunctionDescriptor ConvertToArrowParameter(ir::Expression *expr, bool is_async, - varbinder::FunctionParamScope *param_scope); + binder::FunctionParamScope *param_scope); virtual ir::Expression *ParseNewExpression(); virtual ir::TSTypeParameterDeclaration *ParseFunctionTypeParameters() @@ -503,7 +502,7 @@ protected: virtual std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, - varbinder::FunctionScope *func_scope); + binder::FunctionScope *func_scope); virtual ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers); virtual ir::Statement *ParseExportDeclaration(StatementParsingFlags flags); @@ -540,7 +539,7 @@ protected: ClassBody ParseClassBody(ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags flags = ir::ModifierFlags::NONE, ir::Identifier *ident_node = nullptr); - virtual varbinder::Decl *BindClassName(ir::Identifier *ident_node); + virtual binder::Decl *BindClassName(ir::Identifier *ident_node); Program *GetProgram() const { @@ -631,8 +630,8 @@ public: template class IterationContext : public SavedStatusContext { public: - explicit IterationContext(ParserContext *ctx, varbinder::VarBinder *varbinder) - : SavedStatusContext(ctx), lexical_scope_(varbinder) + explicit IterationContext(ParserContext *ctx, binder::Binder *binder) + : SavedStatusContext(ctx), lexical_scope_(binder) { } @@ -646,13 +645,13 @@ public: } private: - varbinder::LexicalScope lexical_scope_; + binder::LexicalScope lexical_scope_; }; class FunctionParameterContext : public SavedStatusContext { public: - explicit FunctionParameterContext(ParserContext *ctx, varbinder::VarBinder *varbinder) - : SavedStatusContext(ctx), lexical_scope_(varbinder) + explicit FunctionParameterContext(ParserContext *ctx, binder::Binder *binder) + : SavedStatusContext(ctx), lexical_scope_(binder) { } @@ -666,7 +665,7 @@ public: ~FunctionParameterContext() = default; private: - varbinder::LexicalScope lexical_scope_; + binder::LexicalScope lexical_scope_; }; class SavedParserContext { @@ -686,9 +685,9 @@ public: } protected: - varbinder::VarBinder *VarBinder() + binder::Binder *Binder() { - return parser_->VarBinder(); + return parser_->Binder(); } private: @@ -777,8 +776,8 @@ private: class SavedBindingsContext { public: - explicit SavedBindingsContext(varbinder::VarBinder *varbinder) - : varbinder_(varbinder), saved_bindings_(varbinder_->GetScope()->Bindings()) + explicit SavedBindingsContext(binder::Binder *binder) + : binder_(binder), saved_bindings_(binder_->GetScope()->Bindings()) { } NO_COPY_SEMANTIC(SavedBindingsContext); @@ -788,27 +787,27 @@ public: protected: ArenaAllocator *Allocator() const { - return varbinder_->Allocator(); + return binder_->Allocator(); } - varbinder::VarBinder *VarBinder() const + binder::Binder *Binder() const { - return varbinder_; + return binder_; } - varbinder::Scope::VariableMap SavedBindings() const + binder::Scope::VariableMap SavedBindings() const { return saved_bindings_; } private: - varbinder::VarBinder *varbinder_; - varbinder::Scope::VariableMap saved_bindings_; + binder::Binder *binder_; + binder::Scope::VariableMap saved_bindings_; }; class ExportDeclarationContext : public SavedBindingsContext { public: - explicit ExportDeclarationContext(varbinder::VarBinder *varbinder) : SavedBindingsContext(varbinder) {} + explicit ExportDeclarationContext(binder::Binder *binder) : SavedBindingsContext(binder) {} NO_COPY_SEMANTIC(ExportDeclarationContext); NO_MOVE_SEMANTIC(ExportDeclarationContext); ~ExportDeclarationContext() = default; @@ -821,7 +820,7 @@ protected: class ImportDeclarationContext : public SavedBindingsContext { public: - explicit ImportDeclarationContext(varbinder::VarBinder *varbinder) : SavedBindingsContext(varbinder) {} + explicit ImportDeclarationContext(binder::Binder *binder) : SavedBindingsContext(binder) {} NO_COPY_SEMANTIC(ImportDeclarationContext); NO_MOVE_SEMANTIC(ImportDeclarationContext); diff --git a/ets2panda/parser/program/program.cpp b/ets2panda/parser/program/program.cpp index 1ab75d6854366725f90a248146a897c3e21f23bc..f6ec7d2bace95237dbc1488a1bad67e847538669 100644 --- a/ets2panda/parser/program/program.cpp +++ b/ets2panda/parser/program/program.cpp @@ -15,8 +15,8 @@ #include "program.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" +#include "binder/binder.h" +#include "binder/ETSBinder.h" #include "ir/astDump.h" #include "ir/base/classDefinition.h" #include "ir/statements/blockStatement.h" @@ -41,26 +41,26 @@ util::StringView Program::PackageClassName(util::StringView class_name) return name.View(); } -varbinder::ClassScope *Program::GlobalClassScope() +binder::ClassScope *Program::GlobalClassScope() { return global_class_->Scope()->AsClassScope(); } -const varbinder::ClassScope *Program::GlobalClassScope() const +const binder::ClassScope *Program::GlobalClassScope() const { return global_class_->Scope()->AsClassScope(); } -varbinder::GlobalScope *Program::GlobalScope() +binder::GlobalScope *Program::GlobalScope() { ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); - return static_cast(ast_->Scope()); + return static_cast(ast_->Scope()); } -const varbinder::GlobalScope *Program::GlobalScope() const +const binder::GlobalScope *Program::GlobalScope() const { ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); - return static_cast(ast_->Scope()); + return static_cast(ast_->Scope()); } } // namespace panda::es2panda::parser diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index c1331188946169e250b2d3e2192406ca41d8324a..4f10782903955fec60aae2758064e9be2f928140 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -20,7 +20,7 @@ #include "mem/pool_manager.h" #include "os/filesystem.h" #include "util/ustring.h" -#include "varbinder/varbinder.h" +#include "binder/binder.h" #include "es2panda.h" @@ -28,9 +28,9 @@ namespace panda::es2panda::ir { class BlockStatement; } // namespace panda::es2panda::ir -namespace panda::es2panda::varbinder { -class VarBinder; -} // namespace panda::es2panda::varbinder +namespace panda::es2panda::binder { +class Binder; +} // namespace panda::es2panda::binder namespace panda::es2panda::parser { enum class ScriptKind { SCRIPT, MODULE, STDLIB }; @@ -41,22 +41,22 @@ public: template static Program NewProgram(ArenaAllocator *allocator) { - auto *varbinder = allocator->New(allocator); - return Program(allocator, varbinder); + auto *binder = allocator->New(allocator); + return Program(allocator, binder); } - Program(ArenaAllocator *allocator, varbinder::VarBinder *varbinder) + Program(ArenaAllocator *allocator, binder::Binder *binder) : allocator_(allocator), - varbinder_(varbinder), + binder_(binder), external_sources_(allocator_->Adapter()), - extension_(varbinder->Extension()) + extension_(binder->Extension()) { } void SetKind(ScriptKind kind) { kind_ = kind; - varbinder_->InitTopScope(); + binder_->InitTopScope(); } NO_COPY_SEMANTIC(Program); @@ -69,14 +69,14 @@ public: return allocator_; } - const varbinder::VarBinder *VarBinder() const + const binder::Binder *Binder() const { - return varbinder_; + return binder_; } - varbinder::VarBinder *VarBinder() + binder::Binder *Binder() { - return varbinder_; + return binder_; } ScriptExtension Extension() const @@ -207,11 +207,11 @@ public: entry_point_ = true; } - varbinder::ClassScope *GlobalClassScope(); - const varbinder::ClassScope *GlobalClassScope() const; + binder::ClassScope *GlobalClassScope(); + const binder::ClassScope *GlobalClassScope() const; - varbinder::GlobalScope *GlobalScope(); - const varbinder::GlobalScope *GlobalScope() const; + binder::GlobalScope *GlobalScope(); + const binder::GlobalScope *GlobalScope() const; util::StringView PackageClassName(util::StringView class_name); @@ -219,7 +219,7 @@ public: private: ArenaAllocator *allocator_ {}; - varbinder::VarBinder *varbinder_ {}; + binder::Binder *binder_ {}; ir::BlockStatement *ast_ {}; ir::ClassDefinition *global_class_ {}; util::StringView source_code_ {}; diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index 0784b0c5d7980a1d5e787ea08cbfe342600cba30..5103ec040d3f1c176b4300f08cd4dbe4dad0f221 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -15,7 +15,7 @@ #include "parser/parserFlags.h" #include "util/helpers.h" -#include "varbinder/tsBinding.h" +#include "binder/tsBinding.h" #include "ir/astNode.h" #include "ir/base/catchClause.h" #include "ir/base/classDefinition.h" @@ -229,7 +229,7 @@ ir::Statement *ParserImpl::ParseFunctionStatement(StatementParsingFlags flags) return ParseFunctionDeclaration(false, ParserStatus::NO_OPTS); } - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); ArenaVector stmts(Allocator()->Adapter()); auto *func_decl = ParseFunctionDeclaration(false, ParserStatus::NO_OPTS); stmts.push_back(func_decl); @@ -309,9 +309,9 @@ ir::ClassDefinition *ParserImpl::GetAndBindClassDefinition(ir::ClassDefinitionMo util::StringView class_name = ident->Name(); if ((modifiers & ir::ClassDefinitionModifiers::CLASS_DECL) != 0U) { - VarBinder()->AddDecl(ident->Start(), class_name, class_definition); + Binder()->AddDecl(ident->Start(), class_name, class_definition); } else { - VarBinder()->AddDecl(ident->Start(), class_name, class_definition); + Binder()->AddDecl(ident->Start(), class_name, class_definition); } return class_definition; @@ -411,7 +411,7 @@ ir::Statement *ParserImpl::ParseAssertStatement() void ParserImpl::ValidateLabeledStatement([[maybe_unused]] lexer::TokenType type) {} -ir::BlockStatement *ParserImpl::ParseBlockStatement(varbinder::Scope *scope) +ir::BlockStatement *ParserImpl::ParseBlockStatement(binder::Scope *scope) { ASSERT(lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE); @@ -433,7 +433,7 @@ ir::BlockStatement *ParserImpl::ParseBlockStatement(varbinder::Scope *scope) ir::BlockStatement *ParserImpl::ParseBlockStatement() { - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); return ParseBlockStatement(local_ctx.GetScope()); } @@ -549,7 +549,7 @@ ir::ContinueStatement *ParserImpl::ParseContinueStatement() ir::DoWhileStatement *ParserImpl::ParseDoWhileStatement() { - IterationContext iter_ctx(&context_, VarBinder()); + IterationContext iter_ctx(&context_, Binder()); lexer::SourcePosition start_loc = lexer_->GetToken().Start(); lexer_->NextToken(); @@ -589,7 +589,7 @@ ir::DoWhileStatement *ParserImpl::ParseDoWhileStatement() void ParserImpl::CreateFunctionDeclaration(ir::Identifier *ident_node, util::StringView &name, ir::ScriptFunction *func, [[maybe_unused]] const lexer::SourcePosition &start_loc) { - VarBinder()->AddDecl(ident_node->Start(), Allocator(), name, func); + Binder()->AddDecl(ident_node->Start(), Allocator(), name, func); } ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool can_be_anonymous, ParserStatus new_status) @@ -904,7 +904,7 @@ ir::Statement *ParserImpl::ParseForStatement() token_type != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS && token_type != lexer::TokenType::EOS); lexer_->Rewind(current_position); - auto decl_ctx = varbinder::LexicalScope(VarBinder()); + auto decl_ctx = binder::LexicalScope(Binder()); switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_VAR: { @@ -935,7 +935,7 @@ ir::Statement *ParserImpl::ParseForStatement() } } - IterationContext iter_ctx(&context_, VarBinder()); + IterationContext iter_ctx(&context_, Binder()); iter_ctx.LexicalScope().GetScope()->BindDecls(decl_ctx.GetScope()); if (init_node != nullptr) { @@ -1164,7 +1164,7 @@ ir::SwitchStatement *ParserImpl::ParseSwitchStatement() lexer_->NextToken(); bool seen_default = false; - auto local_ctx = varbinder::LexicalScope(VarBinder()); + auto local_ctx = binder::LexicalScope(Binder()); ArenaVector cases(Allocator()->Adapter()); while (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { @@ -1227,7 +1227,7 @@ ir::Expression *ParserImpl::ParseCatchParam() ThrowSyntaxError("Unexpected token in catch parameter"); } - auto param_decl = VarBinder()->AddParamDecl(param); + auto param_decl = Binder()->AddParamDecl(param); if (param->IsIdentifier()) { param->AsIdentifier()->SetVariable(std::get<1>(param_decl)); @@ -1249,7 +1249,7 @@ ir::CatchClause *ParserImpl::ParseCatchClause() lexer::SourcePosition catch_start_loc = lexer_->GetToken().Start(); lexer_->NextToken(); // eat 'catch' keyword - auto catch_param_ctx = varbinder::LexicalScope(VarBinder()); + auto catch_param_ctx = binder::LexicalScope(Binder()); auto *catch_param_scope = catch_param_ctx.GetScope(); ir::Expression *param = ParseCatchParam(); @@ -1262,7 +1262,7 @@ ir::CatchClause *ParserImpl::ParseCatchClause() ThrowSyntaxError("Unexpected token, expected '{'"); } - auto catch_ctx = varbinder::LexicalScope(VarBinder()); + auto catch_ctx = binder::LexicalScope(Binder()); auto *catch_scope = catch_ctx.GetScope(); catch_scope->AssignParamScope(catch_param_scope); @@ -1363,14 +1363,14 @@ void ParserImpl::AddVariableDeclarationBindings(ir::Expression *init, lexer::Sou std::vector bindings = util::Helpers::CollectBindingNames(init); for (const auto *binding : bindings) { - varbinder::Decl *decl = nullptr; + binder::Decl *decl = nullptr; if ((flags & VariableParsingFlags::VAR) != 0U) { - decl = VarBinder()->AddDecl(start_loc, binding->Name()); + decl = Binder()->AddDecl(start_loc, binding->Name()); } else if ((flags & VariableParsingFlags::LET) != 0U) { - decl = VarBinder()->AddDecl(start_loc, binding->Name()); + decl = Binder()->AddDecl(start_loc, binding->Name()); } else { - decl = VarBinder()->AddDecl(start_loc, binding->Name()); + decl = Binder()->AddDecl(start_loc, binding->Name()); } decl->BindNode(init); @@ -1497,7 +1497,7 @@ ir::WhileStatement *ParserImpl::ParseWhileStatement() } lexer_->NextToken(); - IterationContext iter_ctx(&context_, VarBinder()); + IterationContext iter_ctx(&context_, Binder()); ir::Statement *body = ParseStatement(); lexer::SourcePosition end_loc = body->End(); @@ -1517,7 +1517,7 @@ ir::ExportDefaultDeclaration *ParserImpl::ParseExportDefaultDeclaration(const le ir::AstNode *decl_node = nullptr; bool eat_semicolon = false; - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_FUNCTION: { @@ -1604,9 +1604,8 @@ ir::ExportAllDeclaration *ParserImpl::ParseExportAllDeclaration(const lexer::Sou auto *export_declaration = AllocNode(source, exported); export_declaration->SetRange({start_loc, end_loc}); - auto *decl = - VarBinder()->AddDecl(start_loc, exported != nullptr ? exported->Name() : "*", "*"); - VarBinder()->GetScope()->AsModuleScope()->AddExportDecl(export_declaration, decl); + auto *decl = Binder()->AddDecl(start_loc, exported != nullptr ? exported->Name() : "*", "*"); + Binder()->GetScope()->AsModuleScope()->AddExportDecl(export_declaration, decl); ConsumeSemicolon(export_declaration); @@ -1618,7 +1617,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseExportNamedSpecifiers(const lexer:: lexer_->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); // eat `{` character ArenaVector specifiers(Allocator()->Adapter()); - varbinder::ModuleScope::ExportDeclList export_decls(Allocator()->Adapter()); + binder::ModuleScope::ExportDeclList export_decls(Allocator()->Adapter()); while (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { @@ -1645,7 +1644,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseExportNamedSpecifiers(const lexer:: specifier->SetRange({local->Start(), exported->End()}); specifiers.push_back(specifier); - auto *decl = VarBinder()->AddDecl(start_loc, exported->Name(), local->Name(), specifier); + auto *decl = Binder()->AddDecl(start_loc, exported->Name(), local->Name(), specifier); export_decls.push_back(decl); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { @@ -1664,7 +1663,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseExportNamedSpecifiers(const lexer:: auto *export_declaration = AllocNode(Allocator(), source, std::move(specifiers)); export_declaration->SetRange({start_loc, end_pos}); - VarBinder()->GetScope()->AsModuleScope()->AddExportDecl(export_declaration, std::move(export_decls)); + Binder()->GetScope()->AsModuleScope()->AddExportDecl(export_declaration, std::move(export_decls)); ConsumeSemicolon(export_declaration); return export_declaration; @@ -1673,7 +1672,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseExportNamedSpecifiers(const lexer:: ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer::SourcePosition &start_loc) { ir::Statement *decl = nullptr; - ExportDeclarationContext export_decl_ctx(VarBinder()); + ExportDeclarationContext export_decl_ctx(Binder()); switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_VAR: { @@ -1772,7 +1771,7 @@ void ParserImpl::ParseNameSpaceImport(ArenaVector *specifiers) specifier->SetRange({namespace_start, lexer_->GetToken().End()}); specifiers->push_back(specifier); - VarBinder()->AddDecl(namespace_start, "*", local->Name(), specifier); + Binder()->AddDecl(namespace_start, "*", local->Name(), specifier); lexer_->NextToken(); // eat local name } @@ -1819,7 +1818,7 @@ void ParserImpl::ParseNamedImportSpecifiers(ArenaVector *specifie specifier->SetRange({imported->Start(), local->End()}); specifiers->push_back(specifier); - VarBinder()->AddDecl(imported->Start(), imported->Name(), local->Name(), specifier); + Binder()->AddDecl(imported->Start(), imported->Name(), local->Name(), specifier); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { lexer_->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); // eat comma @@ -1838,7 +1837,7 @@ ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector specifier->SetRange(specifier->Local()->Range()); specifiers->push_back(specifier); - VarBinder()->AddDecl(local->Start(), "default", local->Name(), specifier); + Binder()->AddDecl(local->Start(), "default", local->Name(), specifier); lexer_->NextToken(); // eat specifier name @@ -1895,7 +1894,7 @@ ir::AstNode *ParserImpl::ParseImportSpecifiers(ArenaVector *speci ir::Statement *ParserImpl::ParseImportDeclaration(StatementParsingFlags flags) { - ImportDeclarationContext import_ctx(VarBinder()); + ImportDeclarationContext import_ctx(Binder()); if ((flags & StatementParsingFlags::GLOBAL) == 0) { ThrowSyntaxError("'import' and 'export' may only appear at the top level"); diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 690e286a0308e2290f14e82bf9ab937b44e0852e..f8fe8ab3aad6323162684a70a4eff9ac03f6f4b8 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -19,7 +19,7 @@ #include "generated/signatures.h" #include "es2panda.h" #include "assembler/assembly-program.h" -#include "varbinder/ETSBinder.h" +#include "binder/ETSBinder.h" #include "checker/ETSAnalyzer.h" #include "checker/ETSchecker.h" #include "compiler/core/compileQueue.h" @@ -70,7 +70,7 @@ extern "C" es2panda_Config *CreateConfig(int args, char const **argv) auto options = std::make_unique(); if (!options->Parse(args, argv)) { - // NOTE: gogabr. report option errors properly. + // TODO(gogabr): report option errors properly. std::cerr << options->ErrorMsg() << std::endl; return nullptr; } @@ -91,7 +91,7 @@ extern "C" void DestroyConfig(es2panda_Config *config) delete reinterpret_cast(config); } -static void CompileJob(compiler::CompilerContext *context, varbinder::FunctionScope *scope, +static void CompileJob(compiler::CompilerContext *context, binder::FunctionScope *scope, compiler::ProgramElement *program_element) { compiler::StaticRegSpiller reg_spiller; @@ -116,8 +116,8 @@ static es2panda_Context *CreateContext(es2panda_Config *config, std::string cons res->allocator = std::make_unique(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); res->queue = std::make_unique(cfg->options->ThreadCount()); - auto *varbinder = res->allocator->New(res->allocator.get()); - res->parser_program = std::make_unique(res->allocator.get(), varbinder); + auto *binder = res->allocator->New(res->allocator.get()); + res->parser_program = std::make_unique(res->allocator.get(), binder); res->parser_program->MarkEntry(); res->parser = std::make_unique(res->parser_program.get(), cfg->options->CompilerOptions(), parser::ParserStatus::NO_OPTS); @@ -125,11 +125,11 @@ static es2panda_Context *CreateContext(es2panda_Config *config, std::string cons res->analyzer = std::make_unique(res->checker.get()); res->checker->SetAnalyzer(res->analyzer.get()); - varbinder->SetProgram(res->parser_program.get()); + binder->SetProgram(res->parser_program.get()); res->compiler_context = std::make_unique( - varbinder, res->checker.get(), cfg->options->CompilerOptions(), CompileJob); - varbinder->SetCompilerContext(res->compiler_context.get()); + binder, res->checker.get(), cfg->options->CompilerOptions(), CompileJob); + binder->SetCompilerContext(res->compiler_context.get()); res->emitter = std::make_unique(res->compiler_context.get()); res->compiler_context->SetEmitter(res->emitter.get()); res->program = nullptr; @@ -166,7 +166,7 @@ extern "C" es2panda_Context *CreateContextFromFile(es2panda_Config *config, char extern "C" es2panda_Context *CreateContextFromString(es2panda_Config *config, char const *source, char const *file_name) { - // NOTE: gogabr. avoid copying source. + // TODO(gogabr): avoid copying source. return CreateContext(config, source, file_name); } @@ -204,7 +204,7 @@ static Context *Check(Context *ctx) ASSERT(ctx->state == ES2PANDA_STATE_PARSED); try { - ctx->compiler_context->Checker()->StartChecker(ctx->compiler_context->VarBinder(), + ctx->compiler_context->Checker()->StartChecker(ctx->compiler_context->Binder(), ctx->config->options->CompilerOptions()); ctx->state = ES2PANDA_STATE_CHECKED; } catch (Error &e) { @@ -230,7 +230,7 @@ static Context *Lower(Context *ctx) try { for (auto *phase : compiler::GetETSPhaseList()) { - phase->Apply(ctx->compiler_context.get(), ctx->compiler_context->VarBinder()->Program()); + phase->Apply(ctx->compiler_context.get(), ctx->compiler_context->Binder()->Program()); } ctx->state = ES2PANDA_STATE_LOWERED; diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index 0873d590d993b9d6a870de63814f4996ff94d096..4023344201c0d8bb5e315d1d075e0fece2dbddef 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/scripts/test-runner.py b/ets2panda/scripts/test-runner.py index aeb156848f822ac79e6cab0d12ced34baa4f6618..0801e51930f0819fa6d74a2f4bfe823c8366423f 100644 --- a/ets2panda/scripts/test-runner.py +++ b/ets2panda/scripts/test-runner.py @@ -1,4 +1,4 @@ -#/usr/bin/env python +#!/usr/bin/env python # Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ import subprocess import sys from pathlib import Path -def parse_options(): +def parseOptions(): # panda root default panda_env = os.environ.get('PANDA_ROOT') arkdir_default = panda_env if panda_env else os.path.join(Path.home(), 'panda') @@ -43,9 +43,8 @@ def parse_options(): return parser.parse_args() - def main(): - options = parse_options() + options = parseOptions() if not os.path.exists(options.arkdir): print("The following ark directory does not exist: {0}".format(options.arkdir)) @@ -77,6 +76,5 @@ def main(): if options.cts: res = subprocess.call(general_cmd + ['--ets-cts']) - if __name__ == '__main__': main() diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index ff14df7c4ae66ff22c3618052179032ef05d69e4..f40aed24be528f99fc880954a9bb04380f30fce6 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -92,17 +92,5 @@ if(PANDA_WITH_ETS) add_dependencies(ets_tests es2panda_tests) endif() - panda_add_gtest( - NAME es2panda_astverifier_tests - SOURCES - public/ast_verifier_test.cpp - LIBRARIES - es2panda-lib - INCLUDE_DIRS - ${ES2PANDA_PATH} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - add_subdirectory(tsconfig) endif() diff --git a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt index ab661e0a090c8b29e226e770f365520e37552e2e..e902bdbdba6b18c5653e8f9385f15b4f1f1e1952 100644 --- a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt +++ b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt @@ -1256,60 +1256,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 31 - }, - "end": { - "line": 29, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 31 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 37 - }, - "end": { - "line": 29, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 37 - }, - "end": { - "line": 29, - "column": 39 - } - } - }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 29, @@ -1317,45 +1292,55 @@ }, "end": { "line": 29, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 36 + "column": 37 }, "end": { "line": 29, "column": 39 } } - }, - "loc": { - "start": { - "line": 29, - "column": 31 - }, - "end": { - "line": 29, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 31 + "column": 36 }, "end": { "line": 29, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 29, @@ -2047,38 +2032,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 43 - }, - "end": { - "line": 31, - "column": 44 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 43 - }, - "end": { - "line": 31, - "column": 46 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 31, @@ -2086,11 +2046,21 @@ }, "end": { "line": 31, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 31, + "column": 43 + }, + "end": { + "line": 31, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 31, @@ -2767,60 +2737,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 45 - }, - "end": { - "line": 33, - "column": 50 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 45 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 51 - }, - "end": { - "line": 33, - "column": 52 - } - } - }, - "loc": { - "start": { - "line": 33, - "column": 51 - }, - "end": { - "line": 33, - "column": 53 - } - } - }, + "end": { + "line": 33, + "column": 50 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 33, @@ -2828,45 +2773,55 @@ }, "end": { "line": 33, - "column": 53 + "column": 52 } } + }, + "loc": { + "start": { + "line": 33, + "column": 51 + }, + "end": { + "line": 33, + "column": 53 + } } - ], + }, "loc": { "start": { "line": 33, - "column": 50 + "column": 51 }, "end": { "line": 33, "column": 53 } } - }, - "loc": { - "start": { - "line": 33, - "column": 45 - }, - "end": { - "line": 33, - "column": 55 - } } - }, + ], "loc": { "start": { "line": 33, - "column": 45 + "column": 50 }, "end": { "line": 33, - "column": 55 + "column": 53 } } + }, + "loc": { + "start": { + "line": 33, + "column": 45 + }, + "end": { + "line": 33, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 33, @@ -3155,60 +3110,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 53 - }, - "end": { - "line": 34, - "column": 58 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 53 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 59 - }, - "end": { - "line": 34, - "column": 60 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 59 - }, - "end": { - "line": 34, - "column": 61 - } - } - }, + "end": { + "line": 34, + "column": 58 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 34, @@ -3216,45 +3146,55 @@ }, "end": { "line": 34, - "column": 61 + "column": 60 } } + }, + "loc": { + "start": { + "line": 34, + "column": 59 + }, + "end": { + "line": 34, + "column": 61 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 58 + "column": 59 }, "end": { "line": 34, "column": 61 } } - }, - "loc": { - "start": { - "line": 34, - "column": 53 - }, - "end": { - "line": 34, - "column": 63 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 53 + "column": 58 }, "end": { "line": 34, - "column": 63 + "column": 61 } } + }, + "loc": { + "start": { + "line": 34, + "column": 53 + }, + "end": { + "line": 34, + "column": 63 + } } - ], + }, "loc": { "start": { "line": 34, @@ -3651,38 +3591,13 @@ "type": "Identifier", "name": "val", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 38 - }, - "end": { - "line": 39, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 38 - }, - "end": { - "line": 39, - "column": 41 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 39, @@ -3690,11 +3605,21 @@ }, "end": { "line": 39, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 39, + "column": 38 + }, + "end": { + "line": 39, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 39, @@ -11455,60 +11380,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 141, - "column": 47 - }, - "end": { - "line": 141, - "column": 52 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 141, + "column": 47 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 141, - "column": 53 - }, - "end": { - "line": 141, - "column": 54 - } - } - }, - "loc": { - "start": { - "line": 141, - "column": 53 - }, - "end": { - "line": 141, - "column": 55 - } - } - }, + "end": { + "line": 141, + "column": 52 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 141, @@ -11516,45 +11416,55 @@ }, "end": { "line": 141, - "column": 55 + "column": 54 } } + }, + "loc": { + "start": { + "line": 141, + "column": 53 + }, + "end": { + "line": 141, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 141, - "column": 52 + "column": 53 }, "end": { "line": 141, "column": 55 } } - }, - "loc": { - "start": { - "line": 141, - "column": 47 - }, - "end": { - "line": 141, - "column": 57 - } } - }, + ], "loc": { "start": { "line": 141, - "column": 47 + "column": 52 }, "end": { "line": 141, - "column": 57 + "column": 55 } } + }, + "loc": { + "start": { + "line": 141, + "column": 47 + }, + "end": { + "line": 141, + "column": 57 + } } - ], + }, "loc": { "start": { "line": 141, @@ -13216,64 +13126,39 @@ "column": 57 } } - }, - "decorators": [], - "loc": { - "start": { - "line": 156, - "column": 26 - }, - "end": { - "line": 156, - "column": 57 - } - } - }, - "loc": { - "start": { - "line": 156, - "column": 26 - }, - "end": { - "line": 156, - "column": 57 - } - } - } - ], - "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 156, - "column": 59 - }, - "end": { - "line": 156, - "column": 60 - } - } - }, - "loc": { - "start": { - "line": 156, - "column": 59 - }, - "end": { - "line": 156, - "column": 62 - } + }, + "decorators": [], + "loc": { + "start": { + "line": 156, + "column": 26 + }, + "end": { + "line": 156, + "column": 57 } + } + }, + "loc": { + "start": { + "line": 156, + "column": 26 }, + "end": { + "line": 156, + "column": 57 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 156, @@ -13281,11 +13166,21 @@ }, "end": { "line": 156, - "column": 62 + "column": 60 } } + }, + "loc": { + "start": { + "line": 156, + "column": 59 + }, + "end": { + "line": 156, + "column": 62 + } } - ], + }, "loc": { "start": { "line": 156, @@ -15187,60 +15082,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 178, - "column": 60 - }, - "end": { - "line": 178, - "column": 72 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArrayAsListt", + "decorators": [], + "loc": { + "start": { + "line": 178, + "column": 60 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 178, - "column": 73 - }, - "end": { - "line": 178, - "column": 74 - } - } - }, - "loc": { - "start": { - "line": 178, - "column": 73 - }, - "end": { - "line": 178, - "column": 75 - } - } - }, + "end": { + "line": 178, + "column": 72 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 178, @@ -15248,45 +15118,55 @@ }, "end": { "line": 178, - "column": 75 + "column": 74 } } + }, + "loc": { + "start": { + "line": 178, + "column": 73 + }, + "end": { + "line": 178, + "column": 75 + } } - ], + }, "loc": { "start": { "line": 178, - "column": 72 + "column": 73 }, "end": { "line": 178, "column": 75 } } - }, - "loc": { - "start": { - "line": 178, - "column": 60 - }, - "end": { - "line": 178, - "column": 77 - } } - }, + ], "loc": { "start": { "line": 178, - "column": 60 + "column": 72 }, "end": { "line": 178, - "column": 77 + "column": 75 } } + }, + "loc": { + "start": { + "line": 178, + "column": 60 + }, + "end": { + "line": 178, + "column": 77 + } } - ], + }, "loc": { "start": { "line": 178, @@ -16988,60 +16868,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 198, - "column": 68 - }, - "end": { - "line": 198, - "column": 80 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArrayAsListt", + "decorators": [], + "loc": { + "start": { + "line": 198, + "column": 68 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 198, - "column": 81 - }, - "end": { - "line": 198, - "column": 82 - } - } - }, - "loc": { - "start": { - "line": 198, - "column": 81 - }, - "end": { - "line": 198, - "column": 83 - } - } - }, + "end": { + "line": 198, + "column": 80 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 198, @@ -17049,45 +16904,55 @@ }, "end": { "line": 198, - "column": 83 + "column": 82 } } + }, + "loc": { + "start": { + "line": 198, + "column": 81 + }, + "end": { + "line": 198, + "column": 83 + } } - ], + }, "loc": { "start": { "line": 198, - "column": 80 + "column": 81 }, "end": { "line": 198, "column": 83 } } - }, - "loc": { - "start": { - "line": 198, - "column": 68 - }, - "end": { - "line": 198, - "column": 85 - } } - }, + ], "loc": { "start": { "line": 198, - "column": 68 + "column": 80 }, "end": { "line": 198, - "column": 85 + "column": 83 } } + }, + "loc": { + "start": { + "line": 198, + "column": 68 + }, + "end": { + "line": 198, + "column": 85 + } } - ], + }, "loc": { "start": { "line": 198, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt index 02c29ecade92aef99ff48385e2c94c85e9d5c0d8..9378ef0aa26c2df1f48d9148668533fa64f723af 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt @@ -111,60 +111,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 19 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 22 - } - } - }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], "loc": { "start": { "line": 17, @@ -172,45 +147,55 @@ }, "end": { "line": 17, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 19 + "column": 20 }, "end": { "line": 17, "column": 22 } } - }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 16 + "column": 19 }, "end": { "line": 17, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 17, @@ -645,60 +630,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 13 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 16 - } - } - }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 25, @@ -706,45 +666,55 @@ }, "end": { "line": 25, - "column": 16 + "column": 15 } } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 25, - "column": 13 + "column": 14 }, "end": { "line": 25, "column": 16 } } - }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 18 - } } - }, + ], "loc": { "start": { "line": 25, - "column": 12 + "column": 13 }, "end": { "line": 25, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 25, @@ -879,60 +849,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 15 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 18 - } - } - }, + "end": { + "line": 29, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 29, @@ -940,45 +885,55 @@ }, "end": { "line": 29, - "column": 18 + "column": 17 } } + }, + "loc": { + "start": { + "line": 29, + "column": 16 + }, + "end": { + "line": 29, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 15 + "column": 16 }, "end": { "line": 29, "column": 18 } } - }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 20 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 12 + "column": 15 }, "end": { "line": 29, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1522,60 +1477,35 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 16 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 17 - }, - "end": { - "line": 35, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 17 - }, - "end": { - "line": 35, - "column": 24 - } - } - }, + "end": { + "line": 35, + "column": 16 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 35, @@ -1583,45 +1513,55 @@ }, "end": { "line": 35, - "column": 24 + "column": 23 } } + }, + "loc": { + "start": { + "line": 35, + "column": 17 + }, + "end": { + "line": 35, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 35, - "column": 16 + "column": 17 }, "end": { "line": 35, "column": 24 } } - }, - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 26 - } } - }, + ], "loc": { "start": { "line": 35, - "column": 13 + "column": 16 }, "end": { "line": 35, - "column": 26 + "column": 24 } } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 26 + } } - ], + }, "loc": { "start": { "line": 35, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt index 5d98ea0792711bf974f51c431933684fce731e53..4d568d9bcf9474a674492185989acb10183bb7d9 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt @@ -1199,60 +1199,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 31, - "column": 13 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 16 - } - } - }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 31, @@ -1260,45 +1235,55 @@ }, "end": { "line": 31, - "column": 16 + "column": 15 } } + }, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 31, - "column": 13 + "column": 14 }, "end": { "line": 31, "column": 16 } } - }, - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 31, - "column": 18 - } } - }, + ], "loc": { "start": { "line": 31, - "column": 12 + "column": 13 }, "end": { "line": 31, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 31, @@ -1683,60 +1668,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 22 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 21 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 23 - }, - "end": { - "line": 37, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 23 - }, - "end": { - "line": 37, - "column": 25 - } - } - }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], "loc": { "start": { "line": 37, @@ -1744,45 +1704,55 @@ }, "end": { "line": 37, - "column": 25 + "column": 24 } } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 25 + } } - ], + }, "loc": { "start": { "line": 37, - "column": 22 + "column": 23 }, "end": { "line": 37, "column": 25 } } - }, - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 27 - } } - }, + ], "loc": { "start": { "line": 37, - "column": 21 + "column": 22 }, "end": { "line": 37, - "column": 27 + "column": 25 } } + }, + "loc": { + "start": { + "line": 37, + "column": 21 + }, + "end": { + "line": 37, + "column": 27 + } } - ], + }, "loc": { "start": { "line": 37, @@ -2787,60 +2757,35 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 13 - }, - "end": { - "line": 48, - "column": 14 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 15 - }, - "end": { - "line": 48, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 15 - }, - "end": { - "line": 48, - "column": 22 - } - } - }, + "end": { + "line": 48, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 48, @@ -2848,45 +2793,55 @@ }, "end": { "line": 48, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 48, + "column": 15 + }, + "end": { + "line": 48, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 48, - "column": 14 + "column": 15 }, "end": { "line": 48, "column": 22 } } - }, - "loc": { - "start": { - "line": 48, - "column": 13 - }, - "end": { - "line": 48, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 48, - "column": 13 + "column": 14 }, "end": { "line": 48, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 48, + "column": 13 + }, + "end": { + "line": 48, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 48, @@ -4473,60 +4428,35 @@ "type": "Identifier", "name": "p3", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 13 - }, - "end": { - "line": 54, - "column": 14 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 54, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 22 - } - } - }, + "end": { + "line": 54, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], "loc": { "start": { "line": 54, @@ -4534,45 +4464,55 @@ }, "end": { "line": 54, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 54, + "column": 15 + }, + "end": { + "line": 54, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 54, - "column": 14 + "column": 15 }, "end": { "line": 54, "column": 22 } } - }, - "loc": { - "start": { - "line": 54, - "column": 13 - }, - "end": { - "line": 54, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 54, - "column": 13 + "column": 14 }, "end": { "line": 54, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 54, + "column": 13 + }, + "end": { + "line": 54, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 54, diff --git a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt index 9d48d62f2754add599c00fd925e6c1be3d6e6e38..52a16293b34ac77d273306d5549a2a87ff2e1dca 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt @@ -449,22 +449,7 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 21 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 21, @@ -501,38 +486,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 32 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 32 - }, - "end": { - "line": 21, - "column": 37 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 21, @@ -540,11 +500,21 @@ }, "end": { "line": 21, - "column": 37 + "column": 35 } } + }, + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 37 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt index f66aa37242c7def82ef5601b9a368d73c0b803de..88d32c64268c451f08632a85436f45fdd9091fe0 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt @@ -429,22 +429,7 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 22 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 21, diff --git a/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt index 5dedc88c9cdf8aea84a7e30178f842e69db200a8..de072b9e7b5f706195fffecffff6be8198b3e8e3 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt @@ -214,22 +214,7 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 14 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 17, diff --git a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt index f070ebd4cff8a3c3ae2b2baa0166836d0b088902..d551053d61ba41f43eacdf77efef4b2fd91a6959 100644 --- a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt +++ b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt @@ -432,41 +432,16 @@ "type": "Identifier", "name": "exec", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSFunctionType", - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], "loc": { "start": { "line": 1, @@ -488,8 +463,18 @@ "column": 3 } } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } - ], + }, "loc": { "start": { "line": 1, diff --git a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt index 4b076a8743f04a4d2d1fb1e9bd6137eebbd1535c..66ec32d13735169de62634804767afe41114a573 100644 --- a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt +++ b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt @@ -358,38 +358,13 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 19, @@ -397,11 +372,21 @@ }, "end": { "line": 19, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 19, diff --git a/ets2panda/test/compiler/ets/union_types_1-expected.txt b/ets2panda/test/compiler/ets/union_types_1-expected.txt deleted file mode 100644 index 124c26c7ed81d78a771058243ca42cbbb295f32c..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_1-expected.txt +++ /dev/null @@ -1,3567 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 7 - }, - "end": { - "line": 16, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 41, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 10 - }, - "end": { - "line": 17, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 2 - }, - "end": { - "line": 18, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 9 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 7 - }, - "end": { - "line": 20, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5 - }, - "end": { - "line": 21, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 21, - "column": 16 - }, - "end": { - "line": 21, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 10 - }, - "end": { - "line": 21, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 22, - "column": 2 - }, - "end": { - "line": 22, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 20, - "column": 9 - }, - "end": { - "line": 22, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 1 - }, - "end": { - "line": 22, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 7 - }, - "end": { - "line": 24, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 5 - }, - "end": { - "line": 25, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 43, - "loc": { - "start": { - "line": 25, - "column": 16 - }, - "end": { - "line": 25, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 25, - "column": 10 - }, - "end": { - "line": 25, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "kind": "constructor", - "accessibility": "public", - "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": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "num", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 26, - "column": 22 - }, - "end": { - "line": 26, - "column": 25 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 25 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 14 - }, - "end": { - "line": 27, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 17 - } - } - }, - "right": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 20 - }, - "end": { - "line": 27, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 24 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 27 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 16 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 16 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 29, - "column": 18 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 29, - "column": 18 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 26 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 30, - "column": 16 - }, - "end": { - "line": 30, - "column": 20 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 21 - }, - "end": { - "line": 30, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 30, - "column": 16 - }, - "end": { - "line": 30, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 9 - }, - "end": { - "line": 30, - "column": 25 - } - } - } - ], - "loc": { - "start": { - "line": 29, - "column": 27 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 31, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 24, - "column": 9 - }, - "end": { - "line": 32, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 1 - }, - "end": { - "line": 32, - "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": 34, - "column": 10 - }, - "end": { - "line": 34, - "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": 34, - "column": 10 - }, - "end": { - "line": 34, - "column": 13 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 22 - }, - "end": { - "line": 34, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 22 - }, - "end": { - "line": 34, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 22 - }, - "end": { - "line": 34, - "column": 25 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 28 - } - } - } - ], - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 28 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 28 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 9 - }, - "end": { - "line": 35, - "column": 10 - } - } - }, - "right": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 22 - }, - "end": { - "line": 35, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 9 - }, - "end": { - "line": 35, - "column": 23 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "xx", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 13 - }, - "end": { - "line": 36, - "column": 15 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 18 - }, - "end": { - "line": 36, - "column": 19 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 23 - }, - "end": { - "line": 36, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 23 - }, - "end": { - "line": 36, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 23 - }, - "end": { - "line": 36, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 18 - }, - "end": { - "line": 36, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 13 - }, - "end": { - "line": 36, - "column": 19 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 36, - "column": 9 - }, - "end": { - "line": 36, - "column": 25 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "xx", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 16 - }, - "end": { - "line": 37, - "column": 18 - } - } - }, - "property": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 19 - }, - "end": { - "line": 37, - "column": 32 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 37, - "column": 16 - }, - "end": { - "line": 37, - "column": 32 - } - } - }, - "arguments": [], - "optional": false, - "loc": { - "start": { - "line": 37, - "column": 16 - }, - "end": { - "line": 37, - "column": 34 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 777, - "loc": { - "start": { - "line": 37, - "column": 38 - }, - "end": { - "line": 37, - "column": 41 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 16 - }, - "end": { - "line": 37, - "column": 41 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of class `C` must be 777", - "loc": { - "start": { - "line": 37, - "column": 43 - }, - "end": { - "line": 37, - "column": 90 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 91 - } - } - } - ], - "loc": { - "start": { - "line": 35, - "column": 25 - }, - "end": { - "line": 38, - "column": 6 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 35, - "column": 5 - }, - "end": { - "line": 38, - "column": 6 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 9 - }, - "end": { - "line": 39, - "column": 10 - } - } - }, - "right": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 22 - }, - "end": { - "line": 39, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 9 - }, - "end": { - "line": 39, - "column": 23 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 40, - "column": 16 - }, - "end": { - "line": 40, - "column": 21 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x is instaceof C but not A", - "loc": { - "start": { - "line": 40, - "column": 23 - }, - "end": { - "line": 40, - "column": 58 - } - } - }, - "loc": { - "start": { - "line": 40, - "column": 9 - }, - "end": { - "line": 40, - "column": 59 - } - } - } - ], - "loc": { - "start": { - "line": 39, - "column": 25 - }, - "end": { - "line": 41, - "column": 6 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 39, - "column": 5 - }, - "end": { - "line": 41, - "column": 6 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 12 - }, - "end": { - "line": 42, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 14 - }, - "end": { - "line": 42, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 42, - "column": 12 - }, - "end": { - "line": 42, - "column": 17 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 777, - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 12 - }, - "end": { - "line": 42, - "column": 24 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of union must be 777", - "loc": { - "start": { - "line": 42, - "column": 26 - }, - "end": { - "line": 42, - "column": 69 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 5 - }, - "end": { - "line": 42, - "column": 70 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 43, - "column": 12 - }, - "end": { - "line": 43, - "column": 15 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 9 - }, - "end": { - "line": 43, - "column": 10 - } - } - }, - "init": { - "type": "BinaryExpression", - "operator": "+", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 18 - }, - "end": { - "line": 43, - "column": 19 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 20 - }, - "end": { - "line": 43, - "column": 23 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 43, - "column": 18 - }, - "end": { - "line": 43, - "column": 23 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 3, - "loc": { - "start": { - "line": 43, - "column": 26 - }, - "end": { - "line": 43, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 43, - "column": 18 - }, - "end": { - "line": 43, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 43, - "column": 9 - }, - "end": { - "line": 43, - "column": 27 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 43, - "column": 5 - }, - "end": { - "line": 43, - "column": 28 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 12 - }, - "end": { - "line": 44, - "column": 13 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 780, - "loc": { - "start": { - "line": 44, - "column": 17 - }, - "end": { - "line": 44, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 12 - }, - "end": { - "line": 44, - "column": 20 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Variable 'a' must be 780", - "loc": { - "start": { - "line": 44, - "column": 22 - }, - "end": { - "line": 44, - "column": 55 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 5 - }, - "end": { - "line": 44, - "column": 56 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "+=", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 45, - "column": 5 - }, - "end": { - "line": 45, - "column": 6 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 45, - "column": 7 - }, - "end": { - "line": 45, - "column": 10 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 45, - "column": 5 - }, - "end": { - "line": 45, - "column": 10 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 223, - "loc": { - "start": { - "line": 45, - "column": 14 - }, - "end": { - "line": 45, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 45, - "column": 5 - }, - "end": { - "line": 45, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 45, - "column": 5 - }, - "end": { - "line": 45, - "column": 18 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 46, - "column": 12 - }, - "end": { - "line": 46, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 46, - "column": 14 - }, - "end": { - "line": 46, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 46, - "column": 12 - }, - "end": { - "line": 46, - "column": 17 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1000, - "loc": { - "start": { - "line": 46, - "column": 21 - }, - "end": { - "line": 46, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 12 - }, - "end": { - "line": 46, - "column": 25 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of union must be 1000", - "loc": { - "start": { - "line": 46, - "column": 27 - }, - "end": { - "line": 46, - "column": 71 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 5 - }, - "end": { - "line": 46, - "column": 72 - } - } - } - ], - "loc": { - "start": { - "line": 34, - "column": 29 - }, - "end": { - "line": 47, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 13 - }, - "end": { - "line": 47, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 13 - }, - "end": { - "line": 47, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 1 - }, - "end": { - "line": 47, - "column": 2 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 10 - }, - "end": { - "line": 49, - "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": 49, - "column": 10 - }, - "end": { - "line": 49, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 13 - }, - "end": { - "line": 50, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 13 - }, - "end": { - "line": 50, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 13 - }, - "end": { - "line": 50, - "column": 16 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 17 - }, - "end": { - "line": 50, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 17 - }, - "end": { - "line": 50, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 17 - }, - "end": { - "line": 50, - "column": 20 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 21 - }, - "end": { - "line": 50, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 21 - }, - "end": { - "line": 50, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 21 - }, - "end": { - "line": 50, - "column": 23 - } - } - } - ], - "loc": { - "start": { - "line": 50, - "column": 13 - }, - "end": { - "line": 50, - "column": 23 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 9 - }, - "end": { - "line": 50, - "column": 10 - } - } - }, - "init": null, - "loc": { - "start": { - "line": 50, - "column": 9 - }, - "end": { - "line": 50, - "column": 10 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 50, - "column": 5 - }, - "end": { - "line": 50, - "column": 23 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 13 - }, - "end": { - "line": 51, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 13 - }, - "end": { - "line": 51, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 13 - }, - "end": { - "line": 51, - "column": 15 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 777, - "loc": { - "start": { - "line": 51, - "column": 15 - }, - "end": { - "line": 51, - "column": 18 - } - } - } - ], - "loc": { - "start": { - "line": 51, - "column": 9 - }, - "end": { - "line": 51, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 20 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 9 - }, - "end": { - "line": 52, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 12 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 53, - "column": 12 - }, - "end": { - "line": 53, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 53, - "column": 14 - }, - "end": { - "line": 53, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 53, - "column": 12 - }, - "end": { - "line": 53, - "column": 17 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1000, - "loc": { - "start": { - "line": 53, - "column": 21 - }, - "end": { - "line": 53, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 53, - "column": 12 - }, - "end": { - "line": 53, - "column": 25 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of union must be 1000", - "loc": { - "start": { - "line": 53, - "column": 27 - }, - "end": { - "line": 53, - "column": 71 - } - } - }, - "loc": { - "start": { - "line": 53, - "column": 5 - }, - "end": { - "line": 53, - "column": 72 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 9 - }, - "end": { - "line": 54, - "column": 10 - } - } - }, - "right": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 22 - }, - "end": { - "line": 54, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 54, - "column": 9 - }, - "end": { - "line": 54, - "column": 23 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "xx", - "decorators": [], - "loc": { - "start": { - "line": 55, - "column": 13 - }, - "end": { - "line": 55, - "column": 15 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 55, - "column": 18 - }, - "end": { - "line": 55, - "column": 19 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 55, - "column": 23 - }, - "end": { - "line": 55, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 55, - "column": 23 - }, - "end": { - "line": 55, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 55, - "column": 23 - }, - "end": { - "line": 55, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 55, - "column": 18 - }, - "end": { - "line": 55, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 55, - "column": 13 - }, - "end": { - "line": 55, - "column": 19 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 55, - "column": 9 - }, - "end": { - "line": 55, - "column": 25 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "xx", - "decorators": [], - "loc": { - "start": { - "line": 56, - "column": 16 - }, - "end": { - "line": 56, - "column": 18 - } - } - }, - "property": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 56, - "column": 19 - }, - "end": { - "line": 56, - "column": 32 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 56, - "column": 16 - }, - "end": { - "line": 56, - "column": 32 - } - } - }, - "arguments": [], - "optional": false, - "loc": { - "start": { - "line": 56, - "column": 16 - }, - "end": { - "line": 56, - "column": 34 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1000, - "loc": { - "start": { - "line": 56, - "column": 38 - }, - "end": { - "line": 56, - "column": 42 - } - } - }, - "loc": { - "start": { - "line": 56, - "column": 16 - }, - "end": { - "line": 56, - "column": 42 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of class `C` must be 1000", - "loc": { - "start": { - "line": 56, - "column": 44 - }, - "end": { - "line": 56, - "column": 92 - } - } - }, - "loc": { - "start": { - "line": 56, - "column": 9 - }, - "end": { - "line": 56, - "column": 93 - } - } - } - ], - "loc": { - "start": { - "line": 54, - "column": 25 - }, - "end": { - "line": 57, - "column": 6 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 54, - "column": 5 - }, - "end": { - "line": 57, - "column": 6 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 58, - "column": 9 - }, - "end": { - "line": 58, - "column": 10 - } - } - }, - "right": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 58, - "column": 22 - }, - "end": { - "line": 58, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 58, - "column": 9 - }, - "end": { - "line": 58, - "column": 23 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 59, - "column": 16 - }, - "end": { - "line": 59, - "column": 21 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x is instaceof C but not B", - "loc": { - "start": { - "line": 59, - "column": 23 - }, - "end": { - "line": 59, - "column": 58 - } - } - }, - "loc": { - "start": { - "line": 59, - "column": 9 - }, - "end": { - "line": 59, - "column": 59 - } - } - } - ], - "loc": { - "start": { - "line": 58, - "column": 25 - }, - "end": { - "line": 60, - "column": 6 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 58, - "column": 5 - }, - "end": { - "line": 60, - "column": 6 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 61, - "column": 5 - }, - "end": { - "line": 61, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 61, - "column": 13 - }, - "end": { - "line": 61, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 61, - "column": 13 - }, - "end": { - "line": 61, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 61, - "column": 13 - }, - "end": { - "line": 61, - "column": 15 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 61, - "column": 9 - }, - "end": { - "line": 61, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 61, - "column": 5 - }, - "end": { - "line": 61, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 61, - "column": 5 - }, - "end": { - "line": 61, - "column": 17 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 62, - "column": 12 - }, - "end": { - "line": 62, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 62, - "column": 14 - }, - "end": { - "line": 62, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 62, - "column": 12 - }, - "end": { - "line": 62, - "column": 17 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 41, - "loc": { - "start": { - "line": 62, - "column": 21 - }, - "end": { - "line": 62, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 62, - "column": 12 - }, - "end": { - "line": 62, - "column": 23 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of union must be 41", - "loc": { - "start": { - "line": 62, - "column": 25 - }, - "end": { - "line": 62, - "column": 67 - } - } - }, - "loc": { - "start": { - "line": 62, - "column": 5 - }, - "end": { - "line": 62, - "column": 68 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 63, - "column": 5 - }, - "end": { - "line": 63, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 63, - "column": 13 - }, - "end": { - "line": 63, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 63, - "column": 13 - }, - "end": { - "line": 63, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 63, - "column": 13 - }, - "end": { - "line": 63, - "column": 15 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 63, - "column": 9 - }, - "end": { - "line": 63, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 63, - "column": 5 - }, - "end": { - "line": 63, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 63, - "column": 5 - }, - "end": { - "line": 63, - "column": 17 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 64, - "column": 12 - }, - "end": { - "line": 64, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 64, - "column": 14 - }, - "end": { - "line": 64, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 64, - "column": 12 - }, - "end": { - "line": 64, - "column": 17 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 64, - "column": 21 - }, - "end": { - "line": 64, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 64, - "column": 12 - }, - "end": { - "line": 64, - "column": 23 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! The num field of union must be 42", - "loc": { - "start": { - "line": 64, - "column": 25 - }, - "end": { - "line": 64, - "column": 67 - } - } - }, - "loc": { - "start": { - "line": 64, - "column": 5 - }, - "end": { - "line": 64, - "column": 68 - } - } - } - ], - "loc": { - "start": { - "line": 49, - "column": 17 - }, - "end": { - "line": 65, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 49, - "column": 14 - }, - "end": { - "line": 65, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 49, - "column": 14 - }, - "end": { - "line": 65, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 1 - }, - "end": { - "line": 65, - "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": 66, - "column": 1 - } - } -} diff --git a/ets2panda/test/compiler/ets/union_types_1.ets b/ets2panda/test/compiler/ets/union_types_1.ets deleted file mode 100644 index 2f162f1ab67c756d96185a26f994ec1203938d99..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_1.ets +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ - -class A { - num: int = 41; -} - -class B { - num: int = 42; -} - -class C { - num: int = 43; - constructor(num: int) { - this.num = num; - } - num_to_return() : int { - return this.num; - } -} - -function foo(x : A | B | C) { - if (x instanceof C) { - let xx = x as C; - assert xx.num_to_return() == 777: "Error! The num field of class `C` must be 777"; - } - if (x instanceof A) { - assert false: "Error! x is instaceof C but not A"; - } - assert x.num == 777: "Error! The num field of union must be 777"; - let a: int = x.num + 3; - assert a == 780: "Error! Variable 'a' must be 780"; - x.num += 223; - assert x.num == 1000: "Error! The num field of union must be 1000"; -} - -function main() { - let x : A | B | C; - x = new C(777); - foo(x); - assert x.num == 1000: "Error! The num field of union must be 1000"; - if (x instanceof C) { - let xx = x as C; - assert xx.num_to_return() == 1000: "Error! The num field of class `C` must be 1000"; - } - if (x instanceof B) { - assert false: "Error! x is instaceof C but not B"; - } - x = new A(); - assert x.num == 41: "Error! The num field of union must be 41"; - x = new B(); - assert x.num == 42: "Error! The num field of union must be 42"; -} diff --git a/ets2panda/test/compiler/ets/union_types_2-expected.txt b/ets2panda/test/compiler/ets/union_types_2-expected.txt deleted file mode 100644 index 868389447b183772a6d3affbcd902e8bfbcc5715..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_2-expected.txt +++ /dev/null @@ -1,1753 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 7 - }, - "end": { - "line": 16, - "column": 8 - } - } - }, - "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": 16, - "column": 11 - }, - "end": { - "line": 16, - "column": 11 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 9 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 7 - }, - "end": { - "line": 18, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 5 - }, - "end": { - "line": 19, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 19, - "column": 16 - }, - "end": { - "line": 19, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 19, - "column": 10 - }, - "end": { - "line": 19, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 2 - }, - "end": { - "line": 20, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 18, - "column": 9 - }, - "end": { - "line": 20, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 1 - }, - "end": { - "line": 20, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 5 - }, - "end": { - "line": 23, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 43, - "loc": { - "start": { - "line": 23, - "column": 16 - }, - "end": { - "line": 23, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 23, - "column": 10 - }, - "end": { - "line": 23, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "kind": "constructor", - "accessibility": "public", - "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": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "num", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 24, - "column": 22 - }, - "end": { - "line": 24, - "column": 25 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 17 - }, - "end": { - "line": 24, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 17 - }, - "end": { - "line": 24, - "column": 25 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 13 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 17 - } - } - }, - "right": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 20 - }, - "end": { - "line": 25, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 24 - } - } - } - ], - "loc": { - "start": { - "line": 24, - "column": 27 - }, - "end": { - "line": 26, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 16 - }, - "end": { - "line": 26, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 16 - }, - "end": { - "line": 26, - "column": 6 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 5 - }, - "end": { - "line": 26, - "column": 6 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 27, - "column": 18 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "num_to_return", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 27, - "column": 18 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 27, - "column": 23 - }, - "end": { - "line": 27, - "column": 26 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 28, - "column": 16 - }, - "end": { - "line": 28, - "column": 20 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 21 - }, - "end": { - "line": 28, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 28, - "column": 16 - }, - "end": { - "line": 28, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 25 - } - } - } - ], - "loc": { - "start": { - "line": 27, - "column": 27 - }, - "end": { - "line": 29, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 18 - }, - "end": { - "line": 29, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 18 - }, - "end": { - "line": 29, - "column": 6 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 29, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 30, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 1 - }, - "end": { - "line": 30, - "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": 32, - "column": 10 - }, - "end": { - "line": 32, - "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": 32, - "column": 10 - }, - "end": { - "line": 32, - "column": 13 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 18 - }, - "end": { - "line": 32, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 18 - }, - "end": { - "line": 32, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 18 - }, - "end": { - "line": 32, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 22 - }, - "end": { - "line": 32, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 22 - }, - "end": { - "line": 32, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 22 - }, - "end": { - "line": 32, - "column": 25 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 26 - }, - "end": { - "line": 32, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 26 - }, - "end": { - "line": 32, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 26 - }, - "end": { - "line": 32, - "column": 28 - } - } - } - ], - "loc": { - "start": { - "line": 32, - "column": 18 - }, - "end": { - "line": 32, - "column": 28 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 14 - }, - "end": { - "line": 32, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 14 - }, - "end": { - "line": 32, - "column": 28 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 5 - }, - "end": { - "line": 33, - "column": 6 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 7 - }, - "end": { - "line": 33, - "column": 10 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 33, - "column": 5 - }, - "end": { - "line": 33, - "column": 10 - } - } - }, - "loc": { - "start": { - "line": 33, - "column": 5 - }, - "end": { - "line": 33, - "column": 11 - } - } - } - ], - "loc": { - "start": { - "line": 32, - "column": 29 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 13 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 13 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 1 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 10 - }, - "end": { - "line": 36, - "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": 36, - "column": 10 - }, - "end": { - "line": 36, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 13 - }, - "end": { - "line": 37, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 13 - }, - "end": { - "line": 37, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 13 - }, - "end": { - "line": 37, - "column": 16 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 17 - }, - "end": { - "line": 37, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 17 - }, - "end": { - "line": 37, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 17 - }, - "end": { - "line": 37, - "column": 20 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 23 - } - } - } - ], - "loc": { - "start": { - "line": 37, - "column": 13 - }, - "end": { - "line": 37, - "column": 23 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 10 - } - } - }, - "init": null, - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 10 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 37, - "column": 5 - }, - "end": { - "line": 37, - "column": 23 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 5 - }, - "end": { - "line": 38, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 13 - }, - "end": { - "line": 38, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 13 - }, - "end": { - "line": 38, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 13 - }, - "end": { - "line": 38, - "column": 15 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 777, - "loc": { - "start": { - "line": 38, - "column": 15 - }, - "end": { - "line": 38, - "column": 18 - } - } - } - ], - "loc": { - "start": { - "line": 38, - "column": 9 - }, - "end": { - "line": 38, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 5 - }, - "end": { - "line": 38, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 5 - }, - "end": { - "line": 38, - "column": 20 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 5 - }, - "end": { - "line": 39, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 9 - }, - "end": { - "line": 39, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 39, - "column": 5 - }, - "end": { - "line": 39, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 5 - }, - "end": { - "line": 39, - "column": 12 - } - } - } - ], - "loc": { - "start": { - "line": 36, - "column": 17 - }, - "end": { - "line": 40, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 14 - }, - "end": { - "line": 40, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 14 - }, - "end": { - "line": 40, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 1 - }, - "end": { - "line": 40, - "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": 41, - "column": 1 - } - } -} -TypeError: Property 'num' does not exist on type 'A' [union_types_2.ets:33:7] diff --git a/ets2panda/test/compiler/ets/union_types_2.ets b/ets2panda/test/compiler/ets/union_types_2.ets deleted file mode 100644 index 2759e37c14804da2cc06822fc2a5b73824adde3a..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_2.ets +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -class A {} - -class B { - num: int = 42; -} - -class C { - num: int = 43; - constructor(num: int) { - this.num = num; - } - num_to_return() : int { - return this.num; - } -} - -function foo(x : A | B | C) { - x.num; // CTE - `A` doesn't have field `num` -} - -function main() { - let x : A | B | C; - x = new C(777); - foo(x); -} diff --git a/ets2panda/test/compiler/ets/union_types_3-expected.txt b/ets2panda/test/compiler/ets/union_types_3-expected.txt deleted file mode 100644 index 6d79a7c76ac512ae1500d82f24896b0b3b73e847..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_3-expected.txt +++ /dev/null @@ -1,1968 +0,0 @@ -{ - "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": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10 - }, - "end": { - "line": 16, - "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": 16, - "column": 10 - }, - "end": { - "line": 16, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x0", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 14 - }, - "end": { - "line": 17, - "column": 17 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 28 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 29 - }, - "end": { - "line": 17, - "column": 36 - } - } - } - ], - "loc": { - "start": { - "line": 17, - "column": 14 - }, - "end": { - "line": 17, - "column": 36 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 11 - } - } - }, - "init": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 17, - "column": 39 - }, - "end": { - "line": 17, - "column": 40 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 40 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 41 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "*", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 19 - }, - "end": { - "line": 18, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 23 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 18, - "column": 26 - }, - "end": { - "line": 18, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 27 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 4, - "loc": { - "start": { - "line": 18, - "column": 31 - }, - "end": { - "line": 18, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 12 - }, - "end": { - "line": 18, - "column": 32 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be 4", - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 52 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 53 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 5 - }, - "end": { - "line": 19, - "column": 7 - } - } - }, - "right": { - "type": "UnaryExpression", - "operator": "-", - "prefix": true, - "argument": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 19, - "column": 11 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 10 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 5 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 5 - }, - "end": { - "line": 19, - "column": 13 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "*", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 15 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 20, - "column": 19 - }, - "end": { - "line": 20, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 23 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 3, - "loc": { - "start": { - "line": 20, - "column": 26 - }, - "end": { - "line": 20, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 27 - } - } - }, - "right": { - "type": "UnaryExpression", - "operator": "-", - "prefix": true, - "argument": { - "type": "NumberLiteral", - "value": 6, - "loc": { - "start": { - "line": 20, - "column": 32 - }, - "end": { - "line": 20, - "column": 33 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 33 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 12 - }, - "end": { - "line": 20, - "column": 33 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be -6", - "loc": { - "start": { - "line": 20, - "column": 35 - }, - "end": { - "line": 20, - "column": 54 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 5 - }, - "end": { - "line": 20, - "column": 55 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5 - }, - "end": { - "line": 21, - "column": 7 - } - } - }, - "right": { - "type": "BooleanLiteral", - "value": true, - "loc": { - "start": { - "line": 21, - "column": 10 - }, - "end": { - "line": 21, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5 - }, - "end": { - "line": 21, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5 - }, - "end": { - "line": 21, - "column": 14 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 13 - }, - "end": { - "line": 22, - "column": 15 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 12 - }, - "end": { - "line": 22, - "column": 27 - } - } - }, - "right": { - "type": "BooleanLiteral", - "value": true, - "loc": { - "start": { - "line": 22, - "column": 31 - }, - "end": { - "line": 22, - "column": 35 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 12 - }, - "end": { - "line": 22, - "column": 35 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be true", - "loc": { - "start": { - "line": 22, - "column": 37 - }, - "end": { - "line": 22, - "column": 58 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 5 - }, - "end": { - "line": 22, - "column": 59 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 5 - }, - "end": { - "line": 23, - "column": 7 - } - } - }, - "right": { - "type": "StringLiteral", - "value": "STR1", - "loc": { - "start": { - "line": 23, - "column": 10 - }, - "end": { - "line": 23, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 5 - }, - "end": { - "line": 23, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 5 - }, - "end": { - "line": 23, - "column": 16 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "BinaryExpression", - "operator": "+", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x0", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 14 - }, - "end": { - "line": 24, - "column": 16 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 20 - }, - "end": { - "line": 24, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 20 - }, - "end": { - "line": 24, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 20 - }, - "end": { - "line": 24, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 13 - }, - "end": { - "line": 24, - "column": 27 - } - } - }, - "right": { - "type": "StringLiteral", - "value": "STR2", - "loc": { - "start": { - "line": 24, - "column": 30 - }, - "end": { - "line": 24, - "column": 36 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 12 - }, - "end": { - "line": 24, - "column": 37 - } - } - }, - "property": { - "type": "Identifier", - "name": "equals", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 38 - }, - "end": { - "line": 24, - "column": 44 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 24, - "column": 12 - }, - "end": { - "line": 24, - "column": 44 - } - } - }, - "arguments": [ - { - "type": "StringLiteral", - "value": "STR1STR2", - "loc": { - "start": { - "line": 24, - "column": 45 - }, - "end": { - "line": 24, - "column": 55 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 24, - "column": 12 - }, - "end": { - "line": 24, - "column": 56 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be `STR1STR2`", - "loc": { - "start": { - "line": 24, - "column": 58 - }, - "end": { - "line": 24, - "column": 85 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 5 - }, - "end": { - "line": 24, - "column": 86 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x1", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 22 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 25, - "column": 23 - }, - "end": { - "line": 25, - "column": 30 - } - } - } - ], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 30 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 11 - } - } - }, - "init": { - "type": "StringLiteral", - "value": "AAA", - "loc": { - "start": { - "line": 25, - "column": 33 - }, - "end": { - "line": 25, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 9 - }, - "end": { - "line": 25, - "column": 38 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 25, - "column": 5 - }, - "end": { - "line": 25, - "column": 39 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x1", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 9 - }, - "end": { - "line": 26, - "column": 11 - } - } - }, - "right": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 23 - }, - "end": { - "line": 26, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 9 - }, - "end": { - "line": 26, - "column": 29 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x1", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 17 - }, - "end": { - "line": 27, - "column": 19 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 23 - }, - "end": { - "line": 27, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 23 - }, - "end": { - "line": 27, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 23 - }, - "end": { - "line": 27, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 16 - }, - "end": { - "line": 27, - "column": 30 - } - } - }, - "property": { - "type": "Identifier", - "name": "equals", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 31 - }, - "end": { - "line": 27, - "column": 37 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 16 - }, - "end": { - "line": 27, - "column": 37 - } - } - }, - "arguments": [ - { - "type": "StringLiteral", - "value": "AAA", - "loc": { - "start": { - "line": 27, - "column": 38 - }, - "end": { - "line": 27, - "column": 43 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 16 - }, - "end": { - "line": 27, - "column": 44 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be `AAA`", - "loc": { - "start": { - "line": 27, - "column": 46 - }, - "end": { - "line": 27, - "column": 68 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 69 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 31 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x2", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 14 - }, - "end": { - "line": 29, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 14 - }, - "end": { - "line": 29, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 14 - }, - "end": { - "line": 29, - "column": 22 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 30 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 29, - "column": 33 - }, - "end": { - "line": 29, - "column": 36 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 29, - "column": 39 - }, - "end": { - "line": 29, - "column": 45 - } - } - } - ], - "loc": { - "start": { - "line": 29, - "column": 14 - }, - "end": { - "line": 29, - "column": 45 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 9 - }, - "end": { - "line": 29, - "column": 11 - } - } - }, - "init": { - "type": "BooleanLiteral", - "value": true, - "loc": { - "start": { - "line": 29, - "column": 48 - }, - "end": { - "line": 29, - "column": 52 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 9 - }, - "end": { - "line": 29, - "column": 52 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 29, - "column": 53 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x2", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 13 - }, - "end": { - "line": 30, - "column": 15 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 30, - "column": 19 - }, - "end": { - "line": 30, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 12 - }, - "end": { - "line": 30, - "column": 27 - } - } - }, - "right": { - "type": "BooleanLiteral", - "value": true, - "loc": { - "start": { - "line": 30, - "column": 31 - }, - "end": { - "line": 30, - "column": 35 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 12 - }, - "end": { - "line": 30, - "column": 35 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be `true`", - "loc": { - "start": { - "line": 30, - "column": 37 - }, - "end": { - "line": 30, - "column": 60 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 5 - }, - "end": { - "line": 30, - "column": 61 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x3", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 22 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 31, - "column": 23 - }, - "end": { - "line": 31, - "column": 30 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 31, - "column": 33 - }, - "end": { - "line": 31, - "column": 36 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 31, - "column": 39 - }, - "end": { - "line": 31, - "column": 45 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 45 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 9 - }, - "end": { - "line": 31, - "column": 11 - } - } - }, - "init": { - "type": "NumberLiteral", - "value": 3.14, - "loc": { - "start": { - "line": 31, - "column": 48 - }, - "end": { - "line": 31, - "column": 52 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 9 - }, - "end": { - "line": 31, - "column": 52 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 31, - "column": 5 - }, - "end": { - "line": 31, - "column": 53 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x3", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 13 - }, - "end": { - "line": 32, - "column": 15 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 32, - "column": 19 - }, - "end": { - "line": 32, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 12 - }, - "end": { - "line": 32, - "column": 26 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 3.14, - "loc": { - "start": { - "line": 32, - "column": 30 - }, - "end": { - "line": 32, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 12 - }, - "end": { - "line": 32, - "column": 34 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be `3.14`", - "loc": { - "start": { - "line": 32, - "column": 36 - }, - "end": { - "line": 32, - "column": 59 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 5 - }, - "end": { - "line": 32, - "column": 60 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 17 - }, - "end": { - "line": 33, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 33, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 33, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 33, - "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": 34, - "column": 1 - } - } -} diff --git a/ets2panda/test/compiler/ets/union_types_3.ets b/ets2panda/test/compiler/ets/union_types_3.ets deleted file mode 100644 index 78a4cca1daefcbbabe4eb8c9aeb6e1aff7712740..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_3.ets +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -function main() { - let x0 : int | String | boolean = 2; - assert (x0 as int) * 2 == 4: "Error! Must be 4"; - x0 = -2; - assert (x0 as int) * 3 == -6: "Error! Must be -6"; - x0 = true - assert (x0 as boolean) == true: "Error! Must be true"; - x0 = "STR1" - assert ((x0 as String) + "STR2").equals("STR1STR2"): "Error! Must be `STR1STR2`"; - let x1 : String | boolean = "AAA"; - if (x1 instanceof String) { - assert (x1 as String).equals("AAA"): "Error! Must be `AAA`"; - } - let x2 : String | boolean | int | double = true; - assert (x2 as boolean) == true: "Error! Must be `true`"; - let x3 : String | boolean | int | double = 3.14; - assert (x3 as double) == 3.14: "Error! Must be `3.14`"; -} diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt deleted file mode 100644 index c34e9be2467308c8b012df6d432f8c48767be333..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ /dev/null @@ -1,1532 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 7 - }, - "end": { - "line": 16, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 10 - }, - "end": { - "line": 17, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 8 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 8 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, - { - "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": 2 - }, - "end": { - "line": 19, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 9 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 7 - }, - "end": { - "line": 21, - "column": 8 - } - } - }, - "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": 11 - }, - "end": { - "line": 21, - "column": 11 - } - } - } - ], - "loc": { - "start": { - "line": 21, - "column": 9 - }, - "end": { - "line": 21, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 1 - }, - "end": { - "line": 21, - "column": 11 - } - } - }, - { - "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": 23, - "column": 10 - }, - "end": { - "line": 23, - "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": 23, - "column": 10 - }, - "end": { - "line": 23, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 13 - }, - "end": { - "line": 24, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 13 - }, - "end": { - "line": 24, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 13 - }, - "end": { - "line": 24, - "column": 21 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 24, - "column": 22 - }, - "end": { - "line": 24, - "column": 27 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 30 - }, - "end": { - "line": 24, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 30 - }, - "end": { - "line": 24, - "column": 33 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 30 - }, - "end": { - "line": 24, - "column": 33 - } - } - } - ], - "loc": { - "start": { - "line": 24, - "column": 13 - }, - "end": { - "line": 24, - "column": 33 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 9 - }, - "end": { - "line": 24, - "column": 10 - } - } - }, - "init": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 24, - "column": 34 - }, - "end": { - "line": 24, - "column": 35 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 9 - }, - "end": { - "line": 24, - "column": 35 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 24, - "column": 5 - }, - "end": { - "line": 24, - "column": 36 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "*", - "left": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 13 - }, - "end": { - "line": 25, - "column": 14 - } - } - }, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 25, - "column": 18 - }, - "end": { - "line": 25, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 22 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 25, - "column": 25 - }, - "end": { - "line": 25, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 26 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 25, - "column": 30 - }, - "end": { - "line": 25, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 32 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be 10", - "loc": { - "start": { - "line": 25, - "column": 34 - }, - "end": { - "line": 25, - "column": 53 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 5 - }, - "end": { - "line": 25, - "column": 54 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 6 - } - } - }, - "right": { - "type": "StringLiteral", - "value": "STRSTR", - "loc": { - "start": { - "line": 26, - "column": 9 - }, - "end": { - "line": 26, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 18 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 14 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 18 - }, - "end": { - "line": 27, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 18 - }, - "end": { - "line": 27, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 18 - }, - "end": { - "line": 27, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 12 - }, - "end": { - "line": 27, - "column": 25 - } - } - }, - "property": { - "type": "Identifier", - "name": "equals", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 26 - }, - "end": { - "line": 27, - "column": 32 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 12 - }, - "end": { - "line": 27, - "column": 32 - } - } - }, - "arguments": [ - { - "type": "StringLiteral", - "value": "STRSTR", - "loc": { - "start": { - "line": 27, - "column": 33 - }, - "end": { - "line": 27, - "column": 41 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 12 - }, - "end": { - "line": 27, - "column": 42 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Must be `STRSTR`", - "loc": { - "start": { - "line": 27, - "column": 44 - }, - "end": { - "line": 27, - "column": 69 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 27, - "column": 70 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 5 - }, - "end": { - "line": 28, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 15 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 5 - }, - "end": { - "line": 28, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 5 - }, - "end": { - "line": 28, - "column": 17 - } - } - }, - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 13 - }, - "end": { - "line": 29, - "column": 14 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 20 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 21 - }, - "end": { - "line": 29, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 24 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 29, - "column": 28 - }, - "end": { - "line": 29, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 30 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! Field of A must be `42`", - "loc": { - "start": { - "line": 29, - "column": 32 - }, - "end": { - "line": 29, - "column": 64 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 29, - "column": 65 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 5 - }, - "end": { - "line": 30, - "column": 6 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 13 - }, - "end": { - "line": 30, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 13 - }, - "end": { - "line": 30, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 13 - }, - "end": { - "line": 30, - "column": 15 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 30, - "column": 9 - }, - "end": { - "line": 30, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 5 - }, - "end": { - "line": 30, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 5 - }, - "end": { - "line": 30, - "column": 17 - } - } - } - ], - "loc": { - "start": { - "line": 23, - "column": 17 - }, - "end": { - "line": 31, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 31, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 31, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 1 - }, - "end": { - "line": 31, - "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": 32, - "column": 1 - } - } -} -TypeError: Initializers type is not assignable to the target type [union_types_4.ets:30:9] diff --git a/ets2panda/test/compiler/ets/union_types_4.ets b/ets2panda/test/compiler/ets/union_types_4.ets deleted file mode 100644 index fdc49e067fc4954289b0828b1eca30255067efac..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_4.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -class A { - num: int = 42; - foo() {} -} - -class B {} - -function main() { - let x : String | short | A = 5; - assert (x as int) * 2 == 10: "Error! Must be 10"; - x = "STRSTR"; - assert (x as String).equals("STRSTR"): "Error! Must be `STRSTR`"; - x = new A(); - assert (x as A).num == 42: "Error! Field of A must be `42`"; - x = new B(); // CTE -} diff --git a/ets2panda/test/compiler/ets/union_types_5-expected.txt b/ets2panda/test/compiler/ets/union_types_5-expected.txt deleted file mode 100644 index 1ca5dd87b41c5782c6c35e20978a00677fa6680f..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_5-expected.txt +++ /dev/null @@ -1,3319 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 7 - }, - "end": { - "line": 16, - "column": 8 - } - } - }, - "typeParameters": { - "type": "TSTypeParameterDeclaration", - "params": [ - { - "type": "TSTypeParameter", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 9 - }, - "end": { - "line": 16, - "column": 10 - } - } - }, - "constraint": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 9 - }, - "end": { - "line": 16, - "column": 26 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 8 - }, - "end": { - "line": 16, - "column": 26 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 11 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 15 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 2 - }, - "end": { - "line": 18, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 27 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 7 - }, - "end": { - "line": 19, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 5 - }, - "end": { - "line": 20, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 20, - "column": 16 - }, - "end": { - "line": 20, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 20, - "column": 10 - }, - "end": { - "line": 20, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 2 - }, - "end": { - "line": 21, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 21, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 1 - }, - "end": { - "line": 21, - "column": 2 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 8 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 5 - }, - "end": { - "line": 23, - "column": 8 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 43, - "loc": { - "start": { - "line": 23, - "column": 16 - }, - "end": { - "line": 23, - "column": 18 - } - } - }, - "accessibility": "public", - "static": false, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 23, - "column": 10 - }, - "end": { - "line": 23, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "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": 24, - "column": 2 - }, - "end": { - "line": 24, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 24, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 1 - }, - "end": { - "line": 24, - "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": 26, - "column": 10 - }, - "end": { - "line": 26, - "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": 26, - "column": 10 - }, - "end": { - "line": 26, - "column": 13 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "x", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 19 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 19 - }, - "end": { - "line": 26, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 19 - }, - "end": { - "line": 26, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 19 - }, - "end": { - "line": 26, - "column": 21 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 21 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 14 - }, - "end": { - "line": 26, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 14 - }, - "end": { - "line": 26, - "column": 21 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 10 - } - } - }, - "right": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 22 - }, - "end": { - "line": 27, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 23 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 16 - }, - "end": { - "line": 28, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 18 - }, - "end": { - "line": 28, - "column": 21 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 28, - "column": 16 - }, - "end": { - "line": 28, - "column": 21 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 28, - "column": 25 - }, - "end": { - "line": 28, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 16 - }, - "end": { - "line": 28, - "column": 27 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! num field must be 42", - "loc": { - "start": { - "line": 28, - "column": 29 - }, - "end": { - "line": 28, - "column": 58 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 59 - } - } - } - ], - "loc": { - "start": { - "line": 27, - "column": 25 - }, - "end": { - "line": 29, - "column": 6 - } - } - }, - "alternate": { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 17 - } - } - }, - "right": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 29 - }, - "end": { - "line": 29, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 30 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 16 - }, - "end": { - "line": 30, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 18 - }, - "end": { - "line": 30, - "column": 21 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 30, - "column": 16 - }, - "end": { - "line": 30, - "column": 21 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 43, - "loc": { - "start": { - "line": 30, - "column": 25 - }, - "end": { - "line": 30, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 16 - }, - "end": { - "line": 30, - "column": 27 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! num field must be 43", - "loc": { - "start": { - "line": 30, - "column": 29 - }, - "end": { - "line": 30, - "column": 58 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 9 - }, - "end": { - "line": 30, - "column": 59 - } - } - } - ], - "loc": { - "start": { - "line": 29, - "column": 32 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 32, - "column": 16 - }, - "end": { - "line": 32, - "column": 21 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x must be instanceof B|C", - "loc": { - "start": { - "line": 32, - "column": 23 - }, - "end": { - "line": 32, - "column": 56 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 9 - }, - "end": { - "line": 32, - "column": 57 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 33, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 33, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 33, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 22 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 13 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 13 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 1 - }, - "end": { - "line": 34, - "column": 2 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 10 - }, - "end": { - "line": 36, - "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": 36, - "column": 10 - }, - "end": { - "line": 36, - "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": "A", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 17 - }, - "end": { - "line": 36, - "column": 18 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 19 - }, - "end": { - "line": 36, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 19 - }, - "end": { - "line": 36, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 19 - }, - "end": { - "line": 36, - "column": 21 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 21 - }, - "end": { - "line": 36, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 21 - }, - "end": { - "line": 36, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 21 - }, - "end": { - "line": 36, - "column": 23 - } - } - } - ], - "loc": { - "start": { - "line": 36, - "column": 19 - }, - "end": { - "line": 36, - "column": 23 - } - } - } - ], - "loc": { - "start": { - "line": 36, - "column": 18 - }, - "end": { - "line": 36, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 17 - }, - "end": { - "line": 36, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 17 - }, - "end": { - "line": 36, - "column": 24 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 14 - }, - "end": { - "line": 36, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 14 - }, - "end": { - "line": 36, - "column": 24 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 10 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 11 - }, - "end": { - "line": 37, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 17 - } - } - }, - "right": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 29 - }, - "end": { - "line": 37, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 9 - }, - "end": { - "line": 37, - "column": 30 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 16 - }, - "end": { - "line": 38, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 18 - }, - "end": { - "line": 38, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 38, - "column": 16 - }, - "end": { - "line": 38, - "column": 24 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 25 - }, - "end": { - "line": 38, - "column": 28 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 38, - "column": 16 - }, - "end": { - "line": 38, - "column": 28 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 42, - "loc": { - "start": { - "line": 38, - "column": 32 - }, - "end": { - "line": 38, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 16 - }, - "end": { - "line": 38, - "column": 34 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x.union0.num field must be 42", - "loc": { - "start": { - "line": 38, - "column": 36 - }, - "end": { - "line": 38, - "column": 74 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 9 - }, - "end": { - "line": 38, - "column": 75 - } - } - } - ], - "loc": { - "start": { - "line": 37, - "column": 32 - }, - "end": { - "line": 39, - "column": 6 - } - } - }, - "alternate": { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 16 - }, - "end": { - "line": 39, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 18 - }, - "end": { - "line": 39, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 39, - "column": 16 - }, - "end": { - "line": 39, - "column": 24 - } - } - }, - "right": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 36 - }, - "end": { - "line": 39, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 16 - }, - "end": { - "line": 39, - "column": 37 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "MemberExpression", - "object": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 40, - "column": 16 - }, - "end": { - "line": 40, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 40, - "column": 18 - }, - "end": { - "line": 40, - "column": 24 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 40, - "column": 16 - }, - "end": { - "line": 40, - "column": 24 - } - } - }, - "property": { - "type": "Identifier", - "name": "num", - "decorators": [], - "loc": { - "start": { - "line": 40, - "column": 25 - }, - "end": { - "line": 40, - "column": 28 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 40, - "column": 16 - }, - "end": { - "line": 40, - "column": 28 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 43, - "loc": { - "start": { - "line": 40, - "column": 32 - }, - "end": { - "line": 40, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 40, - "column": 16 - }, - "end": { - "line": 40, - "column": 34 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x.union0.num field must be 43", - "loc": { - "start": { - "line": 40, - "column": 36 - }, - "end": { - "line": 40, - "column": 74 - } - } - }, - "loc": { - "start": { - "line": 40, - "column": 9 - }, - "end": { - "line": 40, - "column": 75 - } - } - } - ], - "loc": { - "start": { - "line": 39, - "column": 39 - }, - "end": { - "line": 41, - "column": 6 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssertStatement", - "test": { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 42, - "column": 16 - }, - "end": { - "line": 42, - "column": 21 - } - } - }, - "second": { - "type": "StringLiteral", - "value": "Error! x.union0 must be instanceof B|C", - "loc": { - "start": { - "line": 42, - "column": 23 - }, - "end": { - "line": 42, - "column": 63 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 9 - }, - "end": { - "line": 42, - "column": 64 - } - } - } - ], - "loc": { - "start": { - "line": 41, - "column": 12 - }, - "end": { - "line": 43, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 12 - }, - "end": { - "line": 43, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 5 - }, - "end": { - "line": 43, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 36, - "column": 25 - }, - "end": { - "line": 44, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 13 - }, - "end": { - "line": 44, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 13 - }, - "end": { - "line": 44, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 1 - }, - "end": { - "line": 44, - "column": 2 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 46, - "column": 10 - }, - "end": { - "line": 46, - "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": 46, - "column": 10 - }, - "end": { - "line": 46, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 46, - "column": 18 - }, - "end": { - "line": 46, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 18 - }, - "end": { - "line": 46, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 18 - }, - "end": { - "line": 46, - "column": 24 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 12 - }, - "end": { - "line": 47, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 14 - }, - "end": { - "line": 47, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 14 - }, - "end": { - "line": 47, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 14 - }, - "end": { - "line": 47, - "column": 16 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 16 - }, - "end": { - "line": 47, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 16 - }, - "end": { - "line": 47, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 16 - }, - "end": { - "line": 47, - "column": 18 - } - } - } - ], - "loc": { - "start": { - "line": 47, - "column": 14 - }, - "end": { - "line": 47, - "column": 18 - } - } - } - ], - "loc": { - "start": { - "line": 47, - "column": 13 - }, - "end": { - "line": 47, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 12 - }, - "end": { - "line": 47, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 12 - }, - "end": { - "line": 47, - "column": 20 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 9 - }, - "end": { - "line": 47, - "column": 10 - } - } - }, - "init": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 25 - }, - "end": { - "line": 47, - "column": 26 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 27 - }, - "end": { - "line": 47, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 27 - }, - "end": { - "line": 47, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 27 - }, - "end": { - "line": 47, - "column": 29 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 29 - }, - "end": { - "line": 47, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 29 - }, - "end": { - "line": 47, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 29 - }, - "end": { - "line": 47, - "column": 31 - } - } - } - ], - "loc": { - "start": { - "line": 47, - "column": 27 - }, - "end": { - "line": 47, - "column": 31 - } - } - } - ], - "loc": { - "start": { - "line": 47, - "column": 26 - }, - "end": { - "line": 47, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 25 - }, - "end": { - "line": 47, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 25 - }, - "end": { - "line": 47, - "column": 32 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 47, - "column": 21 - }, - "end": { - "line": 47, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 9 - }, - "end": { - "line": 47, - "column": 34 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 47, - "column": 5 - }, - "end": { - "line": 47, - "column": 34 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 5 - }, - "end": { - "line": 48, - "column": 6 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 7 - }, - "end": { - "line": 48, - "column": 13 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 48, - "column": 5 - }, - "end": { - "line": 48, - "column": 13 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 20 - }, - "end": { - "line": 48, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 20 - }, - "end": { - "line": 48, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 20 - }, - "end": { - "line": 48, - "column": 22 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 48, - "column": 16 - }, - "end": { - "line": 48, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 5 - }, - "end": { - "line": 48, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 5 - }, - "end": { - "line": 48, - "column": 24 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 5 - }, - "end": { - "line": 49, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 9 - }, - "end": { - "line": 49, - "column": 10 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 49, - "column": 11 - }, - "end": { - "line": 49, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 49, - "column": 9 - }, - "end": { - "line": 49, - "column": 17 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 49, - "column": 5 - }, - "end": { - "line": 49, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 49, - "column": 5 - }, - "end": { - "line": 49, - "column": 19 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 5 - }, - "end": { - "line": 50, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 50, - "column": 9 - }, - "end": { - "line": 50, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 50, - "column": 5 - }, - "end": { - "line": 50, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 50, - "column": 5 - }, - "end": { - "line": 50, - "column": 12 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 6 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 7 - }, - "end": { - "line": 51, - "column": 13 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 13 - } - } - }, - "right": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 20 - }, - "end": { - "line": 51, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 20 - }, - "end": { - "line": 51, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 20 - }, - "end": { - "line": 51, - "column": 22 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 51, - "column": 16 - }, - "end": { - "line": 51, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 51, - "column": 5 - }, - "end": { - "line": 51, - "column": 24 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 9 - }, - "end": { - "line": 52, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 52, - "column": 5 - }, - "end": { - "line": 52, - "column": 12 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 53, - "column": 5 - }, - "end": { - "line": 53, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 53, - "column": 9 - }, - "end": { - "line": 53, - "column": 10 - } - } - }, - "property": { - "type": "Identifier", - "name": "union0", - "decorators": [], - "loc": { - "start": { - "line": 53, - "column": 11 - }, - "end": { - "line": 53, - "column": 17 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 53, - "column": 9 - }, - "end": { - "line": 53, - "column": 17 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 53, - "column": 5 - }, - "end": { - "line": 53, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 53, - "column": 5 - }, - "end": { - "line": 53, - "column": 19 - } - } - } - ], - "loc": { - "start": { - "line": 46, - "column": 23 - }, - "end": { - "line": 54, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 14 - }, - "end": { - "line": 54, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 46, - "column": 14 - }, - "end": { - "line": 54, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 46, - "column": 1 - }, - "end": { - "line": 54, - "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": 55, - "column": 1 - } - } -} diff --git a/ets2panda/test/compiler/ets/union_types_5.ets b/ets2panda/test/compiler/ets/union_types_5.ets deleted file mode 100644 index c99a77d48bf67e5cdfdfa5a6c843c36e955df34e..0000000000000000000000000000000000000000 --- a/ets2panda/test/compiler/ets/union_types_5.ets +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - */ - -class A { - union0: T; -} -class B { - num: int = 42 -} -class C { - num: int = 43 -} - -function foo(x: B|C) { - if (x instanceof B) { - assert x.num == 42: "Error! num field must be 42"; - } else if (x instanceof C) { - assert x.num == 43: "Error! num field must be 43"; - } else { - assert false: "Error! x must be instanceof B|C"; - } -} - -function bar(x: A) { - if (x.union0 instanceof B) { - assert x.union0.num == 42: "Error! x.union0.num field must be 42"; - } else if (x.union0 instanceof C) { - assert x.union0.num == 43: "Error! x.union0.num field must be 43"; - } else { - assert false: "Error! x.union0 must be instanceof B|C"; - } -} - -function main(): void { - let a: A = new A(); - a.union0 = new B(); - foo(a.union0); - bar(a); - a.union0 = new C(); - bar(a); - foo(a.union0); -} diff --git a/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt b/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt index 9447d6cad027d103c65b993701124e7455b4a3ba..aa1df0dcac059f43f0821df76763041792174452 100644 --- a/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt +++ b/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt @@ -494,3 +494,4 @@ } } } +TypeError: Bad operand type, the types of the operands must be boolean type. [voidTypeInBinaryOperation.ets:20:10] diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt index 9e4d3701c85ca3daee2097a52b569719d20d470d..df130879674f709131f58e8118451cf1885bee5f 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt +++ b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt @@ -46,38 +46,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 27 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 17, @@ -85,11 +60,21 @@ }, "end": { "line": 17, - "column": 27 + "column": 25 } } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 27 + } } - ], + }, "loc": { "start": { "line": 17, @@ -138,38 +123,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 18, @@ -177,11 +137,21 @@ }, "end": { "line": 18, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 18, @@ -306,38 +276,13 @@ "type": "Identifier", "name": "left", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 21 - }, - "end": { - "line": 21, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 21 - }, - "end": { - "line": 21, - "column": 31 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 21, @@ -345,11 +290,21 @@ }, "end": { "line": 21, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 21, @@ -390,38 +345,13 @@ "type": "Identifier", "name": "right", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 45 - }, - "end": { - "line": 21, - "column": 53 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 45 - }, - "end": { - "line": 21, - "column": 55 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 21, @@ -429,11 +359,21 @@ }, "end": { "line": 21, - "column": 55 + "column": 53 } } + }, + "loc": { + "start": { + "line": 21, + "column": 45 + }, + "end": { + "line": 21, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index 564772a80e03cf6561642324d5832d3b043c9566..dabdff4623bcbe79ae17ebc00332ac88bf5b23b4 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -309,35 +309,20 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 16, - "column": 8 - }, - "end": { - "line": 16, - "column": 11 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 8 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 15 - } + "end": { + "line": 16, + "column": 11 } } - ], + }, "loc": { "start": { "line": 16, @@ -386,35 +371,20 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 14 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 8 }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 18 - } + "end": { + "line": 17, + "column": 14 } } - ], + }, "loc": { "start": { "line": 17, @@ -463,40 +433,15 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], "loc": { "start": { "line": 18, @@ -504,22 +449,32 @@ }, "end": { "line": 18, - "column": 15 + "column": 14 } } }, "loc": { "start": { "line": 18, - "column": 17 + "column": 8 }, "end": { "line": 18, - "column": 18 + "column": 15 } } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 18, @@ -642,35 +597,20 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 19 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 14 }, - "loc": { - "start": { - "line": 21, - "column": 22 - }, - "end": { - "line": 21, - "column": 23 - } + "end": { + "line": 21, + "column": 19 } } - ], + }, "loc": { "start": { "line": 21, @@ -741,35 +681,20 @@ "type": "Identifier", "name": "d", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 12 - }, - "end": { - "line": 22, - "column": 16 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 12 }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 20 - } + "end": { + "line": 22, + "column": 16 } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/async_function-expected.txt b/ets2panda/test/parser/ets/async_function-expected.txt index e98df896b962f6cbae62b7fd7c410321223a39db..f9b41ad62976230f90159731e78beb366c4d2b08 100644 --- a/ets2panda/test/parser/ets/async_function-expected.txt +++ b/ets2panda/test/parser/ets/async_function-expected.txt @@ -68,60 +68,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 32 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 25 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 40 - } - } - }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -129,45 +104,55 @@ }, "end": { "line": 17, - "column": 40 + "column": 39 } } + }, + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 32 + "column": 33 }, "end": { "line": 17, "column": 40 } } - }, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 42 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 25 + "column": 32 }, "end": { "line": 17, - "column": 42 + "column": 40 } } + }, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 17, @@ -533,60 +518,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 23 - }, - "end": { - "line": 20, - "column": 30 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 23 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 38 - } - } - }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 20, @@ -594,45 +554,55 @@ }, "end": { "line": 20, - "column": 38 + "column": 37 } } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 38 + } } - ], + }, "loc": { "start": { "line": 20, - "column": 30 + "column": 31 }, "end": { "line": 20, "column": 38 } } - }, - "loc": { - "start": { - "line": 20, - "column": 23 - }, - "end": { - "line": 20, - "column": 40 - } } - }, + ], "loc": { "start": { "line": 20, - "column": 23 + "column": 30 }, "end": { "line": 20, - "column": 40 + "column": 38 } } + }, + "loc": { + "start": { + "line": 20, + "column": 23 + }, + "end": { + "line": 20, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 20, @@ -748,60 +718,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 54 - }, - "end": { - "line": 22, - "column": 61 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 54 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 62 - }, - "end": { - "line": 22, - "column": 68 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 62 - }, - "end": { - "line": 22, - "column": 69 - } - } - }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -809,45 +754,55 @@ }, "end": { "line": 22, - "column": 69 + "column": 68 } } + }, + "loc": { + "start": { + "line": 22, + "column": 62 + }, + "end": { + "line": 22, + "column": 69 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 61 + "column": 62 }, "end": { "line": 22, "column": 69 } } - }, - "loc": { - "start": { - "line": 22, - "column": 54 - }, - "end": { - "line": 22, - "column": 71 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 54 + "column": 61 }, "end": { "line": 22, - "column": 71 + "column": 69 } } + }, + "loc": { + "start": { + "line": 22, + "column": 54 + }, + "end": { + "line": 22, + "column": 71 + } } - ], + }, "loc": { "start": { "line": 22, @@ -933,60 +888,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 26 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 19 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 27 - }, - "end": { - "line": 22, - "column": 33 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 27 - }, - "end": { - "line": 22, - "column": 34 - } - } - }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -994,45 +924,55 @@ }, "end": { "line": 22, - "column": 34 + "column": 33 } } + }, + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 34 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 26 + "column": 27 }, "end": { "line": 22, "column": 34 } } - }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 36 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 19 + "column": 26 }, "end": { "line": 22, - "column": 36 + "column": 34 } } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 36 + } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/async_overload-expected.txt b/ets2panda/test/parser/ets/async_overload-expected.txt index e8b4419b7fad45a5eb861834745a232c3ea1f5f9..5e103098465eac12ce4bc95270494443db78b42d 100644 --- a/ets2panda/test/parser/ets/async_overload-expected.txt +++ b/ets2panda/test/parser/ets/async_overload-expected.txt @@ -110,60 +110,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 24 - }, - "end": { - "line": 17, - "column": 31 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 32 - }, - "end": { - "line": 17, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 32 - }, - "end": { - "line": 17, - "column": 39 - } - } - }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -171,45 +146,55 @@ }, "end": { "line": 17, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 31 + "column": 32 }, "end": { "line": 17, "column": 39 } } - }, - "loc": { - "start": { - "line": 17, - "column": 24 - }, - "end": { - "line": 17, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 24 + "column": 31 }, "end": { "line": 17, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 17, @@ -337,38 +322,13 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 26 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 21, @@ -376,11 +336,21 @@ }, "end": { "line": 21, - "column": 26 + "column": 24 } } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 26 + } } - ], + }, "loc": { "start": { "line": 21, @@ -458,60 +428,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 42 - }, - "end": { - "line": 21, - "column": 49 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 42 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 50 - }, - "end": { - "line": 21, - "column": 56 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 50 - }, - "end": { - "line": 21, - "column": 57 - } - } - }, + "end": { + "line": 21, + "column": 49 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 21, @@ -519,45 +464,55 @@ }, "end": { "line": 21, - "column": 57 + "column": 56 } } + }, + "loc": { + "start": { + "line": 21, + "column": 50 + }, + "end": { + "line": 21, + "column": 57 + } } - ], + }, "loc": { "start": { "line": 21, - "column": 49 + "column": 50 }, "end": { "line": 21, "column": 57 } } - }, - "loc": { - "start": { - "line": 21, - "column": 42 - }, - "end": { - "line": 21, - "column": 59 - } } - }, + ], "loc": { "start": { "line": 21, - "column": 42 + "column": 49 }, "end": { "line": 21, - "column": 59 + "column": 57 } } + }, + "loc": { + "start": { + "line": 21, + "column": 42 + }, + "end": { + "line": 21, + "column": 59 + } } - ], + }, "loc": { "start": { "line": 21, @@ -950,60 +905,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 29 - }, - "end": { - "line": 25, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 29 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 37 - }, - "end": { - "line": 25, - "column": 43 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 37 - }, - "end": { - "line": 25, - "column": 44 - } - } - }, + "end": { + "line": 25, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 25, @@ -1011,45 +941,55 @@ }, "end": { "line": 25, - "column": 44 + "column": 43 } } + }, + "loc": { + "start": { + "line": 25, + "column": 37 + }, + "end": { + "line": 25, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 25, - "column": 36 + "column": 37 }, "end": { "line": 25, "column": 44 } } - }, - "loc": { - "start": { - "line": 25, - "column": 29 - }, - "end": { - "line": 25, - "column": 46 - } } - }, + ], "loc": { "start": { "line": 25, - "column": 29 + "column": 36 }, "end": { "line": 25, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 25, + "column": 29 + }, + "end": { + "line": 25, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 25, @@ -1177,38 +1117,13 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 31 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1216,11 +1131,21 @@ }, "end": { "line": 29, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 29, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1298,60 +1223,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 47 - }, - "end": { - "line": 29, - "column": 54 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 47 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 55 - }, - "end": { - "line": 29, - "column": 61 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 55 - }, - "end": { - "line": 29, - "column": 62 - } - } - }, + "end": { + "line": 29, + "column": 54 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1359,45 +1259,55 @@ }, "end": { "line": 29, - "column": 62 + "column": 61 } } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 54 + "column": 55 }, "end": { "line": 29, "column": 62 } } - }, - "loc": { - "start": { - "line": 29, - "column": 47 - }, - "end": { - "line": 29, - "column": 64 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 47 + "column": 54 }, "end": { "line": 29, - "column": 64 + "column": 62 } } + }, + "loc": { + "start": { + "line": 29, + "column": 47 + }, + "end": { + "line": 29, + "column": 64 + } } - ], + }, "loc": { "start": { "line": 29, diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 74c87c249980f72fb13929b00a8298a004e67398..2007b8a7be58dbdd60a7102bfe8470e58ad5a622 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -253,60 +253,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 41 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 34 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 42 - }, - "end": { - "line": 18, - "column": 48 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 42 - }, - "end": { - "line": 18, - "column": 49 - } - } - }, + "end": { + "line": 18, + "column": 41 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], "loc": { "start": { "line": 18, @@ -314,45 +289,55 @@ }, "end": { "line": 18, - "column": 49 + "column": 48 } } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 18, + "column": 49 + } } - ], + }, "loc": { "start": { "line": 18, - "column": 41 + "column": 42 }, "end": { "line": 18, "column": 49 } } - }, - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 51 - } } - }, + ], "loc": { "start": { "line": 18, - "column": 34 + "column": 41 }, "end": { "line": 18, - "column": 51 + "column": 49 } } + }, + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 18, + "column": 51 + } } - ], + }, "loc": { "start": { "line": 18, @@ -765,60 +750,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 29 - }, - "end": { - "line": 26, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 29 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 37 - }, - "end": { - "line": 26, - "column": 43 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 37 - }, - "end": { - "line": 26, - "column": 44 - } - } - }, + "end": { + "line": 26, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 26, @@ -826,45 +786,55 @@ }, "end": { "line": 26, - "column": 44 + "column": 43 } } + }, + "loc": { + "start": { + "line": 26, + "column": 37 + }, + "end": { + "line": 26, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 26, - "column": 36 + "column": 37 }, "end": { "line": 26, "column": 44 } } - }, - "loc": { - "start": { - "line": 26, - "column": 29 - }, - "end": { - "line": 26, - "column": 46 - } } - }, + ], "loc": { "start": { "line": 26, - "column": 29 + "column": 36 }, "end": { "line": 26, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 26, + "column": 29 + }, + "end": { + "line": 26, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 26, @@ -909,60 +879,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 64 - }, - "end": { - "line": 26, - "column": 71 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 64 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 72 - }, - "end": { - "line": 26, - "column": 78 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 72 - }, - "end": { - "line": 26, - "column": 79 - } - } - }, + "end": { + "line": 26, + "column": 71 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 26, @@ -970,45 +915,55 @@ }, "end": { "line": 26, - "column": 79 + "column": 78 } } + }, + "loc": { + "start": { + "line": 26, + "column": 72 + }, + "end": { + "line": 26, + "column": 79 + } } - ], + }, "loc": { "start": { "line": 26, - "column": 71 + "column": 72 }, "end": { "line": 26, "column": 79 } } - }, - "loc": { - "start": { - "line": 26, - "column": 64 - }, - "end": { - "line": 26, - "column": 81 - } } - }, + ], "loc": { "start": { "line": 26, - "column": 64 + "column": 71 }, "end": { "line": 26, - "column": 81 + "column": 79 } } + }, + "loc": { + "start": { + "line": 26, + "column": 64 + }, + "end": { + "line": 26, + "column": 81 + } } - ], + }, "loc": { "start": { "line": 26, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 4db57e694b0b058022fa3286e98d3b410478697d..9adc24bf5003ce6ca65d8a6dcb9b75b06f74f263 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -289,60 +289,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 28 - }, - "end": { - "line": 16, - "column": 35 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 36 - }, - "end": { - "line": 16, - "column": 42 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 36 - }, - "end": { - "line": 16, - "column": 43 - } - } - }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 16, @@ -350,45 +325,55 @@ }, "end": { "line": 16, - "column": 43 + "column": 42 } } + }, + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 43 + } } - ], + }, "loc": { "start": { "line": 16, - "column": 35 + "column": 36 }, "end": { "line": 16, "column": 43 } } - }, - "loc": { - "start": { - "line": 16, - "column": 28 - }, - "end": { - "line": 16, - "column": 45 - } } - }, + ], "loc": { "start": { "line": 16, - "column": 28 + "column": 35 }, "end": { "line": 16, - "column": 45 + "column": 43 } } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 45 + } } - ], + }, "loc": { "start": { "line": 16, @@ -412,60 +397,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 26 - }, - "end": { - "line": 17, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 26 - }, - "end": { - "line": 17, - "column": 33 - } - } - }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -473,45 +433,55 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 25 + "column": 26 }, "end": { "line": 17, "column": 33 } } - }, - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 18 + "column": 25 }, "end": { "line": 17, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 17, @@ -788,60 +758,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 59 - }, - "end": { - "line": 22, - "column": 66 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 59 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 67 - }, - "end": { - "line": 22, - "column": 73 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 67 - }, - "end": { - "line": 22, - "column": 74 - } - } - }, + "end": { + "line": 22, + "column": 66 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -849,45 +794,55 @@ }, "end": { "line": 22, - "column": 74 + "column": 73 } } + }, + "loc": { + "start": { + "line": 22, + "column": 67 + }, + "end": { + "line": 22, + "column": 74 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 66 + "column": 67 }, "end": { "line": 22, "column": 74 } } - }, - "loc": { - "start": { - "line": 22, - "column": 59 - }, - "end": { - "line": 22, - "column": 76 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 59 + "column": 66 }, "end": { "line": 22, - "column": 76 + "column": 74 } } + }, + "loc": { + "start": { + "line": 22, + "column": 59 + }, + "end": { + "line": 22, + "column": 76 + } } - ], + }, "loc": { "start": { "line": 22, @@ -911,60 +866,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 18 - }, - "end": { - "line": 23, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 26 - }, - "end": { - "line": 23, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 26 - }, - "end": { - "line": 23, - "column": 33 - } - } - }, + "end": { + "line": 23, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 23, @@ -972,45 +902,55 @@ }, "end": { "line": 23, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 23, - "column": 25 + "column": 26 }, "end": { "line": 23, "column": 33 } } - }, - "loc": { - "start": { - "line": 23, - "column": 18 - }, - "end": { - "line": 23, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 23, - "column": 18 + "column": 25 }, "end": { "line": 23, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 23, @@ -1257,60 +1197,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 31 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 24 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 32 - }, - "end": { - "line": 22, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 32 - }, - "end": { - "line": 22, - "column": 39 - } - } - }, + "end": { + "line": 22, + "column": 31 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -1318,45 +1233,55 @@ }, "end": { "line": 22, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 31 + "column": 32 }, "end": { "line": 22, "column": 39 } } - }, - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 24 + "column": 31 }, "end": { "line": 22, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 22, @@ -1490,60 +1415,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 33 - } - } - }, + "end": { + "line": 29, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1551,45 +1451,55 @@ }, "end": { "line": 29, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 25 + "column": 26 }, "end": { "line": 29, "column": 33 } } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 18 + "column": 25 }, "end": { "line": 29, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1890,60 +1800,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 33 - } - } - }, + "end": { + "line": 34, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 34, @@ -1951,45 +1836,55 @@ }, "end": { "line": 34, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 34, + "column": 26 + }, + "end": { + "line": 34, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 25 + "column": 26 }, "end": { "line": 34, "column": 33 } } - }, - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 18 + "column": 25 }, "end": { "line": 34, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 34, + "column": 18 + }, + "end": { + "line": 34, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 34, @@ -2296,60 +2191,35 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 14 - }, - "end": { - "line": 38, - "column": 21 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 14 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 22 - }, - "end": { - "line": 38, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 22 - }, - "end": { - "line": 38, - "column": 29 - } - } - }, + "end": { + "line": 38, + "column": 21 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 38, @@ -2357,45 +2227,55 @@ }, "end": { "line": 38, - "column": 29 + "column": 28 } } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 38, + "column": 29 + } } - ], + }, "loc": { "start": { "line": 38, - "column": 21 + "column": 22 }, "end": { "line": 38, "column": 29 } } - }, - "loc": { - "start": { - "line": 38, - "column": 14 - }, - "end": { - "line": 38, - "column": 31 - } } - }, + ], "loc": { "start": { "line": 38, - "column": 14 + "column": 21 }, "end": { "line": 38, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 38, + "column": 14 + }, + "end": { + "line": 38, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 38, diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index dc41d3cfc8eac57f254b3d6e922bfcc066d59112..4be4d2ea48517d38274b99172e9921e0e2c1134b 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -5325,38 +5325,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 22, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 22, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -5364,11 +5339,21 @@ }, "end": { "line": 22, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index dba27704398813251870499a6e5e33e8f087ac55..cf852cc4c9f8e79ebaff9db05a99a2370c323fb4 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -299,38 +299,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -338,11 +313,21 @@ }, "end": { "line": 18, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index e485881d1f8eea8912459c005aac377cec5ce20b..2f57863379270d883e3c51ef185d743e23ee990e 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -68,38 +68,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 17, @@ -107,11 +82,21 @@ }, "end": { "line": 17, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 17, @@ -570,38 +555,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 23, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 23, @@ -609,11 +569,21 @@ }, "end": { "line": 23, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index 0fcb60e3135322a6bf7762189ad56de8f159726e..c8a3c89c3654e9524ca71a4129652428bfaec1ea 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -437,38 +437,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -476,11 +451,21 @@ }, "end": { "line": 20, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index d37fa6d8135c28a9e10d5cd4f1a6fc2cfb651f13..9b424caf23208fbe35f822459afa89f11846f049 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -450,40 +450,15 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -491,22 +466,32 @@ }, "end": { "line": 20, - "column": 16 + "column": 15 } } }, "loc": { "start": { "line": 20, - "column": 18 + "column": 14 }, "end": { "line": 20, - "column": 19 + "column": 16 } } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 50334b8aefd86e6c9ba73256d15d31c6eb73c88f..2ac81c66dd171fa491b4225ef1256f366c00ad42 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -156,38 +156,13 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 14 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -195,11 +170,21 @@ }, "end": { "line": 18, - "column": 14 + "column": 12 } } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 14 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 82e7920ea128faada8351445825cd32abbf6b8f2..5dffc7d900e674573395ae100ff05468f16059b6 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -556,38 +556,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 21, @@ -595,11 +570,21 @@ }, "end": { "line": 21, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 205d6300be37ff1f152160f3106439f3f0ced8ad..1aed437dc327df8abf08b3f8e11dca184dfc7825 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -847,38 +847,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "I", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], "loc": { "start": { "line": 25, @@ -886,11 +861,21 @@ }, "end": { "line": 25, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 25, diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index cd6fc79aa53cceb990cf77c4bb380d3d8e79db06..66b6147871606ec2d4d837e67c5ab72fea6a0ba4 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -556,38 +556,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 21, @@ -595,11 +570,21 @@ }, "end": { "line": 21, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/n_nullableTypeMissingNull-expected.txt b/ets2panda/test/parser/ets/n_nullableTypeMissingNull-expected.txt index 8e4ebb99a9ee6d99251afbd9f77be180269157e5..ac3f5bbb268f902ecbfb1a4d1d65ffe54a0db7a8 100644 --- a/ets2panda/test/parser/ets/n_nullableTypeMissingNull-expected.txt +++ b/ets2panda/test/parser/ets/n_nullableTypeMissingNull-expected.txt @@ -1 +1 @@ -SyntaxError: Invalid Type [n_nullableTypeMissingNull.ets:17:16] +SyntaxError: Unexpected token, expected: 'null'. [n_nullableTypeMissingNull.ets:17:16] diff --git a/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt b/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt index d0923f2e1557c513b44c4bfd208b6a67424ffbd8..32fb21e40b74bf5320f95e3366b48929e7c85b89 100644 --- a/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt @@ -1141,38 +1141,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 27 - }, - "end": { - "line": 31, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 27 - }, - "end": { - "line": 31, - "column": 30 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 31, @@ -1180,11 +1155,21 @@ }, "end": { "line": 31, - "column": 30 + "column": 28 } } + }, + "loc": { + "start": { + "line": 31, + "column": 27 + }, + "end": { + "line": 31, + "column": 30 + } } - ], + }, "loc": { "start": { "line": 31, @@ -1361,38 +1346,13 @@ "type": "Identifier", "name": "t", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 40 - }, - "end": { - "line": 35, - "column": 41 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 40 - }, - "end": { - "line": 35, - "column": 43 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 35, @@ -1400,11 +1360,21 @@ }, "end": { "line": 35, - "column": 43 + "column": 41 } } + }, + "loc": { + "start": { + "line": 35, + "column": 40 + }, + "end": { + "line": 35, + "column": 43 + } } - ], + }, "loc": { "start": { "line": 35, diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 7b845a475581a53fee4151647dc30c20a83d4361..7a4275b3329c44d21b6eac4df4ed0bd6933af59d 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -351,38 +351,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 14 - }, - "end": { - "line": 19, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 14 - }, - "end": { - "line": 19, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 19, @@ -390,11 +365,21 @@ }, "end": { "line": 19, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 19, diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index 28f7594bba14f3c613d0e68cbaa363b8855cdcb8..df711d1502c49da6a4a6a678fca403d1719b8860 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -120,38 +120,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -159,11 +134,21 @@ }, "end": { "line": 18, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index 62948820bc33709c34c0a0f477e5a7f7585c0331..b5a328254c9326b65170b466fedf55b3277ab123 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -508,38 +508,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, - "column": 14 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], "loc": { "start": { "line": 19, @@ -547,11 +522,21 @@ }, "end": { "line": 19, - "column": 14 + "column": 12 } } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 14 + } } - ], + }, "loc": { "start": { "line": 19, @@ -704,38 +689,13 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 24 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], "loc": { "start": { "line": 22, @@ -743,11 +703,21 @@ }, "end": { "line": 22, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 22, @@ -1234,38 +1204,13 @@ "type": "Identifier", "name": "e", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 18 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], "loc": { "start": { "line": 31, @@ -1273,11 +1218,21 @@ }, "end": { "line": 31, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 31, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 31, diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 5167140afe6d8cc2b42e257a62f0e4d4ffb9456b..78a7b9c1a8d0f1bae13a38b1bc0e8bd8dd1f5f82 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -248,38 +248,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -287,11 +262,21 @@ }, "end": { "line": 17, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 17, diff --git a/ets2panda/test/parser/ets/nullableType-expected.txt b/ets2panda/test/parser/ets/nullableType-expected.txt index 6f873f8e0e193cb33eb5f0b9c0b199957cc36015..4ffaa76dd684359644472e7adf7c6e4ac0783152 100644 --- a/ets2panda/test/parser/ets/nullableType-expected.txt +++ b/ets2panda/test/parser/ets/nullableType-expected.txt @@ -513,65 +513,35 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 16 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 19, - "column": 12 + "column": 13 }, "end": { "line": 19, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 19, @@ -612,38 +582,13 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -651,11 +596,21 @@ }, "end": { "line": 20, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 20, @@ -765,65 +720,35 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A_alias", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 34 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A_alias", + "decorators": [], "loc": { "start": { "line": 22, - "column": 24 + "column": 25 }, "end": { "line": 22, - "column": 34 + "column": 32 } } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 34 + } } - ], + }, "loc": { "start": { "line": 22, @@ -989,38 +914,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 132, - "column": 15 - }, - "end": { - "line": 132, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 132, - "column": 15 - }, - "end": { - "line": 132, - "column": 18 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 132, @@ -1028,11 +928,21 @@ }, "end": { "line": 132, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 132, + "column": 15 + }, + "end": { + "line": 132, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 132, @@ -1108,38 +1018,13 @@ "type": "Identifier", "name": "t", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 133, - "column": 18 - }, - "end": { - "line": 133, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 133, - "column": 18 - }, - "end": { - "line": 133, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 133, @@ -1147,11 +1032,21 @@ }, "end": { "line": 133, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 133, + "column": 18 + }, + "end": { + "line": 133, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 133, @@ -1188,38 +1083,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 133, - "column": 30 - }, - "end": { - "line": 133, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 133, - "column": 30 - }, - "end": { - "line": 133, - "column": 33 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 133, @@ -1227,13 +1097,23 @@ }, "end": { "line": 133, - "column": 33 + "column": 31 } } - } - ], - "loc": { - "start": { + }, + "loc": { + "start": { + "line": 133, + "column": 30 + }, + "end": { + "line": 133, + "column": 33 + } + } + }, + "loc": { + "start": { "line": 133, "column": 30 }, @@ -2028,38 +1908,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 11 - }, - "end": { - "line": 31, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 11 - }, - "end": { - "line": 31, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 31, @@ -2067,11 +1922,21 @@ }, "end": { "line": 31, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 31, + "column": 11 + }, + "end": { + "line": 31, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 31, @@ -2142,38 +2007,13 @@ "type": "Identifier", "name": "b", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 11 - }, - "end": { - "line": 32, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 11 - }, - "end": { - "line": 32, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 32, @@ -2181,11 +2021,21 @@ }, "end": { "line": 32, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 32, + "column": 11 + }, + "end": { + "line": 32, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 32, @@ -2297,38 +2147,13 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 11 - }, - "end": { - "line": 33, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 33, - "column": 11 - }, - "end": { - "line": 33, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 33, @@ -2336,11 +2161,21 @@ }, "end": { "line": 33, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 33, + "column": 11 + }, + "end": { + "line": 33, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 33, @@ -2412,80 +2247,35 @@ "type": "Identifier", "name": "d", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 13 - }, - "end": { - "line": 34, - "column": 21 - } - } - } - ], - "loc": { - "start": { - "line": 34, - "column": 12 - }, - "end": { - "line": 34, - "column": 21 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 34, - "column": 11 + "column": 14 }, "end": { "line": 34, - "column": 21 + "column": 20 } } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 34, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 34, @@ -2572,38 +2362,13 @@ "type": "Identifier", "name": "f", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 11 - }, - "end": { - "line": 35, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 11 - }, - "end": { - "line": 35, - "column": 14 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 35, @@ -2611,11 +2376,21 @@ }, "end": { "line": 35, - "column": 14 + "column": 12 } } + }, + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 14 + } } - ], + }, "loc": { "start": { "line": 35, @@ -2686,38 +2461,13 @@ "type": "Identifier", "name": "g", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 11 - }, - "end": { - "line": 36, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 11 - }, - "end": { - "line": 36, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 36, @@ -2725,17 +2475,27 @@ }, "end": { "line": 36, - "column": 16 + "column": 14 } } - } - ], - "loc": { - "start": { - "line": 36, - "column": 11 }, - "end": { + "loc": { + "start": { + "line": 36, + "column": 11 + }, + "end": { + "line": 36, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 11 + }, + "end": { "line": 36, "column": 16 } @@ -3111,75 +2871,35 @@ "type": "Identifier", "name": "generic", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 17 - }, - "end": { - "line": 42, - "column": 20 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 17 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 24 - } - } - } - ], + "end": { + "line": 42, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 42, @@ -3187,45 +2907,55 @@ }, "end": { "line": 42, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 42, + "column": 21 + }, + "end": { + "line": 42, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 42, - "column": 20 + "column": 21 }, "end": { "line": 42, - "column": 30 + "column": 24 } } - }, - "loc": { - "start": { - "line": 42, - "column": 17 - }, - "end": { - "line": 42, - "column": 32 - } } - }, + ], "loc": { "start": { "line": 42, - "column": 17 + "column": 20 }, "end": { "line": 42, - "column": 32 + "column": 30 } } + }, + "loc": { + "start": { + "line": 42, + "column": 17 + }, + "end": { + "line": 42, + "column": 32 + } } - ], + }, "loc": { "start": { "line": 42, @@ -3274,38 +3004,13 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 48 - }, - "end": { - "line": 42, - "column": 49 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 48 - }, - "end": { - "line": 42, - "column": 51 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 42, @@ -3313,11 +3018,21 @@ }, "end": { "line": 42, - "column": 51 + "column": 49 } } + }, + "loc": { + "start": { + "line": 42, + "column": 48 + }, + "end": { + "line": 42, + "column": 51 + } } - ], + }, "loc": { "start": { "line": 42, @@ -3408,38 +3123,13 @@ "type": "Identifier", "name": "h", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Char", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 11 - }, - "end": { - "line": 44, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 11 - }, - "end": { - "line": 44, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], "loc": { "start": { "line": 44, @@ -3447,11 +3137,21 @@ }, "end": { "line": 44, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 44, + "column": 11 + }, + "end": { + "line": 44, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 44, @@ -3625,75 +3325,35 @@ "type": "Identifier", "name": "gt1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 13 - }, - "end": { - "line": 47, - "column": 16 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 47, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 20 - } - } - } - ], + "end": { + "line": 47, + "column": 16 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 47, @@ -3701,45 +3361,55 @@ }, "end": { "line": 47, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 47, + "column": 17 + }, + "end": { + "line": 47, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 47, - "column": 16 + "column": 17 }, "end": { "line": 47, - "column": 26 + "column": 20 } } - }, - "loc": { - "start": { - "line": 47, - "column": 13 - }, - "end": { - "line": 47, - "column": 28 - } } - }, + ], "loc": { "start": { "line": 47, - "column": 13 + "column": 16 }, "end": { "line": 47, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 47, + "column": 13 + }, + "end": { + "line": 47, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 47, @@ -4578,35 +4248,20 @@ "type": "Identifier", "name": "narr", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 61, - "column": 14 - }, - "end": { - "line": 61, - "column": 17 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 61, + "column": 14 }, - "loc": { - "start": { - "line": 61, - "column": 20 - }, - "end": { - "line": 61, - "column": 21 - } + "end": { + "line": 61, + "column": 17 } } - ], + }, "loc": { "start": { "line": 61, @@ -4870,78 +4525,48 @@ "type": "Identifier", "name": "arron", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 24 - } - } - } - ], + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 66, - "column": 15 + "column": 16 }, "end": { "line": 66, - "column": 24 + "column": 22 } } }, "loc": { "start": { "line": 66, - "column": 33 + "column": 16 }, "end": { "line": 66, - "column": 34 + "column": 24 } } + }, + "loc": { + "start": { + "line": 66, + "column": 15 + }, + "end": { + "line": 66, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 66, @@ -5721,38 +5346,13 @@ "type": "Identifier", "name": "on", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 77, - "column": 12 - }, - "end": { - "line": 77, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 77, - "column": 12 - }, - "end": { - "line": 77, - "column": 20 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 77, @@ -5760,11 +5360,21 @@ }, "end": { "line": 77, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 77, + "column": 12 + }, + "end": { + "line": 77, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 77, @@ -6420,38 +6030,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 86, - "column": 12 - }, - "end": { - "line": 86, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 86, - "column": 12 - }, - "end": { - "line": 86, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 86, @@ -6459,11 +6044,21 @@ }, "end": { "line": 86, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 86, + "column": 12 + }, + "end": { + "line": 86, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 86, @@ -7666,38 +7261,13 @@ "type": "Identifier", "name": "bn", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 103, - "column": 12 - }, - "end": { - "line": 103, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 103, - "column": 12 - }, - "end": { - "line": 103, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], "loc": { "start": { "line": 103, @@ -7705,11 +7275,21 @@ }, "end": { "line": 103, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 103, + "column": 12 + }, + "end": { + "line": 103, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 103, @@ -8175,38 +7755,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 112, - "column": 33 - }, - "end": { - "line": 112, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 112, - "column": 33 - }, - "end": { - "line": 112, - "column": 41 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 112, @@ -8214,11 +7769,21 @@ }, "end": { "line": 112, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 112, + "column": 33 + }, + "end": { + "line": 112, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 112, @@ -8313,38 +7878,13 @@ "type": "Identifier", "name": "x", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 114, - "column": 10 - }, - "end": { - "line": 114, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 114, - "column": 10 - }, - "end": { - "line": 114, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 114, @@ -8352,11 +7892,21 @@ }, "end": { "line": 114, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 114, + "column": 10 + }, + "end": { + "line": 114, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 114, @@ -8513,38 +8063,13 @@ "type": "Identifier", "name": "y", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Long", - "decorators": [], - "loc": { - "start": { - "line": 117, - "column": 10 - }, - "end": { - "line": 117, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 117, - "column": 10 - }, - "end": { - "line": 117, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Long", + "decorators": [], "loc": { "start": { "line": 117, @@ -8552,13 +8077,23 @@ }, "end": { "line": 117, - "column": 16 + "column": 14 } } - } - ], - "loc": { - "start": { + }, + "loc": { + "start": { + "line": 117, + "column": 10 + }, + "end": { + "line": 117, + "column": 16 + } + } + }, + "loc": { + "start": { "line": 117, "column": 10 }, @@ -8800,38 +8335,13 @@ "type": "Identifier", "name": "arg1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 39 - }, - "end": { - "line": 123, - "column": 42 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 39 - }, - "end": { - "line": 123, - "column": 44 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 123, @@ -8839,11 +8349,21 @@ }, "end": { "line": 123, - "column": 44 + "column": 42 } } + }, + "loc": { + "start": { + "line": 123, + "column": 39 + }, + "end": { + "line": 123, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 123, @@ -8884,65 +8404,35 @@ "type": "Identifier", "name": "args2", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 70 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 72 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 72 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 123, - "column": 66 + "column": 67 }, "end": { "line": 123, - "column": 72 + "column": 70 } } + }, + "loc": { + "start": { + "line": 123, + "column": 67 + }, + "end": { + "line": 123, + "column": 72 + } } - ], + }, "loc": { "start": { "line": 123, @@ -8979,38 +8469,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Char", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 89 - }, - "end": { - "line": 123, - "column": 93 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 89 - }, - "end": { - "line": 123, - "column": 95 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], "loc": { "start": { "line": 123, @@ -9018,11 +8483,21 @@ }, "end": { "line": 123, - "column": 95 + "column": 93 } } + }, + "loc": { + "start": { + "line": 123, + "column": 89 + }, + "end": { + "line": 123, + "column": 95 + } } - ], + }, "loc": { "start": { "line": 123, @@ -9162,75 +8637,35 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 41 - }, - "end": { - "line": 127, - "column": 44 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 127, + "column": 41 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 46 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 48 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 48 - } - } - } - ], + "end": { + "line": 127, + "column": 44 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 127, @@ -9238,45 +8673,55 @@ }, "end": { "line": 127, - "column": 48 + "column": 46 } } + }, + "loc": { + "start": { + "line": 127, + "column": 45 + }, + "end": { + "line": 127, + "column": 48 + } } - ], + }, "loc": { "start": { "line": 127, - "column": 44 + "column": 45 }, "end": { "line": 127, - "column": 54 + "column": 48 } } - }, - "loc": { - "start": { - "line": 127, - "column": 41 - }, - "end": { - "line": 127, - "column": 55 - } } - }, + ], "loc": { "start": { "line": 127, - "column": 40 + "column": 44 }, "end": { "line": 127, - "column": 55 + "column": 54 } } + }, + "loc": { + "start": { + "line": 127, + "column": 41 + }, + "end": { + "line": 127, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 127, @@ -9297,91 +8742,51 @@ "end": { "line": 127, "column": 55 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 34 - }, - "end": { - "line": 127, - "column": 55 - } - } - } - ], - "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 66 - }, - "end": { - "line": 127, - "column": 69 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 73 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 75 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 75 - } - } - } - ], + } + } + }, + "loc": { + "start": { + "line": 127, + "column": 34 + }, + "end": { + "line": 127, + "column": 55 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 127, + "column": 66 + }, + "end": { + "line": 127, + "column": 69 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 127, @@ -9389,45 +8794,55 @@ }, "end": { "line": 127, - "column": 75 + "column": 73 } } + }, + "loc": { + "start": { + "line": 127, + "column": 70 + }, + "end": { + "line": 127, + "column": 75 + } } - ], + }, "loc": { "start": { "line": 127, - "column": 69 + "column": 70 }, "end": { "line": 127, - "column": 81 + "column": 75 } } - }, - "loc": { - "start": { - "line": 127, - "column": 66 - }, - "end": { - "line": 127, - "column": 83 - } } - }, + ], "loc": { "start": { "line": 127, - "column": 66 + "column": 69 }, "end": { "line": 127, - "column": 83 + "column": 81 } } + }, + "loc": { + "start": { + "line": 127, + "column": 66 + }, + "end": { + "line": 127, + "column": 83 + } } - ], + }, "loc": { "start": { "line": 127, @@ -9568,38 +8983,13 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 140, - "column": 37 - }, - "end": { - "line": 140, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 140, - "column": 37 - }, - "end": { - "line": 140, - "column": 40 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 140, @@ -9607,11 +8997,21 @@ }, "end": { "line": 140, - "column": 40 + "column": 38 } } + }, + "loc": { + "start": { + "line": 140, + "column": 37 + }, + "end": { + "line": 140, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 140, @@ -9648,38 +9048,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 140, - "column": 49 - }, - "end": { - "line": 140, - "column": 50 - } - } - }, - "loc": { - "start": { - "line": 140, - "column": 49 - }, - "end": { - "line": 140, - "column": 52 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 140, @@ -9687,11 +9062,21 @@ }, "end": { "line": 140, - "column": 52 + "column": 50 } } + }, + "loc": { + "start": { + "line": 140, + "column": 49 + }, + "end": { + "line": 140, + "column": 52 + } } - ], + }, "loc": { "start": { "line": 140, @@ -10079,38 +9464,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 146, - "column": 23 - }, - "end": { - "line": 146, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 146, - "column": 23 - }, - "end": { - "line": 146, - "column": 28 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 146, @@ -10118,11 +9478,21 @@ }, "end": { "line": 146, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 146, + "column": 23 + }, + "end": { + "line": 146, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 146, @@ -10209,38 +9579,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 146, - "column": 47 - }, - "end": { - "line": 146, - "column": 50 - } - } - }, - "loc": { - "start": { - "line": 146, - "column": 47 - }, - "end": { - "line": 146, - "column": 52 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 146, @@ -10248,11 +9593,21 @@ }, "end": { "line": 146, - "column": 52 + "column": 50 } } + }, + "loc": { + "start": { + "line": 146, + "column": 47 + }, + "end": { + "line": 146, + "column": 52 + } } - ], + }, "loc": { "start": { "line": 146, @@ -10702,38 +10057,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 154, - "column": 27 - }, - "end": { - "line": 154, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 154, - "column": 27 - }, - "end": { - "line": 154, - "column": 30 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 154, @@ -10741,11 +10071,21 @@ }, "end": { "line": 154, - "column": 30 + "column": 28 } } + }, + "loc": { + "start": { + "line": 154, + "column": 27 + }, + "end": { + "line": 154, + "column": 30 + } } - ], + }, "loc": { "start": { "line": 154, diff --git a/ets2panda/test/public/ast_verifier_test.cpp b/ets2panda/test/public/ast_verifier_test.cpp deleted file mode 100644 index dd36a1937988cfe8ea1ae3622f6bfae857a57f81..0000000000000000000000000000000000000000 --- a/ets2panda/test/public/ast_verifier_test.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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 "compiler/core/ASTVerifier.h" -#include "ir/astDump.h" -#include "ir/expressions/literals/stringLiteral.h" - -class ASTVerifierTest : public testing::Test { -public: - ASTVerifierTest() = default; - ~ASTVerifierTest() override = default; - - NO_COPY_SEMANTIC(ASTVerifierTest); - NO_MOVE_SEMANTIC(ASTVerifierTest); - -private: -}; - -TEST_F(ASTVerifierTest, NullParent) -{ - panda::es2panda::compiler::ASTVerifier verifier {}; - panda::es2panda::ir::StringLiteral empty_node; - - bool has_parent = verifier.HasParent(&empty_node); - auto messages = verifier.GetErrorMessages(); - - ASSERT_EQ(has_parent, false); - ASSERT_NE(messages.size(), 0); - ASSERT_EQ(messages[0], "NULL_PARENT: STR_LITERAL "); -} - -TEST_F(ASTVerifierTest, NullType) -{ - panda::es2panda::compiler::ASTVerifier verifier {}; - panda::es2panda::ir::StringLiteral empty_node; - - bool has_type = verifier.HasType(&empty_node); - auto messages = verifier.GetErrorMessages(); - - ASSERT_EQ(has_type, false); - ASSERT_NE(messages.size(), 0); - ASSERT_EQ(messages[0], "NULL_TS_TYPE: STR_LITERAL "); -} - -TEST_F(ASTVerifierTest, WithoutScope) -{ - panda::es2panda::compiler::ASTVerifier verifier {}; - panda::es2panda::ir::StringLiteral empty_node; - - bool has_scope = verifier.HasScope(&empty_node); - auto messages = verifier.GetErrorMessages(); - - ASSERT_EQ(has_scope, true); - ASSERT_EQ(messages.size(), 0); -} diff --git a/ets2panda/test/public/es2panda_public_test.cpp b/ets2panda/test/public/es2panda_public_test.cpp index 03846b4edb2ad52bc77c706bb89004f1a4cb8c28..ac368c3b7c5503f6eaf14dd6cd46208e4b3d31ce 100644 --- a/ets2panda/test/public/es2panda_public_test.cpp +++ b/ets2panda/test/public/es2panda_public_test.cpp @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2021-2022 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. diff --git a/ets2panda/util/declgenEts2Ts.cpp b/ets2panda/util/declgenEts2Ts.cpp index 0f6a124c138b60cb1fab45b382102fd2e102d176..04d61cad2e366a818f229f652c2e8e518644c593 100644 --- a/ets2panda/util/declgenEts2Ts.cpp +++ b/ets2panda/util/declgenEts2Ts.cpp @@ -205,11 +205,11 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *ets_function_typ Out("("); - GenCommaSeparated(sig->Params(), [this](varbinder::LocalVariable *param) { + GenCommaSeparated(sig->Params(), [this](binder::LocalVariable *param) { Out(param->Name()); const auto *param_type = param->TsType(); - if (param->HasFlag(varbinder::VariableFlags::OPTIONAL) || + if (param->HasFlag(binder::VariableFlags::OPTIONAL) || param_type->HasTypeFlag(checker::TypeFlag::NULLABLE)) { Out("?"); } diff --git a/ets2panda/util/generateBin.cpp b/ets2panda/util/generateBin.cpp index 2ae99d923c3895efd796402218ffb47d365a4b1f..35bc28770c43e027698d2db99bdbe2624f13b92b 100644 --- a/ets2panda/util/generateBin.cpp +++ b/ets2panda/util/generateBin.cpp @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/util/generateBin.h b/ets2panda/util/generateBin.h index a5a3456724538fd89506cb0f612d1fb786cbf312..7118c55a7cfe6ff41c01406dab9627f608314018 100644 --- a/ets2panda/util/generateBin.h +++ b/ets2panda/util/generateBin.h @@ -1,4 +1,4 @@ -/* +/** * 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. diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index 4805f7324ce12e50960008d814038b81be8df88f..94996b7a45158d887c8334b83cfd97cc4748d191 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -15,7 +15,7 @@ #include "helpers.h" -#include "varbinder/privateBinding.h" +#include "binder/privateBinding.h" #include "checker/types/ets/types.h" #include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" @@ -532,7 +532,7 @@ util::StringView Helpers::FunctionName(ArenaAllocator *allocator, const ir::Scri return ident->Name(); } - return util::UString(varbinder::PrivateBinding::ToPrivateBinding(ident->Name()), allocator).View(); + return util::UString(binder::PrivateBinding::ToPrivateBinding(ident->Name()), allocator).View(); } break; diff --git a/ets2panda/util/helpers.h b/ets2panda/util/helpers.h index 2611e7914153a1febb170e0ce3c5d93883de6292..36984748bba147245883fed21d340c4861c4bd12 100644 --- a/ets2panda/util/helpers.h +++ b/ets2panda/util/helpers.h @@ -16,7 +16,7 @@ #ifndef ES2PANDA_UTIL_HELPERS_H #define ES2PANDA_UTIL_HELPERS_H -#include "varbinder/variableFlags.h" +#include "binder/variableFlags.h" #include "mem/pool_manager.h" #include "util/ustring.h" #include "ir/module/importSpecifier.h" @@ -24,9 +24,9 @@ #include #include -namespace panda::es2panda::varbinder { +namespace panda::es2panda::binder { class Variable; -} // namespace panda::es2panda::varbinder +} // namespace panda::es2panda::binder namespace panda::es2panda::checker { class ETSObjectType; diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index f5d6b87d989a9251c759e0300d71a9ce9f92c19a..a5c73f877dac0102aeb9d5b33c3da6c6c148cda9 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -36,21 +36,21 @@ Options::~Options() delete argparser_; } -static std::unordered_set StringToStringSet(const std::string &str) +static std::unordered_set StringToStringSet(const std::string &str) { - std::unordered_set res; + std::unordered_set res; std::string_view curr_str {str}; auto ix = curr_str.find(','); while (ix != std::string::npos) { if (ix != 0) { - res.insert(std::string(curr_str.substr(0, ix))); + res.insert(curr_str.substr(0, ix)); } curr_str = curr_str.substr(ix + 1); ix = curr_str.find(','); } if (!curr_str.empty()) { - res.insert(std::string(curr_str)); + res.insert(curr_str); } return res; }