示例#1
0
        public override bool VisitClassDecl(Class @class)
        {
            var arg    = IsByRefParameter ? $"(*{Context.ArgName})" : Context.ArgName;
            var handle = CSources.GetMonoObjectField(Options, CSources.MonoObjectFieldUsage.Parameter,
                                                     arg, "_handle");

            var @object = $"{arg} ? mono_gchandle_get_target({handle}) : 0";

            if (@class.IsValueType)
            {
                @object = $"mono_object_unbox({@object})";
            }

            if (IsByRefParameter)
            {
                var argId = GenParamId(Context);
                var objId = $"{argId}_obj";

                Context.SupportBefore.WriteLine($"MonoObject* {objId} = {@object};");
                Context.SupportBefore.WriteLine($"MonoObject* {argId} = {objId};");

                Context.SupportAfter.WriteLine($"if ({objId} != {argId})");
                Context.SupportAfter.WriteStartBraceIndent();
                Context.SupportAfter.WriteLine($"mono_embeddinator_destroy_object({arg});");
                Context.SupportAfter.WriteLine($"{arg} = ({argId} != 0) ? mono_embeddinator_create_object({argId}) : 0;");
                Context.SupportAfter.WriteCloseBraceIndent();

                Context.Return.Write($"&{argId}");
                return(true);
            }

            Context.Return.Write($"{@object}");
            return(true);
        }
        public override List <CodeGenerator> Generate(IEnumerable <TranslationUnit> units)
        {
            var unit    = units.First();
            var headers = new CHeaders(Context, unit);
            var sources = new CSources(Context, unit);

            return(new List <CodeGenerator> {
                headers, sources
            });
        }
示例#3
0
        public static string GenerateArrayTypeLookup(Type type, TextGenerator gen)
        {
            type = type.Desugar();

            if (type is BuiltinType)
            {
                var builtinType = type as BuiltinType;
                return(GetMonoClassForPrimitiveType(builtinType.Type));
            }
            else if (type is CILType)
            {
                var cilType = type as CILType;

                if (cilType.Type == typeof(string))
                {
                    return("mono_get_string_class()");
                }

                return(string.Format("mono_embeddinator_search_class(\"{0}\", \"{1}\", \"{2}\")",
                                     cilType.Type.Assembly.GetName().Name, cilType.Type.Namespace,
                                     cilType.Type.Name));
            }
            else if (type is TagType)
            {
                var tagType = type as TagType;
                var decl    = tagType.Declaration;

                var classId = $"class_{decl.QualifiedName}";
                gen.WriteLine($"{classId} = {CSources.GenerateMonoClassFromNameCall(decl)}");

                return(classId);
            }
            else if (type is ArrayType)
            {
                var arrayType = type as ArrayType;
                return("0");
            }

            throw new System.NotImplementedException();
        }