diff --git a/core/src/main/java/org/teavm/backend/c/CTarget.java b/core/src/main/java/org/teavm/backend/c/CTarget.java index cfba2f2b4..d54953131 100644 --- a/core/src/main/java/org/teavm/backend/c/CTarget.java +++ b/core/src/main/java/org/teavm/backend/c/CTarget.java @@ -75,6 +75,7 @@ import org.teavm.backend.c.intrinsic.StringsIntrinsic; import org.teavm.backend.c.intrinsic.StructureIntrinsic; import org.teavm.backend.lowlevel.analyze.LowLevelInliningFilterFactory; import org.teavm.backend.lowlevel.dependency.ExceptionHandlingDependencyListener; +import org.teavm.backend.lowlevel.dependency.StringsDependencyListener; import org.teavm.backend.lowlevel.dependency.WeakReferenceDependencyListener; import org.teavm.backend.lowlevel.generate.NameProvider; import org.teavm.backend.lowlevel.generate.NameProviderWithSpecialNames; @@ -324,6 +325,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { dependencyAnalyzer.linkClass(CallSiteLocation.class.getName()); dependencyAnalyzer.addDependencyListener(new ExceptionHandlingDependencyListener()); + dependencyAnalyzer.addDependencyListener(new StringsDependencyListener()); } @Override diff --git a/core/src/main/java/org/teavm/backend/lowlevel/dependency/StringsDependencyListener.java b/core/src/main/java/org/teavm/backend/lowlevel/dependency/StringsDependencyListener.java new file mode 100644 index 000000000..f3fb12ef5 --- /dev/null +++ b/core/src/main/java/org/teavm/backend/lowlevel/dependency/StringsDependencyListener.java @@ -0,0 +1,37 @@ +/* + * Copyright 2020 konsoletyper. + * + * 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. + */ +package org.teavm.backend.lowlevel.dependency; + +import org.teavm.dependency.AbstractDependencyListener; +import org.teavm.dependency.DependencyAgent; +import org.teavm.dependency.MethodDependency; +import org.teavm.model.MethodReference; + +public class StringsDependencyListener extends AbstractDependencyListener { + private static final String STRINGS_CLASS = "org.teavm.interop.Strings"; + + @Override + public void methodReached(DependencyAgent agent, MethodDependency method) { + MethodReference ref = method.getReference(); + if (ref.getClassName().equals(STRINGS_CLASS)) { + switch (ref.getName()) { + case "fromC": + case "fromC16": + method.getResult().propagate(agent.getType("java.lang.String")); + } + } + } +} diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index 12de1f6ca..b86b1924c 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -32,6 +32,7 @@ import java.util.Properties; import java.util.Set; import org.teavm.ast.decompilation.Decompiler; import org.teavm.backend.lowlevel.analyze.LowLevelInliningFilterFactory; +import org.teavm.backend.lowlevel.dependency.StringsDependencyListener; import org.teavm.backend.lowlevel.generate.NameProvider; import org.teavm.backend.lowlevel.generate.NameProviderWithSpecialNames; import org.teavm.backend.wasm.binary.BinaryWriter; @@ -330,6 +331,8 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost { dependencyAnalyzer.linkField(field.getReference()); } } + + dependencyAnalyzer.addDependencyListener(new StringsDependencyListener()); } @Override