From 66d824a2cc0b2908ff1b1c7930795d144cb8cdb2 Mon Sep 17 00:00:00 2001 From: Vsevolod Pukhov Date: Mon, 28 Jul 2025 11:14:54 +0300 Subject: [PATCH] Optimize lambdalowering-related code Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICQ856 Change-Id: Ia8fcad751d836fae34a696bb5d5094b6f2ffe05c Signed-off-by: Vsevolod Pukhov --- ets2panda/checker/ETSchecker.h | 4 +- ets2panda/checker/ets/object.cpp | 38 +++++++++++++++---- ets2panda/checker/ets/typeCreation.cpp | 29 +++++++++++++- ets2panda/checker/types/ets/etsObjectType.cpp | 3 +- ets2panda/checker/types/ets/etsObjectType.h | 5 +++ ets2panda/compiler/core/compilerImpl.cpp | 3 +- .../lowering/ets/genericBridgesLowering.cpp | 27 ++++++++++--- .../lowering/ets/genericBridgesLowering.h | 3 +- .../compiler/lowering/ets/lambdaLowering.cpp | 14 +++---- ets2panda/parser/ETSFormattedParser.cpp | 38 ++++++++++--------- ets2panda/parser/ETSparser.cpp | 2 +- ets2panda/parser/ETSparser.h | 2 + ets2panda/parser/innerSourceParser.h | 2 +- ets2panda/parser/program/program.h | 8 ++++ .../astchecker/astchecker-ets-ignored.txt | 3 ++ 15 files changed, 133 insertions(+), 48 deletions(-) diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 076eba0be4..7d85b9f15e 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -66,6 +66,7 @@ using ComputedAbstracts = ArenaUnorderedMap, ArenaUnorderedSet>>; using ArrayMap = ArenaUnorderedMap, ETSArrayType *, PairHash>; using ObjectInstantiationMap = ArenaUnorderedMap>; +using FunctionTypeInstantiationMap = std::unordered_map; using GlobalArraySignatureMap = ArenaUnorderedMap; using DynamicCallIntrinsicsMap = ArenaUnorderedMap>; using FunctionSignatureMap = ArenaUnorderedMap; @@ -214,7 +215,7 @@ public: Type *MaybeGradualType(ir::AstNode *node, ETSObjectType *type); Type *BuildBasicInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl); ETSObjectType *GetSuperType(ETSObjectType *type); - ArenaVector GetInterfaces(ETSObjectType *type); + ArenaVector const &GetInterfaces(ETSObjectType *type); void GetInterfacesOfClass(ETSObjectType *type); void GetInterfacesOfInterface(ETSObjectType *type); void ValidateImplementedInterface(ETSObjectType *type, Type *interface, std::unordered_set *extendsSet, @@ -1107,6 +1108,7 @@ private: ArrayMap arrayTypes_; std::vector pendingConstraintCheckRecords_ {}; ObjectInstantiationMap objectInstantiationMap_; + FunctionTypeInstantiationMap functionTypeInstantiationMap_; // not an arena container FunctionSignatureMap invokeToArrowSignatures_; FunctionInterfaceMap arrowToFuncInterfaces_; size_t constraintCheckScopesCount_ {0}; diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index e42f1d760e..b042232d8e 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -285,7 +285,7 @@ void ETSChecker::GetInterfacesOfInterface(ETSObjectType *type) type->AddObjectFlag(ETSObjectFlags::RESOLVED_INTERFACES); } -ArenaVector ETSChecker::GetInterfaces(ETSObjectType *type) +ArenaVector const &ETSChecker::GetInterfaces(ETSObjectType *type) { ES2PANDA_ASSERT(type->GetDeclNode()->IsClassDefinition() || type->GetDeclNode()->IsTSInterfaceDeclaration()); @@ -2398,6 +2398,20 @@ void ETSChecker::WarnForEndlessLoopInGetterSetter(const ir::MemberExpression *co } } +[[maybe_unused]] static std::unordered_set CollectInstancePropsTransitive(ETSObjectType *classType) +{ + std::unordered_set transitivePropNames; + for (auto const t : classType->TransitiveSupertypes()) { + for (auto const p : t->InstanceMethods()) { + transitivePropNames.insert(p.first); + } + for (auto const p : t->InstanceFields()) { + transitivePropNames.insert(p.first); + } + } + return transitivePropNames; +} + void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef) { if (classType->SuperType() == nullptr) { @@ -2405,6 +2419,8 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini } const auto &allProps = classType->GetAllProperties(); + auto const interfaceList = GetInterfaces(classType); + auto const instancePropNamesTransitive = CollectInstancePropsTransitive(classType); for (auto *it : allProps) { auto *node = it->Declaration()->Node(); @@ -2412,21 +2428,26 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini node->AsClassProperty()->TsType()->IsTypeError()) { continue; } + if (instancePropNamesTransitive.find(it->Name()) == instancePropNamesTransitive.end()) { + continue; + } - const auto searchFlag = PropertySearchFlags::SEARCH_ALL | PropertySearchFlags::SEARCH_IN_BASE | - PropertySearchFlags::SEARCH_IN_INTERFACES | - PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION; - auto *foundInSuper = classType->SuperType()->GetProperty(it->Name(), searchFlag); + const auto searchFlagsSuper = PropertySearchFlags::SEARCH_INSTANCE | PropertySearchFlags::SEARCH_IN_BASE | + PropertySearchFlags::SEARCH_IN_INTERFACES | + PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION; + auto *foundInSuper = classType->SuperType()->GetProperty(it->Name(), searchFlagsSuper); ETSObjectType *interfaceFound = nullptr; if (foundInSuper != nullptr) { CheckProperties(classType, classDef, it, foundInSuper, interfaceFound); } - auto interfaceList = GetInterfaces(classType); varbinder::LocalVariable *foundInInterface = nullptr; for (auto *interface : interfaceList) { - auto *propertyFound = interface->GetProperty(it->Name(), searchFlag); + const auto searchFlagsInterfaces = PropertySearchFlags::SEARCH_INSTANCE_METHOD | + PropertySearchFlags::SEARCH_IN_INTERFACES | + PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION; + auto *propertyFound = interface->GetProperty(it->Name(), searchFlagsInterfaces); if (propertyFound == nullptr) { continue; } @@ -2726,7 +2747,8 @@ void ETSChecker::CheckInvokeMethodsLegitimacy(ETSObjectType *const classType) } auto searchFlag = PropertySearchFlags::SEARCH_IN_INTERFACES | PropertySearchFlags::SEARCH_IN_BASE | - PropertySearchFlags::SEARCH_STATIC_METHOD; + PropertySearchFlags::SEARCH_STATIC_METHOD | + PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION; auto *const invokeMethod = classType->GetProperty(compiler::Signatures::STATIC_INVOKE_METHOD, searchFlag); if (invokeMethod == nullptr) { diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 0647747376..f7732b08aa 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -180,7 +180,34 @@ ETSTypeAliasType *ETSChecker::CreateETSTypeAliasType(util::StringView name, cons ETSFunctionType *ETSChecker::CreateETSArrowType(Signature *signature) { - return ProgramAllocator()->New(this, signature); + // ASSERT(!signature->HasFunction()); + // ASSERT(signature->Owner() == nullptr); + + std::stringstream ss; + ss << "/" << helpers::ToUnderlying(signature->Flags()); + ss << "/"; + for (auto p : signature->GetSignatureInfo()->typeParams) { + ss << ":" << p; + } + ss << "/" << signature->GetSignatureInfo()->minArgCount; + ss << "/r" << signature->ReturnType(); + ss << "/"; + for (auto p : signature->GetSignatureInfo()->params) { + ss << ":" << p->TsType(); + } + auto restVar = signature->GetSignatureInfo()->restVar; + if (restVar != nullptr) { + ss << "/" << restVar->TsType(); + } + auto hash = ss.str(); + + auto &cache = functionTypeInstantiationMap_; + if (auto it = cache.find(hash); it != cache.end()) { + return it->second; + } + auto type = ProgramAllocator()->New(this, signature); + cache.insert({hash, type}); + return type; } ETSFunctionType *ETSChecker::CreateETSMethodType(util::StringView name, ArenaVector &&signatures) diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 1d42b6745b..249f855b7f 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -771,7 +771,8 @@ ETSFunctionType *ETSObjectType::GetFunctionalInterfaceInvokeType() const std::string invokeName = checker->FunctionalInterfaceInvokeName(foundArity, hasRest); auto *invoke = GetProperty(util::StringView(invokeName), - PropertySearchFlags::SEARCH_INSTANCE_METHOD | PropertySearchFlags::SEARCH_IN_INTERFACES); + PropertySearchFlags::SEARCH_INSTANCE_METHOD | PropertySearchFlags::SEARCH_IN_INTERFACES | + PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION); ES2PANDA_ASSERT(invoke != nullptr && invoke->TsType() != nullptr && invoke->TsType()->IsETSFunctionType()); return invoke->TsType()->AsETSFunctionType(); } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 5cd5fd3941..fb35e25483 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -212,6 +212,11 @@ public: return baseType_; } + const ArenaSet &TransitiveSupertypes() const noexcept + { + return transitiveSupertypes_; + } + ETSObjectType const *GetConstOriginalBaseType() const noexcept; ETSObjectType *GetOriginalBaseType() const noexcept diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index cd36b35536..aa7451f0d2 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -83,10 +83,9 @@ static public_lib::Context::CodeGenCb MakeCompileJob() return [](public_lib::Context *context, varbinder::FunctionScope *scope, compiler::ProgramElement *programElement) -> void { RegSpiller regSpiller; - ArenaAllocator allocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); AstCompiler astcompiler; compiler::SetPhaseManager(context->phaseManager); - CodeGen cg(&allocator, ®Spiller, context, std::make_tuple(scope, programElement, &astcompiler)); + CodeGen cg(context->Allocator(), ®Spiller, context, std::make_tuple(scope, programElement, &astcompiler)); FunctionEmitter funcEmitter(&cg, programElement); funcEmitter.Generate(); }; diff --git a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp index 7ec0e78cdb..8a96cc13a2 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp @@ -294,9 +294,28 @@ GenericBridgesPhase::Substitutions GenericBridgesPhase::GetSubstitutions( return substitutions; } -void GenericBridgesPhase::ProcessInterfaces(ir::ClassDefinition *const classDefinition, - ArenaVector const &interfaces) const +static std::unordered_set CollectInterfacesTransitive(checker::ETSObjectType *type) { + std::unordered_set collected; + + auto traverse = [&collected](auto &&self, checker::ETSObjectType *t) { + if (t->TypeArguments().empty() || !collected.insert(t).second) { + return; + } + for (auto itf : t->Interfaces()) { + self(self, itf); + } + }; + for (auto itf : type->Interfaces()) { + traverse(traverse, itf); + } + return collected; +} + +void GenericBridgesPhase::ProcessInterfaces(ir::ClassDefinition *const classDefinition) const +{ + auto interfaces = CollectInterfacesTransitive(classDefinition->TsType()->AsETSObjectType()); + for (auto const *interfaceType : interfaces) { auto const &typeParameters = interfaceType->GetConstOriginalBaseType()->AsETSObjectType()->TypeArguments(); if (!typeParameters.empty()) { @@ -307,15 +326,13 @@ void GenericBridgesPhase::ProcessInterfaces(ir::ClassDefinition *const classDefi CreateGenericBridges(classDefinition, substitutions, interfaceBody); } } - - ProcessInterfaces(classDefinition, interfaceType->Interfaces()); } } ir::ClassDefinition *GenericBridgesPhase::ProcessClassDefinition(ir::ClassDefinition *const classDefinition) const { // Check class interfaces. - ProcessInterfaces(classDefinition, classDefinition->TsType()->AsETSObjectType()->Interfaces()); + ProcessInterfaces(classDefinition); // Check if the base class is a generic class. if (classDefinition->Super() == nullptr || classDefinition->Super()->TsType() == nullptr || diff --git a/ets2panda/compiler/lowering/ets/genericBridgesLowering.h b/ets2panda/compiler/lowering/ets/genericBridgesLowering.h index a15c7ed01d..82010dae31 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.h +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.h @@ -38,8 +38,7 @@ private: ir::ClassDefinition *ProcessClassDefinition(ir::ClassDefinition *classDefinition) const; - void ProcessInterfaces(ir::ClassDefinition *classDefinition, - ArenaVector const &interfaces) const; + void ProcessInterfaces(ir::ClassDefinition *classDefinition) const; Substitutions GetSubstitutions(checker::ETSObjectType const *const objectType, ArenaVector const &typeParameters) const; diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index 753115eafd..a1212a09a8 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -1473,8 +1473,11 @@ static ir::AstNode *InsertInvokeCall(public_lib::Context *ctx, ir::CallExpressio util::StringView invokeMethodName = util::UString {checker->FunctionalInterfaceInvokeName(arity, hasRestParam), allocator}.View(); - auto *prop = ifaceType->GetProperty(invokeMethodName, checker::PropertySearchFlags::SEARCH_INSTANCE_METHOD | - checker::PropertySearchFlags::SEARCH_IN_INTERFACES); + auto *prop = + ifaceType->GetProperty(invokeMethodName, checker::PropertySearchFlags::SEARCH_INSTANCE_METHOD | + checker::PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION | + checker::PropertySearchFlags::SEARCH_IN_BASE | + checker::PropertySearchFlags::SEARCH_IN_INTERFACES); ES2PANDA_ASSERT(prop != nullptr); auto *invoke0Id = allocator->New(invokeMethodName, allocator); ES2PANDA_ASSERT(invoke0Id != nullptr); @@ -1573,12 +1576,7 @@ static ir::AstNode *BuildLambdaClassWhenNeeded(public_lib::Context *ctx, ir::Ast mexpr->TsType()->IsETSFunctionType() && mexpr->Object()->TsType()->IsETSObjectType() && mexpr->PropVar() != nullptr && !mexpr->PropVar()->HasFlag(varbinder::VariableFlags::DYNAMIC)) { ES2PANDA_ASSERT(mexpr->Property()->IsIdentifier()); - auto *var = mexpr->Object()->TsType()->AsETSObjectType()->GetProperty( - mexpr->Property()->AsIdentifier()->Name(), - checker::PropertySearchFlags::SEARCH_INSTANCE_METHOD | - checker::PropertySearchFlags::SEARCH_STATIC_METHOD | checker::PropertySearchFlags::SEARCH_IN_BASE | - checker::PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION); - if (IsValidFunctionDeclVar(var) && !IsInCalleePosition(mexpr) && !IsOverloadedName(mexpr)) { + if (IsValidFunctionDeclVar(mexpr->PropVar()) && !IsInCalleePosition(mexpr) && !IsOverloadedName(mexpr)) { return ConvertFunctionReference(ctx, mexpr); } } diff --git a/ets2panda/parser/ETSFormattedParser.cpp b/ets2panda/parser/ETSFormattedParser.cpp index b3acf5e559..8a452c7d20 100644 --- a/ets2panda/parser/ETSFormattedParser.cpp +++ b/ets2panda/parser/ETSFormattedParser.cpp @@ -15,6 +15,7 @@ #include "ETSparser.h" +#include "lexer/ETSLexer.h" #include "lexer/lexer.h" #include "ir/typeNode.h" #include "ir/expressions/identifier.h" @@ -283,9 +284,8 @@ ArenaVector &ETSParser::ParseExpressionsArrayFormatPlaceholder ir::Statement *ETSParser::CreateStatement(std::string_view const sourceCode) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer::SourcePosition const startLoc = lexer->GetToken().Start(); lexer->NextToken(); @@ -334,9 +334,8 @@ ir::Statement *ETSParser::CreateFormattedStatement(std::string_view const source ir::TypeNode *ETSParser::CreateFormattedTypeAnnotation(std::string_view const sourceCode) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer->NextToken(); TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::NO_OPTS; return ParseTypeAnnotation(&options); @@ -353,9 +352,8 @@ ir::TypeNode *ETSParser::CreateFormattedTypeAnnotation(std::string_view const so ArenaVector ETSParser::CreateStatements(std::string_view const sourceCode) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer->NextToken(); return ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); @@ -423,9 +421,8 @@ ir::AstNode *ETSParser::CreateFormattedClassElement(std::string_view sourceCode, ir::AstNode *ETSParser::CreateClassElement(std::string_view sourceCode, const ArenaVector &properties, ir::ClassDefinitionModifiers modifiers) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); auto savedCtx = SavedStatusContext(&GetContext()); SavedClassPrivateContext classContext(this); @@ -447,9 +444,8 @@ ir::Statement *ETSParser::CreateFormattedClassDeclaration(std::string_view sourc ir::Statement *ETSParser::CreateClassDeclaration(std::string_view sourceCode, bool allowStatic) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); auto savedCtx = SavedStatusContext(&GetContext()); @@ -490,9 +486,8 @@ ir::Statement *ETSParser::CreateClassDeclaration(std::string_view sourceCode, bo ir::MethodDefinition *ETSParser::CreateConstructorDefinition(ir::ModifierFlags modifiers, std::string_view const sourceCode) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); auto const startLoc = Lexer()->GetToken().Start(); Lexer()->NextToken(); @@ -523,9 +518,8 @@ ir::MethodDefinition *ETSParser::CreateConstructorDefinition(ir::ModifierFlags m ir::Expression *ETSParser::CreateExpression(std::string_view const sourceCode, ExpressionParseFlags const flags) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer->NextToken(); @@ -550,11 +544,20 @@ ir::Expression *ETSParser::CreateFormattedExpression(std::string_view const sour return returnExpression; } -ir::Statement *ETSParser::CreateTopLevelStatement(std::string_view const sourceCode) +[[nodiscard]] std::unique_ptr ETSParser::InitFormattedLexer( + [[maybe_unused]] std::string_view formattedName, std::string_view sourceCode) { util::UString source {sourceCode, Allocator()}; + GetProgram()->SetSource(source.View().Utf8(), util::Path(), ""); + auto lexer = std::make_unique(&GetContext(), DiagnosticEngine()); + SetLexer(lexer.get()); + return lexer; +} + +ir::Statement *ETSParser::CreateTopLevelStatement(std::string_view const sourceCode) +{ auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer->NextToken(); @@ -572,9 +575,8 @@ ir::Statement *ETSParser::CreateFormattedTopLevelStatement(std::string_view cons ir::TypeNode *ETSParser::CreateTypeAnnotation(TypeAnnotationParsingOptions *options, std::string_view const sourceCode) { - util::UString source {sourceCode, Allocator()}; auto const isp = InnerSourceParser(this); - auto const lexer = InitLexer({GetContext().FormattingFileName(), source.View().Utf8()}); + auto const lexer = InitFormattedLexer(GetContext().FormattingFileName(), sourceCode); lexer->NextToken(); return ParseTypeAnnotation(options); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 7847a5b899..d6884b22c3 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2463,7 +2463,7 @@ InnerSourceParser::InnerSourceParser(ETSParser *parser) : parser_(parser), savedLexer_(parser_->Lexer()), savedSourceCode_(parser_->GetProgram()->SourceCode()), - savedSourceFile_(parser_->GetProgram()->SourceFilePath()), + savedSourceFile_(parser_->GetProgram()->SourceFile()), savedSourceFilePath_(parser_->GetProgram()->SourceFileFolder()), savedRelativeFilePath_(parser_->GetProgram()->RelativeFilePath()) { diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index bd8fcb7b1c..ed59222b4d 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -160,6 +160,8 @@ private: ArenaVector &ParseAstNodesArrayFormatPlaceholder() override; ArenaVector &ParseStatementsArrayFormatPlaceholder() override; ArenaVector &ParseExpressionsArrayFormatPlaceholder() override; + [[nodiscard]] std::unique_ptr InitFormattedLexer(std::string_view formattedName, + std::string_view sourceCode); ir::Statement *CreateStatement(std::string_view sourceCode); ir::MethodDefinition *CreateConstructorDefinition(ir::ModifierFlags modifiers, std::string_view sourceCode); ir::Statement *CreateClassDeclaration(std::string_view sourceCode, bool allowStatic = false); diff --git a/ets2panda/parser/innerSourceParser.h b/ets2panda/parser/innerSourceParser.h index c8d1385747..e3c31989bb 100644 --- a/ets2panda/parser/innerSourceParser.h +++ b/ets2panda/parser/innerSourceParser.h @@ -42,7 +42,7 @@ private: ETSParser *parser_; lexer::Lexer *savedLexer_; util::StringView savedSourceCode_ {}; - util::StringView savedSourceFile_ {}; + util::Path savedSourceFile_ {}; util::StringView savedSourceFilePath_ {}; util::StringView savedRelativeFilePath_ {}; }; diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index 5056378116..0eaed07c3b 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -226,6 +226,14 @@ public: packageStartPosition_ = start; } + void SetSource(const util::StringView &sourceCode, const util::Path &sourceFilePath, + const util::StringView &sourceFileFolder) + { + sourceCode_ = sourceCode; + sourceFile_ = sourceFilePath; + sourceFileFolder_ = sourceFileFolder; + } + void SetSource(const util::StringView &sourceCode, const util::StringView &sourceFilePath, const util::StringView &sourceFileFolder) { diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index 0e1295d271..29b4943a94 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -168,3 +168,6 @@ ast/parser/ets/staticFunctionCallOfObject.ets ast/compiler/ets/export_type_class_multiple_times.ets ast/compiler/ets/export_type_interface_multiple_times.ets ast/compiler/ets/import_tests/export_multi_error.ets + +ast/compiler/ets/variance_typeparam_lambda.ets +ast/compiler/ets/first_match/override.ets -- Gitee