Exemple #1
0
        // Gen the c++ side of the native call. This is an extern'd (JNICALL) function which translates
        // the jni types into uno types and then calls the uno method named in the macro
        string GenCppNativeMethod(ForeignMacroExpr ufunc, string name)
        {
            using (var tw = new StringWriter())
            {
                using (var ftw = new TextFormatter(tw))
                {
                    ftw.WriteLine(_convert.Type.UnoToJniType(ufunc.ReturnType) + " JNICALL " + name + "(" + ufunc.CppSignatureArgs + ")");
                    ftw.Indent("{");
                    ftw.WriteLine("uAutoReleasePool pool;");
                    ftw.WriteLine("INIT_JNI;");

                    // NEED TO UNIFY uParam & TYPE CONVERTER
                    foreach (var arg in ufunc.Params)
                    {
                        ftw.WriteLines(arg.JniToUnoCoversion);
                    }

                    var call = ufunc.CallToUno;



                    if (ufunc.ReturnType.FullName != "void")
                    {
                        // ADD CASTUNOTOJNIFORRETURN TAKE THE FM AND GENERATE THE ARGS NAMES IN TYPE CONVERTER
                        var rcast = _convert.Type.CastUnoToJni(ufunc.ReturnType, Converters.Converter.JniFreeingTechnique.WithScope, "__jresult", "__result");
                        ftw.WriteLine(_convert.Type.UnoToJniType(ufunc.ReturnType) + " " + rcast.JniVarName + ";");
                        ftw.Indent("JTRY");
                        ftw.WriteLine(rcast.UnoTmpVarLet(call));
                        ftw.WriteLine(rcast.CastSet);
                        ftw.Unindent("JCATCH");
                        ftw.WriteLine("return " + rcast.JniVarName + ";");
                    }
                    else
                    {
                        ftw.Indent("JTRY");
                        ftw.WriteLine(call + ";");
                        ftw.Unindent("JCATCH");
                    }
                    ftw.Unindent("}");

                    NativeRegistrations.Add("{(char* const)\"" + name + "\", (char* const)\"" + ufunc.JniSignature + "\", (void *)&" + name + "},");

                    return(tw.ToString());
                }
            }
        }
Exemple #2
0
        string GenJavaDelegateCode(DelegateType d, ForeignMacroExpr dEntity, string entrypointName)
        {
            using (var tw = new StringWriter())
            {
                using (var ftw = new TextFormatter(tw))
                {
                    var voidReturn = d.ReturnType.IsVoid;
                    var name       = Convert.Name.JavaDelegateName(d);
                    var fullName   = Convert.Name.JavaDelegateName(d, true);
                    var package    = fullName.Substring(0, fullName.LastIndexOf('.'));
                    var implements = (voidReturn && d.Parameters.Length == 0) ? " implements java.lang.Runnable" : "";
                    ftw.WriteLine("package " + package + ";");
                    ftw.WriteLine("import com.foreign.*;");
                    ftw.WriteLine("import com.uno.BoolArray;");
                    ftw.WriteLine("import com.uno.ByteArray;");
                    ftw.WriteLine("import com.uno.CharArray;");
                    ftw.WriteLine("import com.uno.DoubleArray;");
                    ftw.WriteLine("import com.uno.FloatArray;");
                    ftw.WriteLine("import com.uno.IntArray;");
                    ftw.WriteLine("import com.uno.LongArray;");
                    ftw.WriteLine("import com.uno.ObjectArray;");
                    ftw.WriteLine("import com.uno.ShortArray;");
                    ftw.WriteLine("import com.uno.StringArray;");
                    ftw.WriteLine("import com.uno.UnoObject;");
                    ftw.WriteLine("");
                    ftw.WriteLine("public class " + name + " extends com.uno.UnoObject" + implements);
                    ftw.Indent("{");
                    ftw.WriteLine("public " + name + "(long ptr) { super(ptr); }");

                    ftw.Indent("public " + Convert.Type.UnoToJavaType(d.ReturnType, true) + " run(" + string.Join(", ", d.Parameters.Select(Convert.Param.UnoToJavaParameter)) + ") {");

                    var args = d.Parameters.Select(x => x.Name).ToList();
                    args.Insert(0, "this");

                    ftw.WriteLine((voidReturn ? "" : "return ") + dEntity.GenCallToNativeMethod(entrypointName, args) + ";");

                    ftw.Unindent("}");

                    ftw.Unindent("}");
                    var finalStr = tw.ToString();
                    return(finalStr);
                }
            }
        }
Exemple #3
0
        internal void GenDelegatePlumbing(DelegateType d)
        {
            if (!DelegatesSeen.ContainsKey(d))
            {
                DelegateSanityCheck(d);

                var converted      = new ForeignMacroExpr(d, Convert, Helpers);
                var entrypointName = Convert.Name.GenNativeMethodName(d);

                // Generate c++ entrypoint
                BlockHost.AddCppEntrypoint(converted, entrypointName);
                BlockHost.Include(d);

                // Generate java native method
                BlockHost.NativeJavaMethods.Add(converted.GenJavaNativeMethod(entrypointName));

                // Generate java runnable/callable class
                DelegatesSeen.Add(d, GenJavaDelegateCode(d, converted, entrypointName));
            }
        }
Exemple #4
0
        string InterceptCallToUno(Function func, object callArgs)
        {
            var ufunc          = new ForeignMacroExpr(func, Convert, Helpers);
            var entrypointName = Convert.Name.GenNativeMethodName(func);

            // Add requirements
            BlockHost.RequireMember(func);
            BlockHost.Include(ufunc.EntrypointIncludes);

            // Generate c++ entrypoint
            BlockHost.AddCppEntrypoint(ufunc, entrypointName);

            // Generate java native method
            BlockHost.NativeJavaMethods.Add(ufunc.GenJavaNativeMethod(entrypointName));

            // Generate java call to java native method
            var args       = (List <string>)callArgs;
            var castedArgs = ufunc.Params.Zip(args, (x, y) => x.JavaArgCast + y);

            return(ufunc.GenCallToNativeMethod(entrypointName, new List <string>(castedArgs)));
        }
Exemple #5
0
        string InterceptProperty(string macroText, string expansionResult, Property property, object callArgs)
        {
            var isGetter       = !macroText.Contains(":Set(");
            var ufunc          = new ForeignMacroExpr(property, isGetter, Convert, Helpers);
            var entrypointName = Convert.Name.GenNativePropertyName(property, isGetter);

            // Add requirements
            BlockHost.RequireMember(property);
            BlockHost.Include(property.DeclaringType);
            BlockHost.Include(ufunc.EntrypointIncludes);

            // Generate c++ entrypoint
            BlockHost.AddCppEntrypoint(ufunc, entrypointName);

            // Generate java native method
            BlockHost.NativeJavaMethods.Add(ufunc.GenJavaNativeMethod(entrypointName));

            // Generate java call to java native method
            var args = callArgs == null ? new List <string>() : new List <string>((List <string>)callArgs);

            return(ufunc.GenCallToNativeMethod(entrypointName, args));
        }
Exemple #6
0
 public void AddCppEntrypoint(ForeignMacroExpr ufunc, string name)
 {
     _cppEntrypoints.Add(GenCppNativeMethod(ufunc, name));
 }