C: fix Strings.fromC/fromC16 methods

This commit is contained in:
Alexey Andreev 2020-01-30 15:41:37 +03:00
parent 2285254aa4
commit f13a7e6375
3 changed files with 42 additions and 0 deletions

View File

@ -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

View File

@ -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"));
}
}
}
}

View File

@ -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