From fa3e4968ae554dd28fbded38e8c5ef9e7ba7739a Mon Sep 17 00:00:00 2001 From: kleene Date: Sun, 3 Aug 2025 16:42:42 +0800 Subject: [PATCH] change compile mode Issue: ICQO3D Signed-off-by: kleene Change-Id: I5b4a21984a84b3ac64be7daa47adad8c03eddba0 --- ets2panda/checker/ets/helpers.cpp | 25 +++++++++++++++++++ .../build_system/src/build/base_mode.ts | 9 +++++-- ets2panda/driver/build_system/src/utils.ts | 15 ++++++++++- .../ets/namespace_tests/namespace_import1.ets | 22 ++++++++++++++++ .../ets/namespace_tests/namespace_import2.ets | 20 +++++++++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets create mode 100644 ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 535a1adc40..a8c5d64119 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -18,6 +18,7 @@ #include "checker/ETSchecker.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/gradualType.h" #include "checker/checkerContext.h" #include "checker/ETSAnalyzerHelpers.h" #include "checker/types/ets/etsEnumType.h" @@ -1706,6 +1707,26 @@ std::pair FindSpecifierForModuleObject(ir::ETSImportDecl return std::make_pair(false, util::StringView()); } +static void BuildExportedFunctionSignature(ETSChecker *checker, varbinder::Variable *var) +{ + auto method = var->AsLocalVariable()->Declaration()->Node()->AsMethodDefinition(); + ES2PANDA_ASSERT(method->Parent()->IsClassDefinition() && + method->Parent()->AsClassDefinition()->Ident()->Name().Is(compiler::Signatures::ETS_GLOBAL)); + auto classDef = method->Parent()->AsClassDefinition(); + if (classDef->TsType() == nullptr) { + checker->BuildBasicClassProperties(classDef); + } + + auto containingClass = classDef->TsType()->IsGradualType() + ? classDef->TsType()->AsGradualType()->GetBaseType()->AsETSObjectType() + : classDef->TsType()->AsETSObjectType(); + SavedCheckerContext scc(checker, checker->Context().Status(), containingClass); + auto funcType = checker->BuildMethodSignature(method); + funcType->SetVariable(var); + var->SetTsType(funcType); + method->SetTsType(funcType); +} + template void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, ir::ETSImportDeclaration *importDecl, @@ -1721,6 +1742,10 @@ void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleO if ((var->AsLocalVariable()->Declaration()->Node()->IsExported() || var->AsLocalVariable()->Declaration()->Node()->HasExportAlias()) && found) { + if (var->AsLocalVariable()->Declaration()->Node()->IsMethodDefinition()) { + BuildExportedFunctionSignature(this, var); + } + if (!aliasedName.Empty()) { moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); } diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 578de8289a..4294c512ee 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -47,7 +47,8 @@ import { createFileIfNotExists, ensurePathExists, getFileHash, - isMac + isMac, + isMixCompileProject } from '../utils'; import { PluginDriver, @@ -151,7 +152,11 @@ export abstract class BaseMode { this.isBuildConfigModified = buildConfig.isBuildConfigModified as boolean | undefined; this.hasCleanWorker = false; this.byteCodeHar = buildConfig.byteCodeHar as boolean; - this.es2pandaMode = buildConfig?.es2pandaMode ?? ES2PANDA_MODE.RUN_PARALLEL; + this.es2pandaMode = buildConfig?.es2pandaMode ?? ( + isMixCompileProject(buildConfig) + ? ES2PANDA_MODE.RUN_PARALLEL + : ES2PANDA_MODE.RUN + ); this.skipDeclCheck = buildConfig?.skipDeclCheck as boolean ?? true; } diff --git a/ets2panda/driver/build_system/src/utils.ts b/ets2panda/driver/build_system/src/utils.ts index e3a7a2bc37..d80cf572d6 100644 --- a/ets2panda/driver/build_system/src/utils.ts +++ b/ets2panda/driver/build_system/src/utils.ts @@ -21,6 +21,7 @@ import * as path from 'path'; import { ARKTS_MODULE_NAME, DECL_ETS_SUFFIX, + LANGUAGE_VERSION, NATIVE_MODULE, sdkConfigPrefix } from './pre_define'; @@ -30,7 +31,7 @@ import { LogDataFactory } from './logger'; import { ErrorCode } from './error_code'; -import { ModuleInfo, OHOS_MODULE_TYPE } from './types'; +import { BuildConfig, ModuleInfo, OHOS_MODULE_TYPE } from './types'; const WINDOWS: string = 'Windows_NT'; const LINUX: string = 'Linux'; @@ -201,3 +202,15 @@ export function createFileIfNotExists(filePath: string, content: string): boolea return false; } } + +export function isMixCompileProject(buildConfig: BuildConfig): boolean { + for (const moduleInfo of buildConfig.dependentModuleList) { + if ( + moduleInfo.language === LANGUAGE_VERSION.ARKTS_1_1 || + moduleInfo.language === LANGUAGE_VERSION.ARKTS_HYBRID + ) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets new file mode 100644 index 0000000000..00da04ded5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ns2 from "./namespace_import2" + +export function A() { + return ns2.A() +} + +export let a = 1 \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets new file mode 100644 index 0000000000..07c0f8d124 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ns1 from "./namespace_import1" + +export function A() { + return ns1.a; +} \ No newline at end of file -- Gitee