예제 #1
0
            public string CastJniToUno(DataType unoType, string line, bool stackArg)
            {
                var unbox = stackArg ? "UnBox" : "UnBoxFreeingLocalRef";

                if (_helpers.IsPrimitive(unoType) || unoType.IsEnum)
                {
                    return("(@{" + unoType.FullName + "})" + line);
                }
                if (unoType == _essentials.String)
                {
                    return("JniHelper::JavaToUnoString((jstring)" + line + ")");
                }
                if (IsJavaObject(unoType))
                {
                    return("(@{" + unoType.FullName + "})@{global::Android.Base.Wrappers.JavaObjectHelper.JObjectToJWrapper(global::Android.Base.Primitives.ujobject,bool):Call(" + line + ", " + stackArg.ToString().ToLower() + ")}");
                }
                if (unoType.IsStruct)
                {
                    return(_helpers.UnboxStruct(unoType, "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + "." + unbox + "(global::Android.Base.Primitives.ujobject):Call(" + line + ")}"));
                }
                if (!IsVoid(unoType))
                {
                    return(_helpers.CastTo(unoType, "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + "." + unbox + "(global::Android.Base.Primitives.ujobject):Call(" + line + ")}"));
                }
                throw new InvalidCastException("ForeignCode: Could not establish how to convert from '" + line + "' to the uno type '" + unoType + "'");
            }
예제 #2
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;
        }
예제 #3
0
            public JniValueCast(DataType dt, JniFreeingTechnique free, string jniTmpVarName, string unoTmpVarName,
                                Converter convert, IEssentials essentials, ForeignHelpers helpers)
            {
                JniVarName    = jniTmpVarName;
                UnoTmpVarName = unoTmpVarName;
                UnoTmpVarLet  = line => "@{" + dt.FullName + "} " + unoTmpVarName + "=" + line + ";";
                var    typeUsuallyFreed = true;
                string cast;

                if (helpers.IsPrimitive(dt) || dt.IsEnum)
                {
                    cast             = "(" + convert.Type.UnoToJniType(dt) + ")" + unoTmpVarName;
                    typeUsuallyFreed = false;
                }
                else if (dt == essentials.String)
                {
                    cast = "JniHelper::UnoToJavaString(" + unoTmpVarName + ")";
                }
                else if (convert.Type.IsJavaObject(dt))
                {
                    cast = "(" + unoTmpVarName + "==NULL ? NULL : U_JNIVAR->NewLocalRef(@{global::Android.Base.Wrappers.IJWrapper:Of((@{global::Android.Base.Wrappers.IJWrapper})" + unoTmpVarName + ")._GetJavaObject():Call()}))";
                }
                else if (dt.IsSubclassOfOrEqual(essentials.Delegate))
                {
                    var d = (DelegateType)dt;
                    cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".BoxDelegate(object,global::Android.Base.Primitives.ConstCharPtr):Call((@{object})" + unoTmpVarName + ", \"" + convert.Name.JavaDelegateName(d, true) + "\")}";
                }
                else if (convert.Type.HasJavaEquivalent(dt))
                {
                    cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(" + dt.FullName + "):Call(" + unoTmpVarName + ")}";
                }
                else if (dt.IsStruct)
                {
                    cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(object):Call(" + helpers.BoxStruct(dt, unoTmpVarName) + ")}";
                }
                else
                {
                    cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(object):Call(" + unoTmpVarName + ")}";
                }

                if (typeUsuallyFreed)
                {
                    switch (free)
                    {
                    case JniFreeingTechnique.Default:
                        Free = "if (" + JniVarName + "!=NULL) { U_JNIVAR->DeleteLocalRef(" + JniVarName + "); }";
                        break;

                    case JniFreeingTechnique.WithScope:
                        if (dt.IsStruct)                                 // no null check needed if is uno struct
                        {
                            cast = "U_JNIVAR->NewLocalRef((" + cast + "))";
                        }
                        else
                        {
                            cast = "(" + unoTmpVarName + "==NULL ? NULL : U_JNIVAR->NewLocalRef((" + cast + ")))";
                        }
                        Free = "";
                        break;

                    case JniFreeingTechnique.None:
                        Free = "";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(free), free, null);
                    }
                }
                CastSet = jniTmpVarName + " = " + cast + ";";
                CastLet = convert.Type.UnoToJniType(dt, true) + " " + CastSet;
            }