/// <summary>
 /// Converts a value to the required type.
 /// </summary>
 /// <param name="value">The value to convert.</param>
 /// <param name="targetType">The required targt type.</param>
 public Value Convert(Value value, Type targetType)
 {
     if (value.ValueType == targetType)
     {
         return(value);
     }
     if (value.ValueType.IsValueType || value.ValueType.IsTreatedAsPtr())
     {
         return(BlockHost.CreateConversion(value, targetType));
     }
     else
     {
         Debug.Assert(!targetType.IsValueType);
         return(BlockHost.CreateCastClass(value, targetType));
     }
 }
 /// <summary>
 /// Peeks a value recursively. This method only retrieves a value
 /// from a predecessor but does not build any phi nodes.
 /// </summary>
 /// <param name="var"></param>
 /// <returns></returns>
 private Value?PeekValue(VariableRef var)
 {
     if (values.TryGetValue(var, out Value value))
     {
         return(value);
     }
     foreach (var preprocessor in predecessors)
     {
         Value?result;
         if (BlockHost.IsProcessed(preprocessor) &&
             (result = preprocessor.PeekValue(var)) != null)
         {
             return(result);
         }
     }
     return(null);
 }
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));
        }