예제 #1
0
        public static void GenerateCallableDefinition(this INativeCallable callable, IGeneratable gen, IndentWriter writer)
        {
            callable.ReturnValue.GenerateDocumentation(writer);

            writer.WriteIndent();
            if (!string.IsNullOrEmpty(callable.GetModifiers(gen, writer.Options)) && !(gen is Interface))
            {
                writer.Write(callable.GetModifiers(gen, writer.Options) + " ");
            }

            var returnType = callable.GetReturnCSharpType(writer);

            // generate ReturnValue then Parameters
            var result = BuildParameters(callable, writer.Options, !callable.IsInstanceCallable(gen, writer.Options));

            writer.Write($"{returnType} {callable.Name.ToCSharp ()} ({result.TypesAndNames})");

            if (gen is Interface)
            {
                writer.Write(";");
                writer.WriteLine();
                return;
            }

            writer.WriteLine();
            writer.WriteLine("{");
            using (writer.Indent())
            {
                string prefix = returnType != "void" ? "return " : string.Empty;
                writer.WriteLine($"{prefix}{callable.CIdentifier} ({result.Names});");
            }
            writer.WriteLine("}");
        }
예제 #2
0
        public static void GenerateConstructor(this INativeCallable callable, IGeneratable parent, IndentWriter writer)
        {
            callable.ReturnValue.GenerateDocumentation(writer);

            var modifier = callable.GetModifiers(parent, writer.Options);

            var result = BuildParameters(callable, writer.Options, !callable.IsInstanceCallable(parent, writer.Options));

            // FIXME, should check to see if it is deprecated
            writer.WriteLine($"{modifier} {parent.Name} ({result.TypesAndNames}) : base ({result.Names})");
            writer.WriteLine("{");
            writer.WriteLine("}");
        }
예제 #3
0
        static void GenerateImport(this INativeCallable callable, IGeneratable parent, IndentWriter writer)
        {
            var retType = GetReturnCSharpType(callable, writer);

            var parameters = BuildParameters(callable, writer.Options, appendInstanceParameters: true);

            // TODO: Better than using the constant string, insert a custom generatable which contains the import string as a constant.

            /* i.e.
             * static class <LibraryName>Constants
             * {
             * public const string GLib = "libglib-2.0.so";
             * }
             */
            //writer.WriteLine ($"[DllImport (\"{writer.Options.LibraryName}\", CallingConvention=CallingConvention.Cdecl)]");
            writer.WriteLine($"static extern {retType} {callable.CIdentifier} ({parameters.MarshalTypesAndNames});");
            writer.WriteLine();
        }