示例#1
0
 // All the c++ entrypoints are put in one uno class, the ExternBlockHost. This also is responsible for
 // registering the same entrypoints with the java native methods
 public void WriteCpp(ForeignHelpers helpers)
 {
     helpers.SourceInclude(_externBlockIncludes, UnoType);
     helpers.SourceDeclaration(_cppEntrypoints, UnoType);
     helpers.Require(_externBlockRequiredMembers, UnoType);
     MakeJniRegisterBlock();
 }
示例#2
0
 public TypeConverter(Converter converter, DataType boxedJavaObject, IEssentials essentials, ForeignHelpers helpers)
 {
     _helpers         = helpers;
     _convert         = converter;
     _boxedJavaObject = boxedJavaObject;
     _essentials      = essentials;
     Void             = _essentials.Void;
 }
示例#3
0
文件: JavaMethod.cs 项目: yongaru/uno
 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
		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);
		}
示例#5
0
文件: JavaClass.cs 项目: yongaru/uno
            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
		// 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);
		}
示例#7
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);
 }
示例#8
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);
		}
示例#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
 // 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) + ";");
 }
示例#11
0
 public Converter(DataType boxedJavaObject, IEssentials essentials, IILFactory ilFactory, ForeignHelpers helpers)
 {
     Essentials = essentials;
     Type       = new TypeConverter(this, boxedJavaObject, essentials, helpers);
     Name       = new NameConverter(this, ilFactory);
     Param      = new ParamConverter(this);
     Signature  = new SignatureConverter(this, essentials);
 }
示例#12
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;
            }