Пример #1
0
        public UnoCallToForeignMethod(ForeignMethod fm, Converters.Converter convert, string javaMethodName)
        {
            var jniSignature = fm.JniSignature;

            // gen code for getting class, methods and potentially casting vars
            var tearDown      = new List <string>();
            var jniVarStrings = new List <string> {
                "__cls", "__mtd"
            };
            var safeVarPrefix = fm.GetSafeVarPrefixForCpp();
            var setup         = new List <string>
            {
                "INIT_JNI;",
                "jclass __cls = JniHelper::GetNativeExternClass();",
                "WITH_STATIC_JAVA_METHOD(__mtd, __cls, \"" + javaMethodName + "\", \"" + jniSignature + "\");"
            };

            if (!fm.IsStatic)
            {
                var thisCast = convert.Type.CastUnoToJni(convert.Essentials.Object, Converters.Converter.JniFreeingTechnique.Default, safeVarPrefix + "this_", safeVarPrefix + "uthis");
                setup.Add(thisCast.UnoTmpVarLet("@IL$$"));
                setup.Add(thisCast.CastLet);
                jniVarStrings.Add(thisCast.JniVarName);
                tearDown.Add(thisCast.Free);
            }

            for (var i = 0; i < fm.InitialUnoMethod.Parameters.Length; i++)
            {
                var p    = fm.InitialUnoMethod.Parameters[i];
                var jvar = convert.Type.CastUnoToJni(p.Type, Converters.Converter.JniFreeingTechnique.Default, safeVarPrefix + p.Name, safeVarPrefix + "u" + p.Name);
                setup.Add(jvar.UnoTmpVarLet("@IL$" + i));
                setup.Add(jvar.CastLet);
                jniVarStrings.Add(jvar.JniVarName);
                tearDown.Add(jvar.Free);
            }

            if (fm.UnoReturnType == convert.Essentials.String)
            {
                tearDown.Add("if (__jresult!=nullptr && U_JNIVAR->GetObjectRefType(__jresult) == JNILocalRefType) U_JNIVAR->DeleteLocalRef(__jresult);");
            }

            //--------------------------

            var call = "U_JNIVAR->" + GetJniCallFunction(fm) + "(" + string.Join(",", jniVarStrings) + ")";

            SetUp = setup;

            Recieve = convert.Type.IsVoid(fm.UnoReturnType)
                                                         ? call + ";"
                                         : convert.Type.UnoToJniType(fm.UnoReturnType) + " __jresult = " + call + ";";


            Convert = fm.UnoReturnType.IsVoid
                                                ? "" : "@{" + fm.UnoReturnType.FullName + "} __result = " + convert.Type.CastJniToUno(fm.UnoReturnType, "__jresult", false) + ";";

            TearDown = tearDown;

            Return = convert.Type.IsVoid(fm.UnoReturnType) ? "" : "return __result;";
        }
Пример #2
0
        public Entrypoints(IEnvironment env, Disk disk, IILFactory ilFactory, Converters.Converter convert)
        {
            _environment = env;
            _disk        = disk;
            _convert     = convert;

            UnoType = ilFactory.GetType("Uno.Compiler.ExportTargetInterop.Foreign.Android.ExternBlockHost");
        }
Пример #3
0
 public JavaMethod(ForeignMethod fm, ForeignHelpers helpers, Converters.Converter convert, ExpandInterceptor expandInterceptor, IEnvironment env)
 {
     _convert       = convert;
     _helpers       = helpers;
     _environment   = env;
     _foreignMethod = fm;
     _argsWithTypes = JavaMethodArgs(fm.InitialUnoMethod);
     _argsNoTypes   = JavaMethodArgs(fm.InitialUnoMethod, false);
     Source         = GenJavaMethod(fm.InitialUnoMethod, fm.JavaName, expandInterceptor);
 }
Пример #4
0
 void EnsureInitialized()
 {
     if (!_initialized)
     {
         ExpandInterceptor    = new ExpandInterceptor(InterceptEntity);
         BoxedJavaObject      = ILFactory.GetType("Java.Object");
         _initialized         = true;
         Convert              = new Converters.Converter(BoxedJavaObject, Essentials, ILFactory, Helpers);
         BlockHost            = new Entrypoints(Environment, Disk, ILFactory, Convert);
         UnoToJavaBoxingClass = ILFactory.GetType("Uno.Compiler.ExportTargetInterop.Foreign.Android.JavaUnoObject");
     }
 }
Пример #5
0
            public JavaClass(DataType dt, ForeignHelpers helpers, Converters.Converter convert, Entrypoints blockHost, IEnvironment env)
            {
                _environment = env;
                _blockHost   = blockHost;
                _helpers     = helpers;
                _convert     = convert;

                FullName = convert.Name.ComForeignClassName(dt);
                var split = FullName.LastIndexOf(".", StringComparison.Ordinal);

                _name    = FullName.Substring(split + 1);
                _package = FullName.Substring(0, split);
                _usings.AddRange(helpers.GetForeignIncludes(dt, "Java", env));
                _nested = dt.IsNestedType;
            }
Пример #6
0
 public ForeignMethod(Function f, IEssentials essentials, Converters.Converter convert, ForeignHelpers helpers, List <string> annotations)
 {
     _essentials = essentials;
     Convert     = convert;
     Helpers     = helpers;
     CppHeadersForDeclaringType = new List <string> {
         "jni.h",
         "Uno/JNIHelper.h",
         "@{global::Android.Base.Wrappers.JWrapper:Include}",
         "@{global::Android.Base.Wrappers.JavaObjectHelper:Include}",
         "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ":Include}"
     };
     Annotations = annotations;
     ValidateMethod(f, essentials);
     InitialUnoMethod = f;
     JavaName         = convert.Name.JavaMethodName(f);
 }
Пример #7
0
        public ForeignMacroExpr(DelegateType d, Converters.Converter convert, ForeignHelpers helpers)
        {
            _convert = convert;
            var source = d.Parameters.ToList();

            source.Insert(0, new Parameter(d.Source, AttributeList.Empty, 0, d, MacroParam.DelegateArgName, null));
            var uparams = source.Select(p => new MacroParam(p, convert, helpers)).ToList();

            EntrypointIncludes.AddRange(CalcImportsForExternBlock(d));
            EntrypointIncludes.AddRange(uparams.SelectMany(x => x.EntrypointIncludes));

            CppSignatureArgs = convert.Signature.GenCppSignature(uparams);
            Params           = uparams;
            JniSignature     = convert.Signature.GenJniSignature(uparams, d.ReturnType);
            ReturnType       = d.ReturnType;
            CallToUno        = GenCppToUnoCall(uparams, false, true, d.Name, d, false);
        }
Пример #8
0
        // We use this to get the data we need from the uno function in a form that is easy to use
        // in the generated c++ and java
        public ForeignMacroExpr(Function f, Converters.Converter convert, ForeignHelpers helpers)
        {
            _convert = convert;
            var source = f.Parameters.ToList();

            if (!f.IsStatic)
            {
                source.Insert(0, new Parameter(f.Source, AttributeList.Empty, 0, f.DeclaringType, MacroParam.CppThisArgName, null));
            }
            var uparams = source.Select(p => new MacroParam(p, convert, helpers)).ToList();

            EntrypointIncludes.AddRange(CalcImportsForExternBlock(f));
            EntrypointIncludes.AddRange(uparams.SelectMany(x => x.EntrypointIncludes));

            CppSignatureArgs = convert.Signature.GenCppSignature(uparams);
            Params           = uparams;
            JniSignature     = convert.Signature.GenJniSignature(uparams, f.ReturnType);
            ReturnType       = f.ReturnType;
            CallToUno        = GenCppToUnoCall(uparams, f.IsStatic, false, f.UnoName, f.DeclaringType, f.Prototype.IsConstructor);
        }
Пример #9
0
        public MacroParam(Parameter p, Converters.Converter convert, ForeignHelpers helpers)
        {
            var unoArgName = "uno_" + p.Name;
            var isThis     = (p.Name == CppThisArgName || p.Name == DelegateArgName);
            var callForm   = helpers.IsPrimitive(p.Type) || p.Type.IsEnum || p.Type.IsStruct ? unoArgName : helpers.CastTo(p.Type, unoArgName);

            UnoArgName        = unoArgName;
            Type              = p.Type;
            JniSigType        = convert.Type.UnoToJniSigType(p.Type);
            CppArgName        = p.Name + _javaArgPointerPostfix;
            CppTypedName      = UnoToJniParameter(p, convert);
            JavaArgCast       = "(" + convert.Type.UnoToJavaType(p.Type, false) + ")";
            JavaTypedName     = convert.Param.UnoToJavaParameter(p);
            JniToUnoCoversion = GenToUnoConversion(p, unoArgName, convert, helpers);
            if (!helpers.IsPrimitive(p) && p.Type.IsStruct)
            {
                Console.Write("");
            }
            CallForm      = callForm;
            HasPointerArg = convert.Type.IsJavaObject(p.Type);
            IsThis        = isThis;
        }
Пример #10
0
        public ForeignMacroExpr(Member f, bool isGetter, Converters.Converter convert, ForeignHelpers helpers)
        {
            _convert = convert;
            var source = new List <Parameter>();

            if (!isGetter)
            {
                source.Insert(0, new Parameter(f.Source, AttributeList.Empty, 0, f.ReturnType, MacroParam.CppSetArgName, null));
            }
            if (!f.IsStatic)
            {
                source.Insert(0, new Parameter(f.Source, AttributeList.Empty, 0, f.DeclaringType, MacroParam.CppThisArgName, null));
            }
            var uparams = source.Select(p => new MacroParam(p, convert, helpers)).ToList();

            EntrypointIncludes.AddRange(uparams.SelectMany(x => x.EntrypointIncludes));
            var returnType = isGetter ? f.ReturnType : convert.Type.Void;

            CppSignatureArgs = convert.Signature.GenCppSignature(uparams);
            Params           = uparams;
            JniSignature     = convert.Signature.GenJniSignature(uparams, returnType);
            ReturnType       = returnType;
            CallToUno        = GenCppToUnoGetSet(uparams, f.IsStatic, f.UnoName, f.DeclaringType, isGetter);
        }
Пример #11
0
 // convert the jni type to an uno type
 string GenToUnoConversion(Parameter arg, string unoArgName, Converters.Converter convert, ForeignHelpers helpers)
 {
     EntrypointIncludes.Add(arg.Type);
     return("@{" + arg.Type.FullName + "} " + unoArgName + " = " + convert.Type.CastJniToUno(arg.Type, arg.Name, true) + ";");
 }
Пример #12
0
 static string UnoToJniParameter(Parameter p, Converters.Converter convert)
 {
     return(convert.Type.UnoToJniType(p.Type) + " " + p.Name);
 }