├── .editorconfig
├── .github
└── ISSUE_TEMPLATE.md
├── .gitignore
├── .jenkins.groovy
├── .jenkins.pullrequest.groovy
├── CODE-OF-CONDUCT.md
├── CODEOWNERS
├── LICENSE
├── README.md
└── src
├── Gir.Tests
├── BitFieldTests.cs
├── CallbackTests.cs
├── ClassTests.cs
├── EnumerationTests.cs
├── FunctionTests.cs
├── GenerationOptionsTests.cs
├── GenerationTestBase.cs
├── Gir.Tests.csproj
├── Gtk2
│ └── Atk
│ │ └── AtkTests.cs
├── Gtk2GirTests.cs
├── ImportantGeneratables
│ ├── GObject.cs
│ └── List.cs
├── InterfaceTests.cs
├── RecordTests.cs
├── SymbolTableTests.cs
├── Test.cs
└── TestFiles
│ ├── Gtk2
│ ├── Atk-1.0.gir
│ ├── Avahi-0.6.gir
│ ├── AvahiCore-0.6.gir
│ ├── Cally-1.0.gir
│ ├── Clutter-1.0.gir
│ ├── ClutterX11-1.0.gir
│ ├── Cogl-1.0.gir
│ ├── DBus-1.0.gir
│ ├── DBusGLib-1.0.gir
│ ├── GConf-2.0.gir
│ ├── GIRepository-2.0.gir
│ ├── GL-1.0.gir
│ ├── GLib-2.0.gir
│ ├── GMenu-2.0.gir
│ ├── GModule-2.0.gir
│ ├── GObject-2.0.gir
│ ├── GSSDP-1.0.gir
│ ├── GUPnP-1.0.gir
│ ├── Gda-4.0.gir
│ ├── Gdaui-4.0.gir
│ ├── Gdk-2.0.gir
│ ├── GdkPixbuf-2.0.gir
│ ├── GdkX11-2.0.gir
│ ├── Gio-2.0.gir
│ ├── Gtk-2.0.gir
│ ├── GtkClutter-1.0.gir
│ ├── GtkSource-2.0.gir
│ ├── JSCore-1.0.gir
│ ├── Json-1.0.gir
│ ├── Notify-0.7.gir
│ ├── Pango-1.0.gir
│ ├── PangoCairo-1.0.gir
│ ├── PangoFT2-1.0.gir
│ ├── PangoXft-1.0.gir
│ ├── Polkit-1.0.gir
│ ├── Soup-2.4.gir
│ ├── SoupGNOME-2.4.gir
│ ├── Vte-0.0.gir
│ ├── WebKit-1.0.gir
│ ├── cairo-1.0.gir
│ ├── fontconfig-2.0.gir
│ ├── freetype2-2.0.gir
│ ├── libxml2-2.0.gir
│ ├── xfixes-4.0.gir
│ ├── xft-2.0.gir
│ ├── xlib-2.0.gir
│ └── xrandr-1.3.gir
│ └── Gtk3
│ ├── Atk-1.0.gir
│ ├── GIMarshallingTests-1.0.gir
│ ├── GLib-2.0.gir
│ ├── GModule-2.0.gir
│ ├── GObject-2.0.gir
│ ├── Gdk-3.0.gir
│ ├── GdkPixbuf-2.0.gir
│ ├── Gio-2.0.gir
│ ├── Gtk-3.0.gir
│ ├── Pango-1.0.gir
│ ├── cairo-1.0.gir
│ └── xlib-2.0.gir
├── Gir.sln
└── Gir
├── Error.cs
├── Generation
├── Array.cs
├── Bitfield.cs
├── Callback.cs
├── Class.cs
├── Constant.cs
├── Constructor.cs
├── Enumeration.cs
├── Field.cs
├── Function.cs
├── IGeneratable.cs
├── IGeneratableExtensions.cs
├── IndentWriter.cs
├── Interface.cs
├── Member.cs
├── Method.cs
├── Namespace.cs
├── Property.cs
├── Record.cs
├── Repository.cs
└── Signal.cs
├── GenerationOptions.cs
├── Gir.csproj
├── Marshal
├── Alias.cs
├── Array.cs
├── Bitfield.cs
├── Callback.cs
├── Class.cs
├── Enumeration.cs
├── Field.cs
├── IPassByValue.cs
├── ISymbol.cs
├── ISymbolExtensions.cs
├── IType.cs
├── ITypeOrArray.cs
├── Interface.cs
├── Namespace.cs
├── Primitive.cs
├── Record.cs
├── Repository.cs
├── SymbolTable.Builtin.cs
├── SymbolTable.RegistrationError.cs
├── SymbolTable.cs
├── Type.cs
└── Varargs.cs
├── Model
├── Alias.cs
├── Array.cs
├── Bitfield.cs
├── CInclude.cs
├── Callback.cs
├── Class.cs
├── Constant.cs
├── Constructor.cs
├── Direction.cs
├── Documentation.cs
├── Enumeration.cs
├── Field.cs
├── Function.cs
├── Implements.cs
├── Include.cs
├── InstanceParameter.cs
├── Interface.cs
├── Member.cs
├── Method.cs
├── Namespace.cs
├── Package.cs
├── Parameter.cs
├── Prerequisite.cs
├── Property.cs
├── Record.cs
├── Repository.cs
├── ReturnValue.cs
├── Scope.cs
├── Signal.cs
├── TransferOwnership.cs
├── Type.cs
├── Union.cs
├── Varargs.cs
└── VirtualMethod.cs
├── Parser.cs
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── Schema
├── c.xsd
├── gir.xsd
├── glib.xsd
└── xml.xsd
├── Statistics.cs
└── Utils.cs
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome:http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Baseline
7 | [*]
8 | charset = utf-8
9 | indent_style = tab
10 | trim_trailing_whitespace = true
11 | max_line_length = 120
12 | end_of_line = lf
13 |
14 | # MSBuild
15 | [*.{csproj,proj,projitems,shproj,fsproj,target,props}]
16 | indent_style = space
17 | indent_size = 2
18 |
19 | # Dotnet code style settings:
20 | [*.{cs,vb}]
21 |
22 | # Sort using and Import directives with System.* appearing first
23 | dotnet_sort_system_directives_first = true
24 |
25 | # Avoid "this." and "Me." if not necessary
26 | dotnet_style_qualification_for_field = false:suggestion
27 | dotnet_style_qualification_for_property = false:suggestion
28 | dotnet_style_qualification_for_method = false:suggestion
29 | dotnet_style_qualification_for_event = false:suggestion
30 |
31 | # Use language keywords instead of framework type names for type references
32 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
33 | dotnet_style_predefined_type_for_member_access = true:suggestion
34 |
35 | # Suggest more modern language features when available
36 | dotnet_style_object_initializer = true:suggestion
37 | dotnet_style_collection_initializer = true:suggestion
38 | dotnet_style_coalesce_expression = true:suggestion
39 | dotnet_style_null_propagation = true:suggestion
40 | dotnet_style_explicit_tuple_names = true:suggestion
41 |
42 | # CSharp code style settings:
43 | [*.cs]
44 |
45 | # spaces before parens
46 | csharp_space_between_method_declaration_name_and_open_parenthesis = true
47 | csharp_space_between_method_call_name_and_opening_parenthesis = true
48 | csharp_space_after_keywords_in_control_flow_statements = true
49 |
50 | # spaces before []
51 | csharp_space_before_open_square_brackets = true
52 |
53 | # Newline settings
54 | csharp_new_line_before_open_brace = types,methods
55 | csharp_new_line_before_else = true
56 | csharp_new_line_before_catch = true
57 | csharp_new_line_before_finally = true
58 | csharp_new_line_before_members_in_object_initializers = true
59 | csharp_new_line_before_members_in_anonymous_types = true
60 |
61 | # Switch indentation
62 | csharp_indent_switch_labels = false
63 |
64 | # Prefer "var" everywhere it's apparent
65 | csharp_style_var_for_built_in_types = true:suggestion
66 | csharp_style_var_when_type_is_apparent = true:suggestion
67 | csharp_style_var_elsewhere = false:suggestion
68 |
69 | # Prefer method-like constructs to have a block body
70 | csharp_style_expression_bodied_methods = false:none
71 | csharp_style_expression_bodied_constructors = false:none
72 | csharp_style_expression_bodied_operators = false:none
73 |
74 | # Prefer property-like constructs to have an expression-body
75 | csharp_style_expression_bodied_properties = true:none
76 | csharp_style_expression_bodied_indexers = true:none
77 | csharp_style_expression_bodied_accessors = true:none
78 |
79 | # Suggest more modern language features when available
80 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
81 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
82 | csharp_style_inlined_variable_declaration = true:suggestion
83 | csharp_style_throw_expression = true:suggestion
84 | csharp_style_conditional_delegate_call = true:suggestion
85 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Steps to Reproduce
2 |
3 | 1.
4 | 2.
5 | 3.
6 |
7 |
10 |
11 | ## Current Behavior
12 |
13 |
16 |
17 | ## Expected Behavior
18 |
19 |
22 |
23 | **Version Used**:
24 |
25 |
26 | ### Stacktrace
27 |
28 | ```
29 | Please paste the stacktrace here if available.
30 | ```
31 |
32 |
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 | packages
3 | bin
4 | obj
5 | *.user
6 | .idea
7 | *.iml
8 |
--------------------------------------------------------------------------------
/.jenkins.groovy:
--------------------------------------------------------------------------------
1 | def builders = [:]
2 | // labels to build on
3 | def alltargets = ["ubuntu-1604-amd64","ubuntu-1604-i386"]
4 |
5 | for (x in alltargets) {
6 | def mainlabel = x
7 | builders[mainlabel] = {
8 | stage("Test on ${mainlabel}") {
9 | ws {
10 | git credentialsId: '56f5f1ca-b5a7-41b5-8318-c84dd4364e72', url: 'git://github.com/mono/gir-sharp.git'
11 | chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore src/Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release src/Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll"
12 | step([$class: 'XUnitPublisher', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1'], [$class: 'SkippedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1']], tools: [[$class: 'NUnit3TestType', deleteOutputFiles: true, failIfNotNew: true, pattern: '**/TestResult.xml', skipNoTestFiles: true, stopProcessingIfError: true]]])
13 | }
14 | }
15 | }
16 | }
17 |
18 | timestamps {
19 | node(alltargets[0]) {
20 | parallel builders
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/.jenkins.pullrequest.groovy:
--------------------------------------------------------------------------------
1 | def builders = [:]
2 | // labels to build on
3 | def alltargets = ["ubuntu-1604-amd64","ubuntu-1604-i386"]
4 |
5 | for (x in alltargets) {
6 | def mainlabel = x
7 | builders[mainlabel] = {
8 | stage("Test on ${mainlabel}") {
9 | ws {
10 | checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "${sha1}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[refspec: "+refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*", url: 'git://github.com/mono/gir-sharp.git']]]
11 | chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore src/Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release src/Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll"
12 | step([$class: 'XUnitPublisher', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1'], [$class: 'SkippedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1']], tools: [[$class: 'NUnit3TestType', deleteOutputFiles: true, failIfNotNew: true, pattern: '**/TestResult.xml', skipNoTestFiles: true, stopProcessingIfError: true]]])
13 | }
14 | }
15 | }
16 | }
17 |
18 | timestamps {
19 | node(alltargets[0]) {
20 | echo "${sha1}"
21 | parallel builders
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/CODE-OF-CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | This project has adopted the code of conduct defined by the Contributor Covenant
4 | to clarify expected behavior in our community.
5 |
6 | For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
7 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Gir# Code Owners File
2 | #
3 | # GitHub uses this file to determine who to assign for reviews
4 | # on pull requests. Please keep this file alphabetically sorted.
5 | #
6 | # References:
7 | #
8 | # https://github.com/blog/2392-introducing-code-owners
9 | # https://help.github.com/articles/about-codeowners
10 |
11 |
12 | # These owners will be the default owners for everything in the repo.
13 | * @Therzok @decriptor @stsundermann
14 |
15 | # Order is important. The last matching pattern has the most precedence.
16 |
17 | # /src @someone
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Mono Project
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gir-sharp
2 |
3 | # Chat
4 | * [](https://gitter.im/mono/gtk-sharp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5 |
6 | # Build Status
7 |
8 | | Branch | Status |
9 | |--------|--------|
10 | | Master |[](https://travis-ci.org/mono/gir-sharp)|
11 |
--------------------------------------------------------------------------------
/src/Gir.Tests/BitFieldTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class BitFieldTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void GenerateDocumentationWhenCompatFalse ()
11 | {
12 | var result = GenerateType (Pango, "FontMask");
13 | Assert.AreEqual (@"using System;
14 | using System.Runtime.InteropServices;
15 |
16 | namespace Pango
17 | {
18 | ///
19 | /// The bits in a #PangoFontMask correspond to fields in a
20 | /// #PangoFontDescription that have been set.
21 | ///
22 | [Flags]
23 | public enum FontMask
24 | {
25 | ///the font family is specified.
26 | Family = 0x1,
27 |
28 | ///the font style is specified.
29 | Style = 0x2,
30 |
31 | ///the font variant is specified.
32 | Variant = 0x4,
33 |
34 | ///the font weight is specified.
35 | Weight = 0x8,
36 |
37 | ///the font stretch is specified.
38 | Stretch = 0x10,
39 |
40 | ///the font size is specified.
41 | Size = 0x20,
42 |
43 | ///the font gravity is specified (Since: 1.16.)
44 | Gravity = 0x40,
45 | }
46 | }
47 | ", result);
48 | }
49 |
50 | [Test]
51 | public void GenerateNoDocumentationWhenCompatTrue ()
52 | {
53 | var result = GenerateType (Pango, "FontMask", compat: true);
54 |
55 | Assert.AreEqual (@"using System;
56 | using System.Runtime.InteropServices;
57 |
58 | namespace Pango
59 | {
60 | [Flags]
61 | public enum FontMask
62 | {
63 | Family = 0x1,
64 | Style = 0x2,
65 | Variant = 0x4,
66 | Weight = 0x8,
67 | Stretch = 0x10,
68 | Size = 0x20,
69 | Gravity = 0x40,
70 | }
71 | }
72 | ", result);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/Gir.Tests/CallbackTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class CallbackTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void TestCallbackIsGenerated ()
11 | {
12 | var result = GenerateType (Gtk3, "TreeModelFilterModifyFunc");
13 |
14 | Assert.AreEqual (@"using System;
15 | using System.Runtime.InteropServices;
16 |
17 | namespace Gtk
18 | {
19 | [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
20 | public delegate void TreeModelFilterModifyFunc (ITreeModel model, TreeIter iter, Value value, int column, IntPtr data)
21 |
22 | [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
23 | internal delegate void TreeModelFilterModifyFuncNative (ITreeModel model, TreeIter iter, Value value, int column, IntPtr data)
24 |
25 | internal static class TreeModelFilterModifyFuncWrapper
26 | {
27 | public static void NativeCallback (ITreeModel model, TreeIter iter, Value value, int column, IntPtr data)
28 | {
29 | }
30 | }
31 | }
32 | ", result);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Gir.Tests/ClassTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class ClassTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void TestClassIsGenerated ()
11 | {
12 | // Test is incomplete, as record is not fully generated atm.
13 | var result = GenerateType (Gio2, "BufferedOutputStream");
14 |
15 | // Need to map pointers at symbol level.
16 | Assert.AreEqual (@"using System;
17 | using System.Runtime.InteropServices;
18 |
19 | namespace Gio
20 | {
21 | ///
22 | /// Buffered output stream implements #GFilterOutputStream and provides
23 | /// for buffered writes.
24 | ///
25 | /// By default, #GBufferedOutputStream's buffer size is set at 4 kilobytes.
26 | ///
27 | /// To create a buffered output stream, use g_buffered_output_stream_new(),
28 | /// or g_buffered_output_stream_new_sized() to specify the buffer's size
29 | /// at construction.
30 | ///
31 | /// To get the size of a buffer within a buffered input stream, use
32 | /// g_buffered_output_stream_get_buffer_size(). To change the size of a
33 | /// buffered output stream's buffer, use
34 | /// g_buffered_output_stream_set_buffer_size(). Note that the buffer's
35 | /// size cannot be reduced below the size of the data within the buffer.
36 | ///
37 | public class BufferedOutputStream : FilterOutputStream, ISeekable
38 | {
39 | static extern OutputStream g_buffered_output_stream_new (OutputStream base_stream);
40 |
41 | ///Creates a new buffered output stream for a base stream.
42 | ///a #GOutputStream for the given @base_stream.
43 | public BufferedOutputStream (OutputStream base_stream) : base (base_stream)
44 | {
45 | }
46 |
47 | static extern OutputStream g_buffered_output_stream_new_sized (OutputStream base_stream, UIntPtr size);
48 |
49 | ///Creates a new buffered output stream with a given buffer size.
50 | ///a #GOutputStream with an internal buffer set to @size.
51 | public BufferedOutputStream (OutputStream base_stream, UIntPtr size) : base (base_stream, size)
52 | {
53 | }
54 |
55 | FilterOutputStream ParentInstance;
56 |
57 | BufferedOutputStreamPrivate Priv;
58 |
59 | static extern bool g_buffered_output_stream_get_auto_grow (BufferedOutputStream stream);
60 |
61 | ///Checks if the buffer automatically grows as data is added.
62 | ///
63 | /// %TRUE if the @stream's buffer automatically grows,
64 | /// %FALSE otherwise.
65 | ///
66 | public bool GetAutoGrow ()
67 | {
68 | return g_buffered_output_stream_get_auto_grow ();
69 | }
70 |
71 | static extern UIntPtr g_buffered_output_stream_get_buffer_size (BufferedOutputStream stream);
72 |
73 | ///Gets the size of the buffer in the @stream.
74 | ///the current size of the buffer.
75 | public UIntPtr GetBufferSize ()
76 | {
77 | return g_buffered_output_stream_get_buffer_size ();
78 | }
79 |
80 | static extern void g_buffered_output_stream_set_auto_grow (BufferedOutputStream stream, bool auto_grow);
81 |
82 | ///
83 | /// Sets whether or not the @stream's buffer should automatically grow.
84 | /// If @auto_grow is true, then each write will just make the buffer
85 | /// larger, and you must manually flush the buffer to actually write out
86 | /// the data to the underlying stream.
87 | ///
88 | public void SetAutoGrow (bool auto_grow)
89 | {
90 | g_buffered_output_stream_set_auto_grow (auto_grow);
91 | }
92 |
93 | static extern void g_buffered_output_stream_set_buffer_size (BufferedOutputStream stream, UIntPtr size);
94 |
95 | ///Sets the size of the internal buffer to @size.
96 | public void SetBufferSize (UIntPtr size)
97 | {
98 | g_buffered_output_stream_set_buffer_size (size);
99 | }
100 | }
101 | }
102 | ", result);
103 | }
104 |
105 | [Test]
106 | public void GenerateGtkAboutDialog ()
107 | {
108 | var result = GenerateType(Gtk3, "AboutDialog", true);
109 |
110 | Assert.AreEqual (@"using System;
111 | using System.Runtime.InteropServices;
112 |
113 | namespace Gtk
114 | {
115 | public class AboutDialog : Dialog, Atk.ImplementorIface, Buildable
116 | {
117 | static extern Widget gtk_about_dialog_new ();
118 |
119 | public AboutDialog () : base ()
120 | {
121 | }
122 |
123 | Dialog ParentInstance;
124 |
125 | AboutDialogPrivate Priv;
126 |
127 | static extern void gtk_about_dialog_add_credit_section (AboutDialog about, string section_name, string people);
128 |
129 | public void AddCreditSection (string section_name, string[] people)
130 | {
131 | gtk_about_dialog_add_credit_section (section_name, people);
132 | }
133 |
134 | static extern string gtk_about_dialog_get_artists (AboutDialog about);
135 |
136 | public string GetArtists ()
137 | {
138 | return gtk_about_dialog_get_artists ();
139 | }
140 |
141 | static extern string gtk_about_dialog_get_authors (AboutDialog about);
142 |
143 | public string GetAuthors ()
144 | {
145 | return gtk_about_dialog_get_authors ();
146 | }
147 |
148 | static extern string gtk_about_dialog_get_comments (AboutDialog about);
149 |
150 | public string GetComments ()
151 | {
152 | return gtk_about_dialog_get_comments ();
153 | }
154 |
155 | static extern string gtk_about_dialog_get_copyright (AboutDialog about);
156 |
157 | public string GetCopyright ()
158 | {
159 | return gtk_about_dialog_get_copyright ();
160 | }
161 |
162 | static extern string gtk_about_dialog_get_documenters (AboutDialog about);
163 |
164 | public string GetDocumenters ()
165 | {
166 | return gtk_about_dialog_get_documenters ();
167 | }
168 |
169 | static extern string gtk_about_dialog_get_license (AboutDialog about);
170 |
171 | public string GetLicense ()
172 | {
173 | return gtk_about_dialog_get_license ();
174 | }
175 |
176 | static extern License gtk_about_dialog_get_license_type (AboutDialog about);
177 |
178 | public License GetLicenseType ()
179 | {
180 | return gtk_about_dialog_get_license_type ();
181 | }
182 |
183 | static extern Pixbuf gtk_about_dialog_get_logo (AboutDialog about);
184 |
185 | public Pixbuf GetLogo ()
186 | {
187 | return gtk_about_dialog_get_logo ();
188 | }
189 |
190 | static extern string gtk_about_dialog_get_logo_icon_name (AboutDialog about);
191 |
192 | public string GetLogoIconName ()
193 | {
194 | return gtk_about_dialog_get_logo_icon_name ();
195 | }
196 |
197 | static extern string gtk_about_dialog_get_program_name (AboutDialog about);
198 |
199 | public string GetProgramName ()
200 | {
201 | return gtk_about_dialog_get_program_name ();
202 | }
203 |
204 | static extern string gtk_about_dialog_get_translator_credits (AboutDialog about);
205 |
206 | public string GetTranslatorCredits ()
207 | {
208 | return gtk_about_dialog_get_translator_credits ();
209 | }
210 |
211 | static extern string gtk_about_dialog_get_version (AboutDialog about);
212 |
213 | public string GetVersion ()
214 | {
215 | return gtk_about_dialog_get_version ();
216 | }
217 |
218 | static extern string gtk_about_dialog_get_website (AboutDialog about);
219 |
220 | public string GetWebsite ()
221 | {
222 | return gtk_about_dialog_get_website ();
223 | }
224 |
225 | static extern string gtk_about_dialog_get_website_label (AboutDialog about);
226 |
227 | public string GetWebsiteLabel ()
228 | {
229 | return gtk_about_dialog_get_website_label ();
230 | }
231 |
232 | static extern bool gtk_about_dialog_get_wrap_license (AboutDialog about);
233 |
234 | public bool GetWrapLicense ()
235 | {
236 | return gtk_about_dialog_get_wrap_license ();
237 | }
238 |
239 | static extern void gtk_about_dialog_set_artists (AboutDialog about, string artists);
240 |
241 | public void SetArtists (string[] artists)
242 | {
243 | gtk_about_dialog_set_artists (artists);
244 | }
245 |
246 | static extern void gtk_about_dialog_set_authors (AboutDialog about, string authors);
247 |
248 | public void SetAuthors (string[] authors)
249 | {
250 | gtk_about_dialog_set_authors (authors);
251 | }
252 |
253 | static extern void gtk_about_dialog_set_comments (AboutDialog about, string comments);
254 |
255 | public void SetComments (string comments)
256 | {
257 | gtk_about_dialog_set_comments (comments);
258 | }
259 |
260 | static extern void gtk_about_dialog_set_copyright (AboutDialog about, string copyright);
261 |
262 | public void SetCopyright (string copyright)
263 | {
264 | gtk_about_dialog_set_copyright (copyright);
265 | }
266 |
267 | static extern void gtk_about_dialog_set_documenters (AboutDialog about, string documenters);
268 |
269 | public void SetDocumenters (string[] documenters)
270 | {
271 | gtk_about_dialog_set_documenters (documenters);
272 | }
273 |
274 | static extern void gtk_about_dialog_set_license (AboutDialog about, string license);
275 |
276 | public void SetLicense (string license)
277 | {
278 | gtk_about_dialog_set_license (license);
279 | }
280 |
281 | static extern void gtk_about_dialog_set_license_type (AboutDialog about, License license_type);
282 |
283 | public void SetLicenseType (License license_type)
284 | {
285 | gtk_about_dialog_set_license_type (license_type);
286 | }
287 |
288 | static extern void gtk_about_dialog_set_logo (AboutDialog about, Pixbuf logo);
289 |
290 | public void SetLogo (Pixbuf logo)
291 | {
292 | gtk_about_dialog_set_logo (logo);
293 | }
294 |
295 | static extern void gtk_about_dialog_set_logo_icon_name (AboutDialog about, string icon_name);
296 |
297 | public void SetLogoIconName (string icon_name)
298 | {
299 | gtk_about_dialog_set_logo_icon_name (icon_name);
300 | }
301 |
302 | static extern void gtk_about_dialog_set_program_name (AboutDialog about, string name);
303 |
304 | public void SetProgramName (string name)
305 | {
306 | gtk_about_dialog_set_program_name (name);
307 | }
308 |
309 | static extern void gtk_about_dialog_set_translator_credits (AboutDialog about, string translator_credits);
310 |
311 | public void SetTranslatorCredits (string translator_credits)
312 | {
313 | gtk_about_dialog_set_translator_credits (translator_credits);
314 | }
315 |
316 | static extern void gtk_about_dialog_set_version (AboutDialog about, string version);
317 |
318 | public void SetVersion (string version)
319 | {
320 | gtk_about_dialog_set_version (version);
321 | }
322 |
323 | static extern void gtk_about_dialog_set_website (AboutDialog about, string website);
324 |
325 | public void SetWebsite (string website)
326 | {
327 | gtk_about_dialog_set_website (website);
328 | }
329 |
330 | static extern void gtk_about_dialog_set_website_label (AboutDialog about, string website_label);
331 |
332 | public void SetWebsiteLabel (string website_label)
333 | {
334 | gtk_about_dialog_set_website_label (website_label);
335 | }
336 |
337 | static extern void gtk_about_dialog_set_wrap_license (AboutDialog about, bool wrap_license);
338 |
339 | public void SetWrapLicense (bool wrap_license)
340 | {
341 | gtk_about_dialog_set_wrap_license (wrap_license);
342 | }
343 |
344 | event AboutDialog.activate-linkHandler ActivateLink;
345 | }
346 | }
347 | ",
348 | result);
349 | }
350 | }
351 | }
352 |
--------------------------------------------------------------------------------
/src/Gir.Tests/EnumerationTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class Enumeration : GenerationTestBase
8 | {
9 | [Test]
10 | public void PangoAlignmentIsGenerated ()
11 | {
12 | var result = GenerateType (Pango, "Alignment");
13 |
14 | Assert.AreEqual (@"using System;
15 | using System.Runtime.InteropServices;
16 |
17 | namespace Pango
18 | {
19 | ///
20 | /// A #PangoAlignment describes how to align the lines of a #PangoLayout within the
21 | /// available space. If the #PangoLayout is set to justify
22 | /// using pango_layout_set_justify(), this only has effect for partial lines.
23 | ///
24 | public enum Alignment
25 | {
26 | ///Put all available space on the right
27 | Left = 0,
28 |
29 | ///Center the line within the available space
30 | Center = 1,
31 |
32 | ///Put all available space on the left
33 | Right = 2,
34 | }
35 | }
36 | ", result);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Gir.Tests/FunctionTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class FunctionTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void TestRecordFunctionIsGenerated ()
11 | {
12 | // Test is incomplete, as record is not fully generated atm.
13 | var result = GenerateMember (GLib, "ByteArray", "append");
14 |
15 | Assert.AreEqual (@"static extern ByteArray g_byte_array_append (ByteArray array, byte data, uint len);
16 |
17 | ///
18 | /// Adds the given bytes to the end of the #GByteArray.
19 | /// The array will grow in size automatically if necessary.
20 | ///
21 | ///the #GByteArray
22 | public ByteArray Append (byte data, uint len)
23 | {
24 | return g_byte_array_append (data, len);
25 | }
26 | ", result);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Gir.Tests/GenerationOptionsTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class GenerationOptionsTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void GenerateDocumentationWhenCompatFalse ()
11 | {
12 | var result = GenerateType (Pango, "Alignment");
13 |
14 | Assert.AreEqual (@"using System;
15 | using System.Runtime.InteropServices;
16 |
17 | namespace Pango
18 | {
19 | ///
20 | /// A #PangoAlignment describes how to align the lines of a #PangoLayout within the
21 | /// available space. If the #PangoLayout is set to justify
22 | /// using pango_layout_set_justify(), this only has effect for partial lines.
23 | ///
24 | public enum Alignment
25 | {
26 | ///Put all available space on the right
27 | Left = 0,
28 |
29 | ///Center the line within the available space
30 | Center = 1,
31 |
32 | ///Put all available space on the left
33 | Right = 2,
34 | }
35 | }
36 | ", result);
37 | }
38 |
39 | [Test]
40 | public void GenerateNoDocumentationWhenCompatTrue ()
41 | {
42 | var result = GenerateType (Pango, "Alignment", compat: true);
43 |
44 | Assert.AreEqual (@"using System;
45 | using System.Runtime.InteropServices;
46 |
47 | namespace Pango
48 | {
49 | public enum Alignment
50 | {
51 | Left = 0,
52 | Center = 1,
53 | Right = 2,
54 | }
55 | }
56 | ", result);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Gir.Tests/GenerationTestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 |
8 | using NUnit.Framework;
9 |
10 | namespace Gir.Tests
11 | {
12 | // Use directory name
13 | public enum Library
14 | {
15 | Gtk2,
16 | Gtk3
17 | }
18 |
19 | [TestFixture]
20 | public abstract class GenerationTestBase
21 | {
22 |
23 | protected const string Gdk2 = "Gtk2.Gdk-2.0";
24 | protected const string Gtk2GLib = "Gtk2.GLib-2.0";
25 | protected const string Gtk2Atk1 = "Gtk2.Atk-1.0";
26 | protected const string Gtk2 = "Gtk2.Gtk-2.0";
27 |
28 | protected const string Gdk3 = "Gtk3.Gdk-3.0";
29 | protected const string GLib = "Gtk3.GLib-2.0";
30 | protected const string Gtk3 = "Gtk3.Gtk-3.0";
31 | protected const string GObject = "Gtk3.GObject-2.0";
32 | protected const string Pango = "Gtk3.Pango-1.0";
33 | protected const string Gio2 = "Gtk3.Gio-2.0";
34 | protected const string Atk1 = "Gtk3.Atk-1.0";
35 |
36 | protected const string GIMarshallingTests = "Gtk3.GIMarshallingTests-1.0";
37 |
38 | static IEnumerable<(string Name, Stream ResourceStream, string IncludeDirectory)> GetResourceStreams (string name = null)
39 | {
40 | var assembly = Assembly.GetExecutingAssembly ();
41 |
42 | var names = assembly.GetManifestResourceNames ();
43 | foreach (var resName in names) {
44 | if (string.IsNullOrEmpty (resName) || resName.EndsWith (name + ".gir", StringComparison.OrdinalIgnoreCase)) {
45 | var targetLibrary = (!string.IsNullOrEmpty (name)) ? GetLibraryFromGirFile (name) : GetLibraryFromGirFile (resName);
46 | yield return (resName, assembly.GetManifestResourceStream (resName), targetLibrary.ToString ());
47 | }
48 | }
49 | }
50 |
51 | static string GetIncludeDirectory (string includeDirectory)
52 | {
53 | return Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "TestFiles", includeDirectory);
54 | }
55 |
56 | protected static IEnumerable>> ParseAllGirFiles (Library library)
57 | {
58 | foreach (var stream in GetResourceStreams ()) {
59 | if (stream.IncludeDirectory != library.ToString ())
60 | continue;
61 |
62 | var repos = ParseGirStream (stream, out Repository mainRepository);
63 |
64 | yield return new Tuple> (mainRepository, repos);
65 | }
66 | }
67 |
68 | protected static (String Name, Stream stream, string includeDirectory) GetGirFile (string name)
69 | {
70 | var framework = GetLibraryFromGirFile (name);
71 | return GetResourceStreams (name).Single ();
72 | }
73 |
74 | protected static IEnumerable ParseGirFile (string name, out Repository mainRepository)
75 | {
76 | return ParseGirStream (GetGirFile (name), out mainRepository);
77 | }
78 |
79 | protected static IEnumerable ParseGirStream ((string Name, Stream stream, string includeDirectory) gir, out Repository mainRepository)
80 | {
81 | return Parser.Parse (gir.stream, GetIncludeDirectory (gir.includeDirectory), out mainRepository);
82 | }
83 |
84 |
85 | protected static string GetGenerationResult (GenerationOptions opts)
86 | {
87 | var ms = (MemoryStream)opts.RedirectStream;
88 | return Encoding.UTF8.GetString (ms.ToArray ());
89 | }
90 |
91 | protected static GenerationOptions GetOptions (IEnumerable repositories, Repository mainRepository, bool compat = false, bool generateMember = false)
92 | {
93 | return new GenerationOptions ("", repositories, mainRepository, new GenerationOptions.ToggleOptions {
94 | Compat = compat,
95 | RedirectStream = new MemoryStream (),
96 | WriteHeader = !generateMember,
97 | // Note, all of the tests assume "\n" and not "\r\n"
98 | NewLine = "\n"
99 | });
100 | }
101 |
102 | protected static void GenerateType (Repository repo, GenerationOptions opts, string typeName)
103 | {
104 | repo.GetGeneratables ().First (x => x.Name == typeName).Generate (opts);
105 | }
106 |
107 | protected static void GenerateMember (Repository repo, GenerationOptions opts, string typeName, string memberName)
108 | {
109 | var type = repo.GetGeneratables ().First (x => x.Name == typeName);
110 |
111 | using (var writer = type.GetWriter (opts)) {
112 | type.GenerateMembers (writer, x => x.Name == memberName);
113 | }
114 | }
115 |
116 | protected static string GenerateType (string girFile, string typeName, bool compat = false)
117 | {
118 | var repositories = ParseGirFile (girFile, out var mainRepository);
119 | var opts = GetOptions (repositories, mainRepository, compat);
120 |
121 | GenerateType (mainRepository, opts, typeName);
122 |
123 | return GetGenerationResult (opts);
124 | }
125 |
126 | protected static string GenerateMember (string girFile, string typeName, string memberName, bool compat = false)
127 | {
128 | var repositories = ParseGirFile (girFile, out var mainRepository);
129 | var opts = GetOptions (repositories, mainRepository, compat, generateMember: true);
130 |
131 | GenerateMember (mainRepository, opts, typeName, memberName);
132 |
133 | return GetGenerationResult (opts);
134 | }
135 |
136 | static Library GetLibraryFromGirFile (string girFile)
137 | {
138 | if (girFile.Contains ("Gtk2"))
139 | return Library.Gtk2;
140 |
141 | //if (girFile.Contains ("Gtk3"))
142 | return Library.Gtk3;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/src/Gir.Tests/Gir.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {51FB7677-5684-4664-A59C-075CA6976F57}
7 | Library
8 | Gir.Tests
9 | Gir.Tests
10 | v4.7
11 |
12 |
13 |
14 |
15 | true
16 | full
17 | false
18 | bin\Debug
19 | DEBUG;
20 | prompt
21 | 4
22 |
23 |
24 | true
25 | bin\Release
26 | prompt
27 | 4
28 |
29 |
30 |
31 |
32 | ..\..\..\..\..\..\..\Library\Frameworks\Mono.framework\Versions\5.13.0\lib\mono\4.7-api\System.Xml.dll
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | Always
55 |
56 |
57 | Always
58 |
59 |
60 | Always
61 |
62 |
63 | Always
64 |
65 |
66 | Always
67 |
68 |
69 | Always
70 |
71 |
72 | Always
73 |
74 |
75 | Always
76 |
77 |
78 | Always
79 |
80 |
81 | Always
82 |
83 |
84 | Always
85 |
86 |
87 | Always
88 |
89 |
90 | Always
91 |
92 |
93 | Always
94 |
95 |
96 | Always
97 |
98 |
99 | Always
100 |
101 |
102 | Always
103 |
104 |
105 | Always
106 |
107 |
108 | Always
109 |
110 |
111 | Always
112 |
113 |
114 | Always
115 |
116 |
117 | Always
118 |
119 |
120 | Always
121 |
122 |
123 | Always
124 |
125 |
126 | Always
127 |
128 |
129 | Always
130 |
131 |
132 | Always
133 |
134 |
135 | Always
136 |
137 |
138 | Always
139 |
140 |
141 | Always
142 |
143 |
144 | Always
145 |
146 |
147 | Always
148 |
149 |
150 | Always
151 |
152 |
153 | Always
154 |
155 |
156 | Always
157 |
158 |
159 | Always
160 |
161 |
162 | Always
163 |
164 |
165 | Always
166 |
167 |
168 | Always
169 |
170 |
171 | Always
172 |
173 |
174 | Always
175 |
176 |
177 | Always
178 |
179 |
180 | Always
181 |
182 |
183 | Always
184 |
185 |
186 | Always
187 |
188 |
189 | Always
190 |
191 |
192 | Always
193 |
194 |
195 | Always
196 |
197 |
198 |
199 |
200 | Always
201 |
202 |
203 | Always
204 |
205 |
206 | Always
207 |
208 |
209 | Always
210 |
211 |
212 | Always
213 |
214 |
215 | Always
216 |
217 |
218 | Always
219 |
220 |
221 | Always
222 |
223 |
224 | Always
225 |
226 |
227 | Always
228 |
229 |
230 | Always
231 |
232 |
233 |
234 |
235 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}
236 | Gir
237 |
238 |
239 |
240 |
241 | 3.10.1
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/src/Gir.Tests/Gtk2/Atk/AtkTests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace Gir.Tests.Gtk2.Atk
4 | {
5 | [TestFixture]
6 | class AtkTests : GenerationTestBase
7 | {
8 | [Test]
9 | public void GenerateAtkAction ()
10 | {
11 | var result = GenerateType (Gtk2Atk1, "Action", true);
12 |
13 | Assert.AreEqual (@"using System;
14 | using System.Runtime.InteropServices;
15 |
16 | namespace Atk
17 | {
18 | public interface Action
19 | {
20 | bool DoAction (int i);
21 |
22 | string GetDescription (int i);
23 |
24 | string GetKeybinding (int i);
25 |
26 | string GetLocalizedName (int i);
27 |
28 | int GetNActions ();
29 |
30 | string GetName (int i);
31 |
32 | bool SetDescription (int i, string desc);
33 | }
34 | }
35 | ", result);
36 | }
37 |
38 | [Test]
39 | public void GenerateAtkRole ()
40 | {
41 | var result = GenerateType (Gtk2Atk1, "Role", true);
42 |
43 | Assert.AreEqual (@"using System;
44 | using System.Runtime.InteropServices;
45 |
46 | namespace Atk
47 | {
48 | public enum Role
49 | {
50 | Invalid = 0,
51 | AccelLabel = 1,
52 | Alert = 2,
53 | Animation = 3,
54 | Arrow = 4,
55 | Calendar = 5,
56 | Canvas = 6,
57 | CheckBox = 7,
58 | CheckMenuItem = 8,
59 | ColorChooser = 9,
60 | ColumnHeader = 10,
61 | ComboBox = 11,
62 | DateEditor = 12,
63 | DesktopIcon = 13,
64 | DesktopFrame = 14,
65 | Dial = 15,
66 | Dialog = 16,
67 | DirectoryPane = 17,
68 | DrawingArea = 18,
69 | FileChooser = 19,
70 | Filler = 20,
71 | FontChooser = 21,
72 | Frame = 22,
73 | GlassPane = 23,
74 | HtmlContainer = 24,
75 | Icon = 25,
76 | Image = 26,
77 | InternalFrame = 27,
78 | Label = 28,
79 | LayeredPane = 29,
80 | List = 30,
81 | ListItem = 31,
82 | Menu = 32,
83 | MenuBar = 33,
84 | MenuItem = 34,
85 | OptionPane = 35,
86 | PageTab = 36,
87 | PageTabList = 37,
88 | Panel = 38,
89 | PasswordText = 39,
90 | PopupMenu = 40,
91 | ProgressBar = 41,
92 | PushButton = 42,
93 | RadioButton = 43,
94 | RadioMenuItem = 44,
95 | RootPane = 45,
96 | RowHeader = 46,
97 | ScrollBar = 47,
98 | ScrollPane = 48,
99 | Separator = 49,
100 | Slider = 50,
101 | SplitPane = 51,
102 | SpinButton = 52,
103 | Statusbar = 53,
104 | Table = 54,
105 | TableCell = 55,
106 | TableColumnHeader = 56,
107 | TableRowHeader = 57,
108 | TearOffMenuItem = 58,
109 | Terminal = 59,
110 | Text = 60,
111 | ToggleButton = 61,
112 | ToolBar = 62,
113 | ToolTip = 63,
114 | Tree = 64,
115 | TreeTable = 65,
116 | Unknown = 66,
117 | Viewport = 67,
118 | Window = 68,
119 | Header = 69,
120 | Footer = 70,
121 | Paragraph = 71,
122 | Ruler = 72,
123 | Application = 73,
124 | Autocomplete = 74,
125 | Editbar = 75,
126 | Embedded = 76,
127 | Entry = 77,
128 | Chart = 78,
129 | Caption = 79,
130 | DocumentFrame = 80,
131 | Heading = 81,
132 | Page = 82,
133 | Section = 83,
134 | RedundantObject = 84,
135 | Form = 85,
136 | Link = 86,
137 | InputMethodWindow = 87,
138 | LastDefined = 88,
139 | }
140 | }
141 | ", result);
142 | }
143 |
144 | [Test]
145 | public void GenerateAtkEventListener ()
146 | {
147 | var result = GenerateType (Gtk2Atk1, "EventListener", true);
148 |
149 | Assert.AreEqual(@"using System;
150 | using System.Runtime.InteropServices;
151 |
152 | namespace Atk
153 | {
154 | [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
155 | public delegate void EventListener (Object obj)
156 |
157 | [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
158 | internal delegate void EventListenerNative (Object obj)
159 |
160 | internal static class EventListenerWrapper
161 | {
162 | public static void NativeCallback (Object obj)
163 | {
164 | }
165 | }
166 | }
167 | ", result);
168 | }
169 |
170 | [Test]
171 | public void GenerateAttribute ()
172 | {
173 | var result = GenerateType (Gtk2Atk1, "Attribute", true);
174 |
175 | Assert.AreEqual (@"using System;
176 | using System.Runtime.InteropServices;
177 |
178 | namespace Atk
179 | {
180 | [StructLayout (LayoutKind.Sequential)]
181 | public struct Attribute
182 | {
183 | string Name;
184 |
185 | string Value;
186 | }
187 | }
188 | ", result);
189 | }
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/Gir.Tests/ImportantGeneratables/List.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class List : GenerationTestBase
8 | {
9 | [Test]
10 | public void ListIsGenerated ()
11 | {
12 | var result = GenerateType(GLib, "List", true);
13 |
14 | Assert.AreEqual (@"using System;
15 | using System.Runtime.InteropServices;
16 |
17 | namespace GLib
18 | {
19 | [StructLayout (LayoutKind.Sequential)]
20 | public struct List
21 | {
22 | IntPtr Data;
23 |
24 | List Next;
25 |
26 | List Prev;
27 |
28 | static extern List g_list_alloc ();
29 |
30 | public static List Alloc ()
31 | {
32 | return g_list_alloc ();
33 | }
34 |
35 | static extern List g_list_append (List list, IntPtr data);
36 |
37 | public List Append (IntPtr data)
38 | {
39 | return g_list_append (data);
40 | }
41 |
42 | static extern List g_list_concat (List list1, List list2);
43 |
44 | public List Concat (List list2)
45 | {
46 | return g_list_concat (list2);
47 | }
48 |
49 | static extern List g_list_copy (List list);
50 |
51 | public List Copy ()
52 | {
53 | return g_list_copy ();
54 | }
55 |
56 | static extern List g_list_copy_deep (List list, CopyFunc func, IntPtr user_data);
57 |
58 | public List CopyDeep (CopyFunc func, IntPtr user_data)
59 | {
60 | return g_list_copy_deep (func, user_data);
61 | }
62 |
63 | static extern List g_list_delete_link (List list, List link_);
64 |
65 | public List DeleteLink (List link_)
66 | {
67 | return g_list_delete_link (link_);
68 | }
69 |
70 | static extern List g_list_find (List list, IntPtr data);
71 |
72 | public List Find (IntPtr data)
73 | {
74 | return g_list_find (data);
75 | }
76 |
77 | static extern List g_list_find_custom (List list, IntPtr data, CompareFunc func);
78 |
79 | public List FindCustom (IntPtr data, CompareFunc func)
80 | {
81 | return g_list_find_custom (data, func);
82 | }
83 |
84 | static extern List g_list_first (List list);
85 |
86 | public List First ()
87 | {
88 | return g_list_first ();
89 | }
90 |
91 | static extern void g_list_foreach (List list, Func func, IntPtr user_data);
92 |
93 | public void Foreach (Func func, IntPtr user_data)
94 | {
95 | g_list_foreach (func, user_data);
96 | }
97 |
98 | static extern void g_list_free (List list);
99 |
100 | public void Free ()
101 | {
102 | g_list_free ();
103 | }
104 |
105 | static extern void g_list_free_1 (List list);
106 |
107 | public void Free1 ()
108 | {
109 | g_list_free_1 ();
110 | }
111 |
112 | static extern void g_list_free_full (List list, DestroyNotify free_func);
113 |
114 | public void FreeFull (DestroyNotify free_func)
115 | {
116 | g_list_free_full (free_func);
117 | }
118 |
119 | static extern int g_list_index (List list, IntPtr data);
120 |
121 | public int Index (IntPtr data)
122 | {
123 | return g_list_index (data);
124 | }
125 |
126 | static extern List g_list_insert (List list, IntPtr data, int position);
127 |
128 | public List Insert (IntPtr data, int position)
129 | {
130 | return g_list_insert (data, position);
131 | }
132 |
133 | static extern List g_list_insert_before (List list, List sibling, IntPtr data);
134 |
135 | public List InsertBefore (List sibling, IntPtr data)
136 | {
137 | return g_list_insert_before (sibling, data);
138 | }
139 |
140 | static extern List g_list_insert_sorted (List list, IntPtr data, CompareFunc func);
141 |
142 | public List InsertSorted (IntPtr data, CompareFunc func)
143 | {
144 | return g_list_insert_sorted (data, func);
145 | }
146 |
147 | static extern List g_list_insert_sorted_with_data (List list, IntPtr data, CompareDataFunc func, IntPtr user_data);
148 |
149 | public List InsertSortedWithData (IntPtr data, CompareDataFunc func, IntPtr user_data)
150 | {
151 | return g_list_insert_sorted_with_data (data, func, user_data);
152 | }
153 |
154 | static extern List g_list_last (List list);
155 |
156 | public List Last ()
157 | {
158 | return g_list_last ();
159 | }
160 |
161 | static extern uint g_list_length (List list);
162 |
163 | public uint Length ()
164 | {
165 | return g_list_length ();
166 | }
167 |
168 | static extern List g_list_nth (List list, uint n);
169 |
170 | public List Nth (uint n)
171 | {
172 | return g_list_nth (n);
173 | }
174 |
175 | static extern IntPtr g_list_nth_data (List list, uint n);
176 |
177 | public IntPtr NthData (uint n)
178 | {
179 | return g_list_nth_data (n);
180 | }
181 |
182 | static extern List g_list_nth_prev (List list, uint n);
183 |
184 | public List NthPrev (uint n)
185 | {
186 | return g_list_nth_prev (n);
187 | }
188 |
189 | static extern int g_list_position (List list, List llink);
190 |
191 | public int Position (List llink)
192 | {
193 | return g_list_position (llink);
194 | }
195 |
196 | static extern List g_list_prepend (List list, IntPtr data);
197 |
198 | public List Prepend (IntPtr data)
199 | {
200 | return g_list_prepend (data);
201 | }
202 |
203 | static extern List g_list_remove (List list, IntPtr data);
204 |
205 | public List Remove (IntPtr data)
206 | {
207 | return g_list_remove (data);
208 | }
209 |
210 | static extern List g_list_remove_all (List list, IntPtr data);
211 |
212 | public List RemoveAll (IntPtr data)
213 | {
214 | return g_list_remove_all (data);
215 | }
216 |
217 | static extern List g_list_remove_link (List list, List llink);
218 |
219 | public List RemoveLink (List llink)
220 | {
221 | return g_list_remove_link (llink);
222 | }
223 |
224 | static extern List g_list_reverse (List list);
225 |
226 | public List Reverse ()
227 | {
228 | return g_list_reverse ();
229 | }
230 |
231 | static extern List g_list_sort (List list, CompareFunc compare_func);
232 |
233 | public List Sort (CompareFunc compare_func)
234 | {
235 | return g_list_sort (compare_func);
236 | }
237 |
238 | static extern List g_list_sort_with_data (List list, CompareDataFunc compare_func, IntPtr user_data);
239 |
240 | public List SortWithData (CompareDataFunc compare_func, IntPtr user_data)
241 | {
242 | return g_list_sort_with_data (compare_func, user_data);
243 | }
244 | }
245 | }
246 | ", result);
247 | }
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/src/Gir.Tests/InterfaceTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class InterfaceTests : GenerationTestBase
8 | {
9 | public void TestSeekableInterfaceIsGenerated()
10 | {
11 | var result = GenerateType(Gio2, "Seekable");
12 | Assert.AreEqual(@"using System;
13 |
14 | namespace Gio
15 | {
16 | ///
17 | /// #GSeekable is implemented by streams (implementations of
18 | /// #GInputStream or #GOutputStream) that support seeking.
19 | ///
20 | /// Seekable streams largely fall into two categories: resizable and
21 | /// fixed-size.
22 | ///
23 | /// #GSeekable on fixed-sized streams is approximately the same as POSIX
24 | /// lseek() on a block device (for example: attmepting to seek past the
25 | /// end of the device is an error). Fixed streams typically cannot be
26 | /// truncated.
27 | ///
28 | /// #GSeekable on resizable streams is approximately the same as POSIX
29 | /// lseek() on a normal file. Seeking past the end and writing data will
30 | /// usually cause the stream to resize by introducing zero bytes.
31 | ///
32 | public interface ISeekable
33 | {
34 | ///Tests if the stream supports the #GSeekableIface.
35 | ///%TRUE if @seekable can be seeked. %FALSE otherwise.
36 | bool CanSeek (Seekable seekable);
37 |
38 | ///Tests if the stream can be truncated.
39 | ///%TRUE if the stream can be truncated, %FALSE otherwise.
40 | bool CanTruncate (Seekable seekable);
41 |
42 | ///
43 | /// Seeks in the stream by the given @offset, modified by @type.
44 | ///
45 | /// Attempting to seek past the end of the stream will have different
46 | /// results depending on if the stream is fixed-sized or resizable. If
47 | /// the stream is resizable then seeking past the end and then writing
48 | /// will result in zeros filling the empty space. Seeking past the end
49 | /// of a resizable stream and reading will result in EOF. Seeking past
50 | /// the end of a fixed-sized stream will fail.
51 | ///
52 | /// Any operation that would result in a negative offset will fail.
53 | ///
54 | /// If @cancellable is not %NULL, then the operation can be cancelled by
55 | /// triggering the cancellable object from another thread. If the operation
56 | /// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
57 | ///
58 | ///
59 | /// %TRUE if successful. If an error
60 | /// has occurred, this function will return %FALSE and set @error
61 | /// appropriately if present.
62 | ///
63 | bool Seek (Seekable seekable, long offset, GLib.SeekType type, Cancellable cancellable);
64 |
65 | ///Tells the current position within the stream.
66 | ///the offset from the beginning of the buffer.
67 | long Tell (Seekable seekable);
68 |
69 | ///
70 | /// Truncates a stream with a given #offset.
71 | ///
72 | /// If @cancellable is not %NULL, then the operation can be cancelled by
73 | /// triggering the cancellable object from another thread. If the operation
74 | /// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
75 | /// operation was partially finished when the operation was cancelled the
76 | /// partial result will be returned, without an error.
77 | ///
78 | ///
79 | /// %TRUE if successful. If an error
80 | /// has occurred, this function will return %FALSE and set @error
81 | /// appropriately if present.
82 | ///
83 | bool Truncate (Seekable seekable, long offset, Cancellable cancellable);
84 | }
85 | }
86 | ", result);
87 | }
88 |
89 | [Test]
90 | public void TestSeekableInterfaceIsGeneratedCompatEnabled()
91 | {
92 | var result = GenerateType(Gio2, "Seekable", true);
93 | Assert.AreEqual(@"using System;
94 | using System.Runtime.InteropServices;
95 |
96 | namespace Gio
97 | {
98 | public interface Seekable
99 | {
100 | bool CanSeek ();
101 |
102 | bool CanTruncate ();
103 |
104 | bool Seek (long offset, SeekType type, Cancellable cancellable);
105 |
106 | long Tell ();
107 |
108 | bool Truncate (long offset, Cancellable cancellable);
109 | }
110 | }
111 | ", result);
112 | }
113 |
114 | [Test]
115 | public void GenerateAtkComponentInterface ()
116 | {
117 | var result = GenerateType(Atk1, "Component");
118 | Assert.AreEqual(@"using System;
119 | using System.Runtime.InteropServices;
120 |
121 | namespace Atk
122 | {
123 | ///
124 | /// #AtkComponent should be implemented by most if not all UI elements
125 | /// with an actual on-screen presence, i.e. components which can be
126 | /// said to have a screen-coordinate bounding box. Virtually all
127 | /// widgets will need to have #AtkComponent implementations provided
128 | /// for their corresponding #AtkObject class. In short, only UI
129 | /// elements which are *not* GUI elements will omit this ATK interface.
130 | ///
131 | /// A possible exception might be textual information with a
132 | /// transparent background, in which case text glyph bounding box
133 | /// information is provided by #AtkText.
134 | ///
135 | public interface IComponent
136 | {
137 | ///
138 | /// Add the specified handler to the set of functions to be called
139 | /// when this object receives focus events (in or out). If the handler is
140 | /// already added it is not added again
141 | ///
142 | [Obsolete (""(Version: 2.9.4) If you need to track when an object gains or
143 | lose the focus, use the #AtkObject::state-change ""focused"" notification instead."")]
144 | ///
145 | /// a handler id which can be used in atk_component_remove_focus_handler()
146 | /// or zero if the handler was already added.
147 | ///
148 | uint AddFocusHandler (FocusHandler handler);
149 |
150 | ///
151 | /// Checks whether the specified point is within the extent of the @component.
152 | ///
153 | /// Toolkit implementor note: ATK provides a default implementation for
154 | /// this virtual method. In general there are little reason to
155 | /// re-implement it.
156 | ///
157 | ///
158 | /// %TRUE or %FALSE indicating whether the specified point is within
159 | /// the extent of the @component or not
160 | ///
161 | bool Contains (int x, int y, CoordType coord_type);
162 |
163 | ///
164 | /// Returns the alpha value (i.e. the opacity) for this
165 | /// @component, on a scale from 0 (fully transparent) to 1.0
166 | /// (fully opaque).
167 | ///
168 | ///An alpha value from 0 to 1.0, inclusive.
169 | double GetAlpha ();
170 |
171 | ///Gets the rectangle which gives the extent of the @component.
172 | void GetExtents (int x, int y, int width, int height, CoordType coord_type);
173 |
174 | ///Gets the layer of the component.
175 | ///an #AtkLayer which is the layer of the component
176 | Layer GetLayer ();
177 |
178 | ///
179 | /// Gets the zorder of the component. The value G_MININT will be returned
180 | /// if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
181 | ///
182 | ///
183 | /// a gint which is the zorder of the component, i.e. the depth at
184 | /// which the component is shown in relation to other components in the same
185 | /// container.
186 | ///
187 | int GetMdiZorder ();
188 |
189 | ///
190 | /// Gets the position of @component in the form of
191 | /// a point specifying @component's top-left corner.
192 | ///
193 | [Obsolete (""(Version: ) Since 2.12. Use atk_component_get_extents() instead."")]
194 | void GetPosition (int x, int y, CoordType coord_type);
195 |
196 | ///Gets the size of the @component in terms of width and height.
197 | [Obsolete (""(Version: ) Since 2.12. Use atk_component_get_extents() instead."")]
198 | void GetSize (int width, int height);
199 |
200 | ///Grabs focus for this @component.
201 | ///%TRUE if successful, %FALSE otherwise.
202 | bool GrabFocus ();
203 |
204 | ///
205 | /// Gets a reference to the accessible child, if one exists, at the
206 | /// coordinate point specified by @x and @y.
207 | ///
208 | ///
209 | /// a reference to the accessible
210 | /// child, if one exists
211 | ///
212 | Object RefAccessibleAtPoint (int x, int y, CoordType coord_type);
213 |
214 | ///
215 | /// Remove the handler specified by @handler_id from the list of
216 | /// functions to be executed when this object receives focus events
217 | /// (in or out).
218 | ///
219 | [Obsolete (""(Version: 2.9.4) If you need to track when an object gains or
220 | lose the focus, use the #AtkObject::state-change ""focused"" notification instead."")]
221 | void RemoveFocusHandler (uint handler_id);
222 |
223 | ///Sets the extents of @component.
224 | ///%TRUE or %FALSE whether the extents were set or not
225 | bool SetExtents (int x, int y, int width, int height, CoordType coord_type);
226 |
227 | ///Sets the postition of @component.
228 | ///%TRUE or %FALSE whether or not the position was set or not
229 | bool SetPosition (int x, int y, CoordType coord_type);
230 |
231 | ///Set the size of the @component in terms of width and height.
232 | ///%TRUE or %FALSE whether the size was set or not
233 | bool SetSize (int width, int height);
234 |
235 | ///
236 | /// The 'bounds-changed"" signal is emitted when the bposition or
237 | /// size of the component changes.
238 | ///
239 | event System.EventHandler BoundsChanged;
240 | }
241 | }
242 | ", result);
243 | }
244 |
245 | [Test]
246 | public void GenerateAtkComponentInterfaceCompat ()
247 | {
248 | var result = GenerateType (Atk1, "Component", true);
249 |
250 | Assert.AreEqual (@"using System;
251 | using System.Runtime.InteropServices;
252 |
253 | namespace Atk
254 | {
255 | public interface Component
256 | {
257 | [Obsolete (""(Version: 2.9.4) If you need to track when an object gains or
258 | lose the focus, use the #AtkObject::state-change ""focused"" notification instead."")]
259 | uint AddFocusHandler (FocusHandler handler);
260 |
261 | bool Contains (int x, int y, CoordType coord_type);
262 |
263 | double GetAlpha ();
264 |
265 | void GetExtents (int x, int y, int width, int height, CoordType coord_type);
266 |
267 | Layer GetLayer ();
268 |
269 | int GetMdiZorder ();
270 |
271 | [Obsolete (""(Version: ) Since 2.12. Use atk_component_get_extents() instead."")]
272 | void GetPosition (int x, int y, CoordType coord_type);
273 |
274 | [Obsolete (""(Version: ) Since 2.12. Use atk_component_get_extents() instead."")]
275 | void GetSize (int width, int height);
276 |
277 | bool GrabFocus ();
278 |
279 | Object RefAccessibleAtPoint (int x, int y, CoordType coord_type);
280 |
281 | [Obsolete (""(Version: 2.9.4) If you need to track when an object gains or
282 | lose the focus, use the #AtkObject::state-change ""focused"" notification instead."")]
283 | void RemoveFocusHandler (uint handler_id);
284 |
285 | bool SetExtents (int x, int y, int width, int height, CoordType coord_type);
286 |
287 | bool SetPosition (int x, int y, CoordType coord_type);
288 |
289 | bool SetSize (int width, int height);
290 |
291 | event System.EventHandler BoundsChanged;
292 | }
293 | }
294 | ", result);
295 | }
296 |
297 | [Test]
298 | public void GenerateAtkDriveInterfaceCompat()
299 | {
300 | var result = GenerateType(Gio2, "Drive", true);
301 |
302 | Assert.AreEqual(@"using System;
303 | using System.Runtime.InteropServices;
304 |
305 | namespace Gio
306 | {
307 | public interface Drive
308 | {
309 | bool CanEject ();
310 |
311 | bool CanPollForMedia ();
312 |
313 | bool CanStart ();
314 |
315 | bool CanStartDegraded ();
316 |
317 | bool CanStop ();
318 |
319 | [Obsolete (""(Version: 2.22) Use g_drive_eject_with_operation() instead."")]
320 | void Eject (MountUnmountFlags flags, Cancellable cancellable, AsyncReadyCallback callback, IntPtr user_data);
321 |
322 | [Obsolete (""(Version: 2.22) Use g_drive_eject_with_operation_finish() instead."")]
323 | bool EjectFinish (IAsyncResult result);
324 |
325 | void EjectWithOperation (MountUnmountFlags flags, MountOperation mount_operation, Cancellable cancellable, AsyncReadyCallback callback, IntPtr user_data);
326 |
327 | bool EjectWithOperationFinish (IAsyncResult result);
328 |
329 | string EnumerateIdentifiers ();
330 |
331 | IIcon GetIcon ();
332 |
333 | string GetIdentifier (string kind);
334 |
335 | string GetName ();
336 |
337 | string GetSortKey ();
338 |
339 | DriveStartStopType GetStartStopType ();
340 |
341 | IIcon GetSymbolicIcon ();
342 |
343 | List GetVolumes ();
344 |
345 | bool HasMedia ();
346 |
347 | bool HasVolumes ();
348 |
349 | bool IsMediaCheckAutomatic ();
350 |
351 | bool IsMediaRemovable ();
352 |
353 | void PollForMedia (Cancellable cancellable, AsyncReadyCallback callback, IntPtr user_data);
354 |
355 | bool PollForMediaFinish (IAsyncResult result);
356 |
357 | void Start (DriveStartFlags flags, MountOperation mount_operation, Cancellable cancellable, AsyncReadyCallback callback, IntPtr user_data);
358 |
359 | bool StartFinish (IAsyncResult result);
360 |
361 | void Stop (MountUnmountFlags flags, MountOperation mount_operation, Cancellable cancellable, AsyncReadyCallback callback, IntPtr user_data);
362 |
363 | bool StopFinish (IAsyncResult result);
364 |
365 | event System.EventHandler Changed;
366 |
367 | event System.EventHandler Disconnected;
368 |
369 | event System.EventHandler EjectButton;
370 |
371 | event System.EventHandler StopButton;
372 | }
373 | }
374 | ", result);
375 | }
376 | }
377 | }
378 |
--------------------------------------------------------------------------------
/src/Gir.Tests/RecordTests.cs:
--------------------------------------------------------------------------------
1 |
2 | using NUnit.Framework;
3 |
4 | namespace Gir.Tests
5 | {
6 | [TestFixture]
7 | public class RecordTests : GenerationTestBase
8 | {
9 | [Test]
10 | public void TestRecordIsGenerated ()
11 | {
12 | // Test is incomplete, as record is not fully generated atm.
13 | var result = GenerateType (GLib, "ByteArray");
14 |
15 | // Need to map pointers at symbol level.
16 | Assert.AreEqual (@"using System;
17 | using System.Runtime.InteropServices;
18 |
19 | namespace GLib
20 | {
21 | ///Contains the public fields of a GByteArray.
22 | [StructLayout (LayoutKind.Sequential)]
23 | public struct ByteArray
24 | {
25 | ///
26 | /// a pointer to the element data. The data may be moved as
27 | /// elements are added to the #GByteArray
28 | ///
29 | byte Data;
30 |
31 | ///the number of elements in the #GByteArray
32 | uint Len;
33 |
34 | static extern ByteArray g_byte_array_append (ByteArray array, byte data, uint len);
35 |
36 | ///
37 | /// Adds the given bytes to the end of the #GByteArray.
38 | /// The array will grow in size automatically if necessary.
39 | ///
40 | ///the #GByteArray
41 | public ByteArray Append (byte data, uint len)
42 | {
43 | return g_byte_array_append (data, len);
44 | }
45 |
46 | static extern byte g_byte_array_free (ByteArray array, bool free_segment);
47 |
48 | ///
49 | /// Frees the memory allocated by the #GByteArray. If @free_segment is
50 | /// %TRUE it frees the actual byte data. If the reference count of
51 | /// @array is greater than one, the #GByteArray wrapper is preserved but
52 | /// the size of @array will be set to zero.
53 | ///
54 | ///
55 | /// the element data if @free_segment is %FALSE, otherwise
56 | /// %NULL. The element data should be freed using g_free().
57 | ///
58 | public byte Free (bool free_segment)
59 | {
60 | return g_byte_array_free (free_segment);
61 | }
62 |
63 | static extern Bytes g_byte_array_free_to_bytes (ByteArray array);
64 |
65 | ///
66 | /// Transfers the data from the #GByteArray into a new immutable #GBytes.
67 | ///
68 | /// The #GByteArray is freed unless the reference count of @array is greater
69 | /// than one, the #GByteArray wrapper is preserved but the size of @array
70 | /// will be set to zero.
71 | ///
72 | /// This is identical to using g_bytes_new_take() and g_byte_array_free()
73 | /// together.
74 | ///
75 | ///
76 | /// a new immutable #GBytes representing same
77 | /// byte data that was in the array
78 | ///
79 | public Bytes FreeToBytes ()
80 | {
81 | return g_byte_array_free_to_bytes ();
82 | }
83 |
84 | static extern ByteArray g_byte_array_new ();
85 |
86 | ///Creates a new #GByteArray with a reference count of 1.
87 | ///the new #GByteArray
88 | public static ByteArray New ()
89 | {
90 | return g_byte_array_new ();
91 | }
92 |
93 | static extern ByteArray g_byte_array_new_take (byte data, UIntPtr len);
94 |
95 | ///
96 | /// Create byte array containing the data. The data will be owned by the array
97 | /// and will be freed with g_free(), i.e. it could be allocated using g_strdup().
98 | ///
99 | ///a new #GByteArray
100 | public static ByteArray NewTake (byte[] data, UIntPtr len)
101 | {
102 | return g_byte_array_new_take (data, len);
103 | }
104 |
105 | static extern ByteArray g_byte_array_prepend (ByteArray array, byte data, uint len);
106 |
107 | ///
108 | /// Adds the given data to the start of the #GByteArray.
109 | /// The array will grow in size automatically if necessary.
110 | ///
111 | ///the #GByteArray
112 | public ByteArray Prepend (byte data, uint len)
113 | {
114 | return g_byte_array_prepend (data, len);
115 | }
116 |
117 | static extern ByteArray g_byte_array_ref (ByteArray array);
118 |
119 | ///
120 | /// Atomically increments the reference count of @array by one.
121 | /// This function is thread-safe and may be called from any thread.
122 | ///
123 | ///The passed in #GByteArray
124 | public ByteArray Ref ()
125 | {
126 | return g_byte_array_ref ();
127 | }
128 |
129 | static extern ByteArray g_byte_array_remove_index (ByteArray array, uint index_);
130 |
131 | ///
132 | /// Removes the byte at the given index from a #GByteArray.
133 | /// The following bytes are moved down one place.
134 | ///
135 | ///the #GByteArray
136 | public ByteArray RemoveIndex (uint index_)
137 | {
138 | return g_byte_array_remove_index (index_);
139 | }
140 |
141 | static extern ByteArray g_byte_array_remove_index_fast (ByteArray array, uint index_);
142 |
143 | ///
144 | /// Removes the byte at the given index from a #GByteArray. The last
145 | /// element in the array is used to fill in the space, so this function
146 | /// does not preserve the order of the #GByteArray. But it is faster
147 | /// than g_byte_array_remove_index().
148 | ///
149 | ///the #GByteArray
150 | public ByteArray RemoveIndexFast (uint index_)
151 | {
152 | return g_byte_array_remove_index_fast (index_);
153 | }
154 |
155 | static extern ByteArray g_byte_array_remove_range (ByteArray array, uint index_, uint length);
156 |
157 | ///
158 | /// Removes the given number of bytes starting at the given index from a
159 | /// #GByteArray. The following elements are moved to close the gap.
160 | ///
161 | ///the #GByteArray
162 | public ByteArray RemoveRange (uint index_, uint length)
163 | {
164 | return g_byte_array_remove_range (index_, length);
165 | }
166 |
167 | static extern ByteArray g_byte_array_set_size (ByteArray array, uint length);
168 |
169 | ///Sets the size of the #GByteArray, expanding it if necessary.
170 | ///the #GByteArray
171 | public ByteArray SetSize (uint length)
172 | {
173 | return g_byte_array_set_size (length);
174 | }
175 |
176 | static extern ByteArray g_byte_array_sized_new (uint reserved_size);
177 |
178 | ///
179 | /// Creates a new #GByteArray with @reserved_size bytes preallocated.
180 | /// This avoids frequent reallocation, if you are going to add many
181 | /// bytes to the array. Note however that the size of the array is still
182 | /// 0.
183 | ///
184 | ///the new #GByteArray
185 | public static ByteArray SizedNew (uint reserved_size)
186 | {
187 | return g_byte_array_sized_new (reserved_size);
188 | }
189 |
190 | static extern void g_byte_array_sort (ByteArray array, CompareFunc compare_func);
191 |
192 | ///
193 | /// Sorts a byte array, using @compare_func which should be a
194 | /// qsort()-style comparison function (returns less than zero for first
195 | /// arg is less than second arg, zero for equal, greater than zero if
196 | /// first arg is greater than second arg).
197 | ///
198 | /// If two array elements compare equal, their order in the sorted array
199 | /// is undefined. If you want equal elements to keep their order (i.e.
200 | /// you want a stable sort) you can write a comparison function that,
201 | /// if two elements would otherwise compare equal, compares them by
202 | /// their addresses.
203 | ///
204 | public void Sort (CompareFunc compare_func)
205 | {
206 | g_byte_array_sort (compare_func);
207 | }
208 |
209 | static extern void g_byte_array_sort_with_data (ByteArray array, CompareDataFunc compare_func, IntPtr user_data);
210 |
211 | ///
212 | /// Like g_byte_array_sort(), but the comparison function takes an extra
213 | /// user data argument.
214 | ///
215 | public void SortWithData (CompareDataFunc compare_func, IntPtr user_data)
216 | {
217 | g_byte_array_sort_with_data (compare_func, user_data);
218 | }
219 |
220 | static extern void g_byte_array_unref (ByteArray array);
221 |
222 | ///
223 | /// Atomically decrements the reference count of @array by one. If the
224 | /// reference count drops to 0, all memory allocated by the array is
225 | /// released. This function is thread-safe and may be called from any
226 | /// thread.
227 | ///
228 | public void Unref ()
229 | {
230 | g_byte_array_unref ();
231 | }
232 | }
233 | }
234 | ", result);
235 | }
236 |
237 | // [Test]
238 | // [Ignore ("This currently fails. NRE w/ do_action field")]
239 | // public void CanGenerateActionIfaceRecord ()
240 | // {
241 | // // Test is incomplete, as record is not fully generated atm.
242 | // var result = GenerateType(Atk1, "ActionIface");
243 |
244 |
245 | // // Need to map pointers at symbol level.
246 | // Assert.AreEqual(@"namespace Atk
247 | //{
248 | //}", result);
249 | //}
250 | }
251 | }
252 |
--------------------------------------------------------------------------------
/src/Gir.Tests/SymbolTableTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using NUnit.Framework;
4 |
5 | namespace Gir.Tests
6 | {
7 | [TestFixture]
8 | public class SymbolTableTests : GenerationTestBase
9 | {
10 | [Test]
11 | public void TestAliasMapping ()
12 | {
13 | var repo = ParseGirFile (GLib, out var mainRepository);
14 | var opts = GetOptions (repo, mainRepository);
15 |
16 | Assert.AreEqual (opts.SymbolTable ["guint8"], opts.SymbolTable ["DateDay"]);
17 | }
18 |
19 | [TestCase (Gdk3, 0)]
20 | [TestCase (GLib, 0)]
21 | [TestCase (Gtk3, 0)]
22 | [TestCase (Pango, 0)]
23 | [TestCase (GIMarshallingTests, 0)]
24 | [TestCase (Gdk2, 1)] // FIXME
25 | [TestCase (Gtk2, 3)] // FIXME
26 | public void TestSymbolTableErrorsTracker (string girFile, int errorCount)
27 | {
28 | var repo = ParseGirFile (girFile, out var mainRepository);
29 | var opts = GetOptions (repo, mainRepository);
30 |
31 | var stats = opts.Statistics.Errors.ToArray ();
32 |
33 | // FUTURE: This should be 0.
34 | foreach (var error in stats) {
35 | Console.WriteLine (error.Message);
36 | }
37 | Assert.AreEqual (errorCount, stats.Length);
38 | }
39 |
40 | [TestCase (Library.Gtk2)]
41 | [TestCase (Library.Gtk3)]
42 | public void NoAliasTypeAfterProcessing (Library library)
43 | {
44 | foreach (var tpl in ParseAllGirFiles (library)) {
45 | var repo = tpl.Item2;
46 | var mainRepository = tpl.Item1;
47 |
48 | var opts = GetOptions (repo, mainRepository);
49 |
50 | Assert.AreEqual (0, opts.SymbolTable.OfType ().Count ());
51 | }
52 | }
53 |
54 | [TestCase (Gtk2)]
55 | [TestCase (Gtk3)]
56 | public void CanResolveIncludedFiles (string girFile)
57 | {
58 | var repo = ParseGirFile (girFile, out var mainRepository);
59 | var opts = GetOptions (repo, mainRepository);
60 |
61 | Assert.NotNull (opts.SymbolTable["GdkPixbuf.PixbufError"]);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Gir.Tests/Test.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace Gir.Tests
4 | {
5 | [TestFixture]
6 | public class ParserTests : GenerationTestBase
7 | {
8 | [TestCase (Library.Gtk2)]
9 | [TestCase (Library.Gtk3)]
10 | public void CanLoadGirFiles (Library library)
11 | {
12 | foreach (var repo in ParseAllGirFiles (library)) {
13 | // Should not throw.
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/AvahiCore-0.6.gir:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
17 |
20 |
21 |
22 |
25 |
28 |
31 |
34 |
37 |
40 |
43 |
46 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/DBus-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/DBusGLib-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/GL-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/GModule-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/GSSDP-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/JSCore-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/SoupGNOME-2.4.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
37 | Creates a #SoupCookieJarSqlite.
38 | cookies. If @read_only is %FALSE, then the non-session cookies will
39 | be written to @filename when the 'changed' signal is emitted from
40 | the jar. (If @read_only is %TRUE, then the cookie jar will only be
41 | used for this session, and changes made to it will be lost when the
42 | jar is destroyed.)
43 |
44 | the new #SoupCookieJar
45 |
46 |
47 |
48 |
49 | the filename to read to/write from, or %NULL
50 |
51 |
52 |
53 | %TRUE if @filename is read-only
54 |
55 |
56 |
57 |
58 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
111 |
112 |
113 |
114 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/cairo-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
12 |
15 |
16 |
19 |
22 |
25 |
28 |
31 |
34 |
35 |
36 |
37 |
40 |
43 |
44 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/fontconfig-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/freetype2-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/libxml2-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/xfixes-4.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/xft-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/xlib-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk2/xrandr-1.3.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk3/cairo-1.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
14 |
17 |
18 |
21 |
24 |
27 |
30 |
33 |
36 |
37 |
38 |
39 |
42 |
45 |
46 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/src/Gir.Tests/TestFiles/Gtk3/xlib-2.0.gir:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/Gir.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir", "Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir.Tests", "Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.ActiveCfg = Debug|x86
15 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.Build.0 = Debug|x86
16 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.ActiveCfg = Release|x86
17 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.Build.0 = Release|x86
18 | {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.ActiveCfg = Debug|Any CPU
19 | {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.Build.0 = Debug|Any CPU
20 | {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.ActiveCfg = Release|Any CPU
21 | {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.Build.0 = Release|Any CPU
22 | EndGlobalSection
23 | EndGlobal
24 |
--------------------------------------------------------------------------------
/src/Gir/Error.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public abstract class Error
5 | {
6 | public abstract string Message { get; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Array.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Array : IGeneratable
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 |
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Bitfield.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Bitfield : IGeneratable, IDocumented, IEnumFormatter
5 | {
6 | public string FormatValue (string value)
7 | {
8 | int intValue = int.Parse (value);
9 |
10 | // Maybe pad with leading zeroes based on the value?
11 | return string.Format ("0x{0:X}", intValue);
12 | }
13 |
14 | public void Generate (GenerationOptions opts)
15 | {
16 | using (var writer = this.GetWriter (opts)) {
17 | this.GenerateDocumentation (writer);
18 | writer.WriteLine ("[Flags]");
19 | writer.WriteLine ("public enum " + Name);
20 | writer.WriteLine ("{");
21 |
22 | using (writer.Indent ()) {
23 | this.GenerateMembers (writer);
24 | }
25 | writer.WriteLine ("}");
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Callback.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public partial class Callback : IGeneratable, IMethodLike
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 | using (var writer = this.GetWriter (opts))
9 | {
10 | // TODO: Validation if we have an userdata parameter we can use so we can write this code.
11 | // Otherwise, we need to generate code which uses a non-static callback.
12 |
13 | var returnType = this.GetReturnCSharpType (writer);
14 | var parameters = this.BuildParameters (opts, true);
15 |
16 | // Public API delegate which uses managed types.
17 | writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
18 | writer.WriteLine ($"public delegate {returnType} {Name} ({parameters.TypesAndNames})");
19 | writer.WriteLine ();
20 |
21 | // Internal API delegate which uses unmanaged types.
22 | writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
23 | // TODO: Use native marshal types.
24 | writer.WriteLine ($"internal delegate {returnType} {Name}Native ({parameters.TypesAndNames})");
25 | writer.WriteLine ();
26 |
27 | // Generate wrapper class - static if we can use gchandle, otherwise instance
28 | // Check callback convention - async, notify, call
29 | writer.WriteLine ($"internal static class {Name}Wrapper");
30 | writer.WriteLine ("{");
31 | using (writer.Indent ()) {
32 | writer.WriteLine ($"public static void NativeCallback ({parameters.TypesAndNames})");
33 | writer.WriteLine ("{");
34 | // TODO: marshal params, call, handle exceptions
35 | writer.WriteLine ("}");
36 | }
37 | writer.WriteLine ("}");
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Class.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Gir
5 | {
6 | public partial class Class : IGeneratable, IDocumented
7 | {
8 | public void Generate (GenerationOptions opts)
9 | {
10 | using (var writer = this.GetWriter (opts)) {
11 | this.GenerateDocumentation (writer);
12 |
13 | var inheritanceList = new List ();
14 | if (!string.IsNullOrEmpty (Parent))
15 | inheritanceList.Add (Parent);
16 | inheritanceList.AddRange (Implements.Select (x => opts.GenerateInterfacesWithIPrefix ? "I" + x.Name : x.Name));
17 |
18 | var inheritanceString = string.Join (", ", inheritanceList.ToArray ());
19 | if (!string.IsNullOrEmpty (inheritanceString)) {
20 | writer.WriteLine ($"public class {Name} : {inheritanceString}");
21 | } else {
22 | writer.WriteLine ($"public class {Name}");
23 | }
24 | writer.WriteLine ("{");
25 |
26 | using (writer.Indent ()) {
27 | this.GenerateMembers (writer);
28 | }
29 | writer.WriteLine ("}");
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Constant.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Constant : IGeneratable
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Constructor.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Constructor : INativeCallable, IDocumented
5 | {
6 | public string GetModifiers (IGeneratable parent, GenerationOptions opts)
7 | {
8 | if (parent is Class @class && @class.Abstract)
9 | return "protected";
10 |
11 | return "public";
12 | }
13 |
14 | public void Generate (IGeneratable parent, IndentWriter writer)
15 | {
16 | this.GenerateConstructor (parent, writer);
17 | }
18 |
19 | public bool NewlineAfterGeneration (GenerationOptions opts) => true;
20 | bool INativeCallable.IsInstanceCallable (IGeneratable parent, GenerationOptions opts) => false;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Enumeration.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Enumeration : IGeneratable, IDocumented
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 | using (var writer = this.GetWriter (opts)) {
9 | this.GenerateDocumentation (writer);
10 | writer.WriteLine ("public enum " + Name);
11 | writer.WriteLine ("{");
12 |
13 | using (writer.Indent ()) {
14 | this.GenerateMembers (writer);
15 | }
16 | writer.WriteLine ("}");
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Field.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Field : IMemberGeneratable, IDocumented
5 | {
6 | public void Generate (IGeneratable parent, IndentWriter writer)
7 | {
8 | // Simple uncorrect gen for now
9 | var managedType = this.Resolve (writer.Options);
10 |
11 | // We need something that will tell us the equivalent C# type
12 | // including the number of pointers.
13 | // For now, generate normal info.
14 |
15 | writer.WriteLine($"{managedType.CSharpType} {Name.ToCSharp ()};");
16 | }
17 |
18 | public bool NewlineAfterGeneration (GenerationOptions opts) => true;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Function.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | namespace Gir
4 | {
5 | public partial class Function : INativeCallable
6 | {
7 | // TODO: Decide what to do here if we have functions which work
8 | // on instances (instance-parameter is not set)
9 | public string GetModifiers (IGeneratable parent, GenerationOptions opts)
10 | {
11 | if (CanFirstParameterBeInstance (parent, opts))
12 | return "public";
13 | return "public static";
14 | }
15 |
16 | public void Generate (IGeneratable parent, IndentWriter writer)
17 | {
18 | this.GenerateCallableDefinition (parent, writer);
19 | }
20 |
21 | public bool NewlineAfterGeneration (GenerationOptions opts) => true;
22 |
23 | public bool IsInstanceCallable (IGeneratable parent, GenerationOptions opts) => CanFirstParameterBeInstance (parent, opts);
24 |
25 | // TODO: Unexpose this
26 | public bool CanFirstParameterBeInstance (IGeneratable parent, GenerationOptions opts)
27 | {
28 | var param = Parameters.FirstOrDefault();
29 | if (param == null)
30 | return false;
31 |
32 | // hacky check for symbol equality
33 | return param.Resolve (opts).GetType () == parent.GetType ();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Gir/Generation/IGeneratable.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Gir
4 | {
5 | // Top level generation capability
6 | public interface IGeneratable
7 | {
8 | string Name { get; }
9 | //void Process();
10 | void Generate (GenerationOptions opts);
11 | }
12 |
13 | // IDocumented might end up being added to IGeneratable/IMemberGeneratable
14 | public interface IDocumented
15 | {
16 | Documentation Doc { get; }
17 | }
18 |
19 | // When generated as part of another generatable
20 | public interface IMemberGeneratable
21 | {
22 | string Name { get; }
23 | bool NewlineAfterGeneration (GenerationOptions opts);
24 | void Generate (IGeneratable parent, IndentWriter writer);
25 | }
26 |
27 | public interface IMethodLike
28 | {
29 | ReturnValue ReturnValue { get; }
30 | List Parameters { get; }
31 | }
32 |
33 | public interface INativeCallable : IMemberGeneratable, IMethodLike, IDocumented
34 | {
35 | // TODO: Check if only one param and prefixed with Get/Set.
36 | //bool CanGenerateAsProperty (IGeneratable parent, GenerationOptions opts);
37 |
38 | bool IsInstanceCallable (IGeneratable parent, GenerationOptions opts);
39 | string GetModifiers (IGeneratable parent, GenerationOptions opts);
40 |
41 | string CIdentifier { get; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Gir/Generation/IGeneratableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 |
6 | namespace Gir
7 | {
8 | public static class IGeneratableExtensions
9 | {
10 | const string CSharpFileExtension = ".cs";
11 |
12 | public static IndentWriter GetWriter (this IGeneratable gen, GenerationOptions opts)
13 | {
14 | var path = Path.Combine (opts.DirectoryPath, gen.Name + CSharpFileExtension);
15 | return IndentWriter.OpenWrite (path, opts).WriteHeader ();
16 | }
17 |
18 | public static void GenerateDocumentation (this IDocumented gen, IndentWriter writer)
19 | {
20 | if (gen.Doc is null)
21 | return;
22 |
23 | writer.WriteDocumentation (gen.Doc, gen is ReturnValue ? "returns" : "summary");
24 | }
25 |
26 | public static void GenerateMembers (this IGeneratable gen, IndentWriter writer, Func where = null)
27 | {
28 | var array = gen.GetMemberGeneratables ().Where (x => where == null || where (x)).ToArray ();
29 | for (int i = 0; i < array.Length; ++i) {
30 | var member = array [i];
31 |
32 | // Generate pinvoke signature for a method
33 | if (!(gen is Interface) && member is INativeCallable callable)
34 | callable.GenerateImport (gen, writer);
35 |
36 | // Generate documentation is a member supports it.
37 | if (member is IDocumented doc)
38 | doc.GenerateDocumentation (writer);
39 |
40 | // Call the main member generation implementation.
41 | member.Generate (gen, writer);
42 |
43 | if (i != array.Length - 1 && member.NewlineAfterGeneration (writer.Options))
44 | writer.WriteLine ();
45 | }
46 | }
47 |
48 | static void GenerateImport (this INativeCallable callable, IGeneratable parent, IndentWriter writer)
49 | {
50 | var retType = GetReturnCSharpType (callable, writer);
51 |
52 | var parameters = BuildParameters (callable, writer.Options, appendInstanceParameters: true);
53 |
54 | // TODO: Better than using the constant string, insert a custom generatable which contains the import string as a constant.
55 | /* i.e.
56 | static class Constants
57 | {
58 | public const string GLib = "libglib-2.0.so";
59 | }
60 | */
61 | //writer.WriteLine ($"[DllImport (\"{writer.Options.LibraryName}\", CallingConvention=CallingConvention.Cdecl)]");
62 | writer.WriteLine ($"static extern {retType} {callable.CIdentifier} ({parameters.MarshalTypesAndNames});");
63 | writer.WriteLine ();
64 | }
65 |
66 | public static string GetReturnCSharpType (this IMethodLike callable, IndentWriter writer)
67 | {
68 | var retVal = callable.ReturnValue;
69 | if (retVal == null)
70 | return "void";
71 |
72 | // TODO: Handle marshalling.
73 |
74 | // Try getting the array return value, then the type one.
75 | var retSymbol = retVal.Resolve (writer.Options);
76 | return retSymbol.CSharpType;
77 | }
78 |
79 | public static void GenerateCallableDefinition (this INativeCallable callable, IGeneratable gen, IndentWriter writer)
80 | {
81 | callable.ReturnValue.GenerateDocumentation (writer);
82 |
83 | writer.WriteIndent ();
84 | if (!string.IsNullOrEmpty (callable.GetModifiers (gen, writer.Options)) && !(gen is Interface))
85 | writer.Write (callable.GetModifiers (gen, writer.Options) + " ");
86 |
87 | var returnType = callable.GetReturnCSharpType (writer);
88 |
89 | // generate ReturnValue then Parameters
90 | var result = BuildParameters (callable, writer.Options, !callable.IsInstanceCallable (gen, writer.Options));
91 | writer.Write ($"{returnType} {callable.Name.ToCSharp ()} ({result.TypesAndNames})");
92 |
93 | if (gen is Interface) {
94 | writer.Write (";");
95 | writer.WriteLine();
96 | return;
97 | }
98 |
99 | writer.WriteLine();
100 | writer.WriteLine("{");
101 | using (writer.Indent())
102 | {
103 | string prefix = returnType != "void" ? "return " : string.Empty;
104 | writer.WriteLine($"{prefix}{callable.CIdentifier} ({result.Names});");
105 | }
106 | writer.WriteLine("}");
107 | }
108 |
109 | public static void GenerateConstructor (this INativeCallable callable, IGeneratable parent, IndentWriter writer)
110 | {
111 | callable.ReturnValue.GenerateDocumentation (writer);
112 |
113 | var modifier = callable.GetModifiers (parent, writer.Options);
114 |
115 | var result = BuildParameters (callable, writer.Options, !callable.IsInstanceCallable (parent, writer.Options));
116 |
117 | // FIXME, should check to see if it is deprecated
118 | writer.WriteLine ($"{modifier} {parent.Name} ({result.TypesAndNames}) : base ({result.Names})");
119 | writer.WriteLine ("{");
120 | writer.WriteLine ("}");
121 | }
122 |
123 | public static ParametersResult BuildParameters(this IMethodLike callable, GenerationOptions opts, bool appendInstanceParameters)
124 | {
125 | var parameters = callable.Parameters;
126 | var marshalTypeAndName = new List(parameters.Count);
127 | var typeAndName = new List (parameters.Count);
128 | var parameterNames = new List (parameters.Count);
129 |
130 | for (int i = 0; i < parameters.Count; ++i) {
131 | var parameter = parameters [i];
132 | if (!appendInstanceParameters) {
133 | if (parameter is InstanceParameter)
134 | continue;
135 |
136 | // HACK: Make this proper
137 | if (i == 0 && callable is Function)
138 | continue;
139 | }
140 |
141 | var symbol = parameter.Resolve(opts);
142 | marshalTypeAndName.Add(symbol.CSharpType + " " + parameter.Name);
143 | typeAndName.Add(symbol.CSharpType + (parameter.Array != null ? "[]" : "") + " " + parameter.Name);
144 | parameterNames.Add(parameter.Name);
145 | }
146 |
147 | // PERF: Use an array as the string[] overload of Join is way more efficient than the IEnumerable one.
148 | string marshalParameterString = string.Join(", ", marshalTypeAndName.ToArray());
149 | string parameterString = string.Join (", ", typeAndName.ToArray ());
150 | string baseParams = string.Join (", ", parameterNames.ToArray ());
151 |
152 | return new ParametersResult(marshalParameterString, parameterString, baseParams);
153 | }
154 |
155 | static IEnumerable GetMemberGeneratables (this IGeneratable gen)
156 | {
157 | return Utils.GetAllCollectionMembers (gen);
158 | }
159 | }
160 |
161 | public class ParametersResult
162 | {
163 | public string MarshalTypesAndNames { get; }
164 | public string TypesAndNames { get; }
165 | public string Names { get; }
166 |
167 | public ParametersResult(string marshalTypesAndNames, string typesAndNames, string names)
168 | {
169 | MarshalTypesAndNames = marshalTypesAndNames;
170 | TypesAndNames = typesAndNames;
171 | Names = names;
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/Gir/Generation/IndentWriter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Gir
5 | {
6 | public class IndentWriter : IDisposable
7 | {
8 | TextWriter writer;
9 | int indent;
10 |
11 | public GenerationOptions Options { get; private set; }
12 |
13 | public static IndentWriter OpenWrite (string path, GenerationOptions opts)
14 | {
15 | var toStream = opts.RedirectStream ?? File.Open (path, FileMode.Create);
16 | var sw = new StreamWriter (toStream) {
17 | NewLine = opts.NewLine
18 | };
19 |
20 | return new IndentWriter (sw) {
21 | Options = opts,
22 | };
23 | }
24 |
25 | public IndentWriter WriteHeader ()
26 | {
27 | if (!Options.WriteHeader)
28 | return this;
29 |
30 | WriteLine ("using System;");
31 | WriteLine ("using System.Runtime.InteropServices;");
32 | // TODO: Uncomment this when we know exactly which namespaces to include.
33 | //foreach (var include in Options.UsingNamespaces) {
34 | // if (include == Options.Namespace)
35 | // continue;
36 | // WriteLine ($"using {include};");
37 | //}
38 | WriteLine ();
39 |
40 | WriteLine ($"namespace {Options.Namespace}");
41 | WriteLine ("{");
42 | Indent ();
43 |
44 | return this;
45 | }
46 |
47 | public IndentWriter (TextWriter tw)
48 | {
49 | writer = tw;
50 | }
51 |
52 | public void Dispose ()
53 | {
54 | if (writer != null) {
55 | if (Options.WriteHeader) {
56 | Unindent ();
57 | WriteLine ("}");
58 | }
59 |
60 | writer?.Dispose ();
61 | writer = null;
62 | }
63 | }
64 |
65 | public IndentWriter WriteDocumentation (Documentation doc, string tag)
66 | {
67 | if (!Options.GenerateDocumentation)
68 | return this;
69 |
70 | var text = doc.Text.Split ('\n');
71 | if (text.Length == 1) {
72 | WriteIndent ();
73 | return Write ($"///<{tag}>").Write (text [0]).Write ($"{tag}>").WriteLine ();
74 | }
75 |
76 | WriteLine ($"///<{tag}>");
77 | foreach (var line in text)
78 | WriteLine ("/// " + line);
79 | return WriteLine ($"///{tag}>");
80 | }
81 |
82 | public IndentWriter WriteIndent ()
83 | {
84 | writer.Write (new string ('\t', indent));
85 | return this;
86 | }
87 |
88 | public IndentWriter Write (string s)
89 | {
90 | writer.Write (s);
91 | return this;
92 | }
93 |
94 | public IndentWriter WriteLine ()
95 | {
96 | writer.WriteLine ();
97 | return this;
98 | }
99 |
100 | public IndentWriter WriteLine (string s)
101 | {
102 | return WriteIndent ().Write (s).WriteLine ();
103 | }
104 |
105 | public IndentWriter WriteLineAndIndent (string s)
106 | {
107 | WriteLine (s);
108 | Indent ();
109 | return this;
110 | }
111 |
112 | public IndentWriter WriteLineAndUnindent (string s)
113 | {
114 | Unindent ();
115 | WriteLine (s);
116 | return this;
117 | }
118 |
119 | public IDisposable Indent ()
120 | {
121 | indent++;
122 | return new IndentDisposable (this);
123 | }
124 |
125 | public void Unindent ()
126 | {
127 | indent--;
128 | }
129 |
130 | class IndentDisposable : IDisposable
131 | {
132 | readonly IndentWriter writer;
133 | public IndentDisposable (IndentWriter writer)
134 | {
135 | this.writer = writer;
136 | }
137 |
138 | public void Dispose ()
139 | {
140 | writer.indent--;
141 | }
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Interface.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Interface : IGeneratable, IDocumented
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 | using (var writer = this.GetWriter (opts)) {
9 | this.GenerateDocumentation (writer);
10 | var interfaceName = (opts.GenerateInterfacesWithIPrefix) ? $"I{Name}" : Name;
11 | writer.WriteLine ($"public interface {interfaceName}");
12 | writer.WriteLine ("{");
13 |
14 | using (writer.Indent ()) {
15 | this.GenerateMembers (writer);
16 | }
17 | writer.WriteLine ("}");
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Member.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Member : IMemberGeneratable, IDocumented
5 | {
6 | public bool NewlineAfterGeneration (GenerationOptions opts) => opts.GenerateDocumentation;
7 |
8 | public void Generate (IGeneratable parent, IndentWriter writer)
9 | {
10 | string value = Value;
11 | if (parent is IEnumFormatter formatter)
12 | value = formatter.FormatValue (value);
13 |
14 | writer.WriteLine (Name.ToCSharp () + " = " + value + ",");
15 | }
16 | }
17 |
18 | public interface IEnumFormatter
19 | {
20 | string FormatValue (string value);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Method.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Method : INativeCallable
5 | {
6 | public string GetModifiers (IGeneratable parent, GenerationOptions opts) => "public";
7 |
8 | public void Generate (IGeneratable parent, IndentWriter writer)
9 | {
10 | if (!string.IsNullOrEmpty (Deprecated)) {
11 | if (Deprecated == "1")
12 | writer.WriteLine ($"[Obsolete (\"(Version: {DeprecatedVersion}) {DocDeprecated.Text}\")]");
13 | else if (Deprecated != "0")
14 | writer.WriteLine ($"[Obsolete (\"{Deprecated}\")]");
15 | }
16 | this.GenerateCallableDefinition (parent, writer);
17 | }
18 |
19 | public bool NewlineAfterGeneration (GenerationOptions opts) => true;
20 | public bool IsInstanceCallable (IGeneratable parent, GenerationOptions opts) => true;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Namespace.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Gir
4 | {
5 | public partial class Namespace
6 | {
7 | public IEnumerable GetGeneratables () => Utils.GetAllCollectionMembers (this);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Property.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Gir
4 | {
5 | public partial class Property : IGeneratable, IDocumented
6 | {
7 | public void Generate (GenerationOptions opts)
8 | {
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Record.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Record : IGeneratable, IDocumented
5 | {
6 | public void Generate (GenerationOptions opts)
7 | {
8 | using (var writer = this.GetWriter (opts)) {
9 | this.GenerateDocumentation (writer);
10 |
11 | var access = "public";
12 | if (!string.IsNullOrEmpty (GLibIsGTypeStructFor))
13 | access = "internal";
14 |
15 | writer.WriteLine ("[StructLayout (LayoutKind.Sequential)]");
16 | writer.WriteLine ($"{access} struct {Name}");
17 | writer.WriteLine ("{");
18 |
19 | using (writer.Indent ()) {
20 | this.GenerateMembers (writer);
21 | }
22 | writer.WriteLine ("}");
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Repository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Gir
4 | {
5 | public partial class Repository
6 | {
7 | public IEnumerable GetGeneratables () => Namespace.GetGeneratables ();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Gir/Generation/Signal.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Signal : IMemberGeneratable, IDocumented
5 | {
6 | public void Generate(IGeneratable parent, IndentWriter writer)
7 | {
8 | writer.WriteLine($"event {EventHandlerQualifiedName(parent)} {Name.ToCSharp()};");
9 | }
10 |
11 | bool IsEventHandler {
12 | get {
13 | return ReturnValue.Type.CType == "void" && Parameters.Count == 0;// && (Parameters[0] is Object || Parameters[0] is Interface);
14 | }
15 | }
16 |
17 | string EventHandlerQualifiedName (IGeneratable parent)
18 | {
19 | if (IsEventHandler)
20 | return "System.EventHandler";
21 |
22 | return parent.Name + "." + EventHandlerName;
23 | }
24 |
25 | public bool NewlineAfterGeneration (GenerationOptions opts) => true;
26 |
27 | string EventHandlerName {
28 | get {
29 | if (IsEventHandler)
30 | return "EventHandler";
31 |
32 | //if (SymbolTable.Table[container_type.NS + Name + "Handler"] != null)
33 | //return Name + "EventHandler";
34 |
35 | return Name + "Handler";
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Gir/GenerationOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 |
6 | namespace Gir
7 | {
8 | public sealed class GenerationOptions
9 | {
10 | public SymbolTable SymbolTable { get; }
11 | public Statistics Statistics { get; } = new Statistics ();
12 | public ToggleOptions Options { get; }
13 |
14 | #region Generation information
15 | public string DirectoryPath { get; }
16 | public string Namespace => Repository.Namespace.Name;
17 | public IEnumerable UsingNamespaces => AllRepositories.Select (x => x.Namespace.Name);
18 | public Stream RedirectStream => Options.RedirectStream;
19 |
20 | public string LibraryName { get; }
21 |
22 | public IEnumerable AllGeneratables => allGeneratables;
23 | #endregion
24 |
25 | #region Generation toggles
26 | public bool GenerateDocumentation => !Options.Compat;
27 | public bool GenerateInterfacesWithIPrefix => !Options.Compat;
28 | public bool WriteHeader => Options.WriteHeader;
29 |
30 | // Try to find better logic for detecting this.
31 | public bool NativeWin64 => Options.Win64Longs;
32 |
33 | public string NewLine => Options.NewLine;
34 | #endregion
35 |
36 | #region Symbols
37 |
38 | #endregion
39 |
40 | IEnumerable AllRepositories { get; }
41 | Repository Repository { get; }
42 | List allGeneratables = new List ();
43 |
44 | public GenerationOptions (string dir, IEnumerable allRepos, Repository repo, ToggleOptions options = null)
45 | {
46 | // Set options to default if none
47 | Options = options ?? new ToggleOptions ();
48 |
49 | DirectoryPath = dir;
50 | AllRepositories = allRepos;
51 | Repository = repo;
52 | allGeneratables.AddRange (Repository.GetGeneratables ());
53 |
54 | // This may contain multiple libraries, so get the first one. Also, hack a string.Empty for xlib.
55 | LibraryName = repo.Namespace.SharedLibrary?.Split (',') [0] ?? "";
56 |
57 | SymbolTable = new SymbolTable(Statistics, Options.Win64Longs);
58 |
59 | // Register the main repository once without namespace names and once with them.
60 | SymbolTable.AddTypes (repo.GetSymbols());
61 | foreach (var repository in allRepos) {
62 | SymbolTable.AddTypes (repository.GetSymbols(), repository);
63 | }
64 | SymbolTable.ProcessAliases();
65 | }
66 |
67 | public class ToggleOptions
68 | {
69 | public bool Compat;
70 | public Stream RedirectStream;
71 | public bool Win64Longs;
72 | public bool WriteHeader = true;
73 | public string NewLine = Environment.NewLine;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Gir/Gir.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Debug
4 | x86
5 | {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}
6 | Exe
7 | Gir
8 | Gir
9 | v4.7
10 |
11 |
12 | true
13 | full
14 | false
15 | bin\Debug
16 | DEBUG;
17 | prompt
18 | 4
19 | true
20 | true
21 | x86
22 |
23 |
24 | true
25 | bin\Release
26 | prompt
27 | 4
28 | true
29 | x86
30 | true
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Alias.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Gir
4 | {
5 | public partial class Alias : ISymbol
6 | {
7 | public string CSharpType => throw new NotSupportedException ();
8 | public string DefaultValue => throw new NotSupportedException ();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Array.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public partial class Array
5 | {
6 | public ISymbol GetSymbol (GenerationOptions opts)
7 | {
8 | if (Name != null)
9 | return opts.SymbolTable [Name];
10 |
11 | // TODO: Here, we need to return a custom ISymbol implementation for a plain array in case name is not null.
12 | return opts.SymbolTable [Type.Name];
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Bitfield.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Bitfield : ISymbol
5 | {
6 | // FIXME: Probably default to the first value
7 | public string DefaultValue => "default(" + Name + ")";
8 | public string CSharpType => Name;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Callback.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public partial class Callback : ISymbol
5 | {
6 | public string CSharpType => Name;
7 |
8 | public string DefaultValue => "null";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Class.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Class : ISymbol
5 | {
6 | public string CSharpType => Name;
7 |
8 | public string DefaultValue => throw new System.NotImplementedException ();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Enumeration.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Enumeration : ISymbol
5 | {
6 | // FIXME: Probably default to the first value
7 | public string DefaultValue => "default(" + Name + ")";
8 | public string CSharpType => Name;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Field.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Field : ITypeOrArray
5 | {
6 | public ReturnValue ReturnValue => null;
7 | public Varargs Varargs => null;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/IPassByValue.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public interface IPassByValue
5 | {
6 | string ByValueMarshalType { get; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/ISymbol.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public interface ISymbol
5 | {
6 | string CSharpType { get; }
7 | string Name { get; }
8 | string DefaultValue { get; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/ISymbolExtensions.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public static class ISymbolExtensions
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/IType.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public interface IType
5 | {
6 | Type Type { get; }
7 | }
8 |
9 | public static class IHasTypeExtensions
10 | {
11 | public static ISymbol GetSymbol (this IType type, GenerationOptions opts)
12 | {
13 | return opts.SymbolTable [type.Type.Name];
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/ITypeOrArray.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public interface ITypeOrArray : IType
5 | {
6 | Array Array { get; }
7 | Varargs Varargs { get; }
8 | Callback Callback { get; }
9 | }
10 |
11 | public static class ITypeOrArrayExtensions
12 | {
13 | public static ISymbol Resolve (this ITypeOrArray toResolve, GenerationOptions opts)
14 | {
15 | return toResolve.Array?.GetSymbol(opts) ?? toResolve.Type?.GetSymbol(opts) ?? (ISymbol)toResolve.Callback ?? toResolve.Varargs;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Interface.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Gir
4 | {
5 | public partial class Interface : ISymbol
6 | {
7 | public string CSharpType => "I" + Name;
8 |
9 | public string DefaultValue => throw new NotImplementedException ();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Namespace.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Gir
4 | {
5 | public partial class Namespace
6 | {
7 | public IEnumerable GetSymbols () => Utils.GetAllCollectionMembers (this);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Primitive.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public class Primitive : ISymbol
5 | {
6 | public string Name { get; }
7 | public string CSharpType { get; }
8 | public string DefaultValue { get; }
9 |
10 | public string ByValueMarshalType => CSharpType;
11 |
12 | public Primitive(string name, string csharpType, string defaultValue)
13 | {
14 | Name = name;
15 | CSharpType = csharpType;
16 | DefaultValue = defaultValue;
17 | }
18 | }
19 |
20 | public class StringMarshal : Primitive
21 | {
22 | public string MarshalType { get; }
23 |
24 | public StringMarshal (string ctype, string csharpType, string defaultValue, string marshalType) : base (ctype, csharpType, defaultValue)
25 | {
26 | MarshalType = marshalType;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Record.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class Record : ISymbol
5 | {
6 | public string CSharpType => Name;
7 |
8 | public string DefaultValue => "default(" + Name + ")";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Repository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Gir
4 | {
5 | public partial class Repository
6 | {
7 | public IEnumerable GetSymbols () => Namespace.GetSymbols ();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/SymbolTable.Builtin.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class SymbolTable
5 | {
6 | // Only call this, not the ones below.
7 | void RegisterBuiltIn (bool nativeWin64)
8 | {
9 | RegisterPrimitives (nativeWin64);
10 |
11 | //AddType(new MarshalGen("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
12 | AddType (new StringMarshal ("utf8", "string", "string.Empty", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
13 | }
14 |
15 | void RegisterPrimitives (bool nativeWin64)
16 | {
17 | AddType (new Primitive ("none", "void", string.Empty));
18 | AddType (new Primitive ("gpointer", "IntPtr", "IntPtr.Zero"));
19 | AddType (new Primitive ("gconstpointer", "IntPtr", "IntPtr.Zero"));
20 | AddType (new Primitive ("gboolean", "bool", "false"));
21 | AddType (new Primitive ("gint", "int", "0"));
22 | AddType (new Primitive ("guint", "uint", "0"));
23 | AddType (new Primitive ("int", "int", "0"));
24 | AddType (new Primitive ("unsigned", "uint", "0"));
25 | AddType (new Primitive ("unsigned int", "uint", "0"));
26 | AddType (new Primitive ("gshort", "short", "0"));
27 | AddType (new Primitive ("gushort", "ushort", "0"));
28 | AddType (new Primitive ("short", "short", "0"));
29 | AddType (new Primitive ("guchar", "byte", "0"));
30 | AddType (new Primitive ("unsigned char", "byte", "0"));
31 | AddType (new Primitive ("guint1", "bool", "false"));
32 | AddType (new Primitive ("uint1", "bool", "false"));
33 | AddType (new Primitive ("gint8", "sbyte", "0"));
34 | AddType (new Primitive ("guint8", "byte", "0"));
35 | AddType (new Primitive ("gint16", "short", "0"));
36 | AddType (new Primitive ("guint16", "ushort", "0"));
37 | AddType (new Primitive ("gint32", "int", "0"));
38 | AddType (new Primitive ("guint32", "uint", "0"));
39 | AddType (new Primitive ("gint64", "long", "0"));
40 | AddType (new Primitive ("guint64", "ulong", "0"));
41 | AddType (new Primitive ("long long", "long", "0"));
42 | AddType (new Primitive ("gfloat", "float", "0.0"));
43 | AddType (new Primitive ("float", "float", "0.0"));
44 | AddType (new Primitive ("gdouble", "double", "0.0"));
45 | AddType (new Primitive ("double", "double", "0.0"));
46 | AddType (new Primitive ("goffset", "long", "0"));
47 |
48 | AddType (new Primitive ("ssize_t", "IntPtr", "IntPtr.Zero"));
49 | AddType (new Primitive ("gssize", "IntPtr", "IntPtr.Zero"));
50 | AddType (new Primitive ("size_t", "UIntPtr", "UIntPtr.Zero"));
51 | AddType (new Primitive ("gsize", "UIntPtr", "UIntPtr.Zero"));
52 |
53 | AddType (new Primitive ("va_list", "...", ""));
54 |
55 | RegisterGTypeHack ();
56 | RegisterLongTypes (nativeWin64);
57 | }
58 |
59 | void RegisterGTypeHack ()
60 | {
61 | // It seems like GType is kind of a primitive since in GObject GType is used without a prefix even though the definition is in GLib.
62 | var alias = new Alias {
63 | Type = new Type {
64 | CType = "GType",
65 | Name = "GLib.Type",
66 | Array = null
67 | },
68 | Doc = new Documentation {
69 | Text = ""
70 | },
71 | CType = "GType",
72 | Name = "GType"
73 | };
74 | AddType (alias);
75 | }
76 |
77 | void RegisterLongTypes (bool nativeWin64)
78 | {
79 | if (nativeWin64) {
80 | AddType (new Primitive ("long", "int", "0"));
81 | AddType (new Primitive ("glong", "int", "0"));
82 | AddType (new Primitive ("ulong", "uint", "0"));
83 | AddType (new Primitive ("gulong", "uint", "0"));
84 | AddType (new Primitive ("unsigned long", "uint", "0"));
85 | }
86 | else {
87 | AddType (new Primitive ("long", "IntPtr", "IntPtr.Zero"));
88 | AddType (new Primitive ("glong", "IntPtr", "IntPtr.Zero"));
89 | AddType (new Primitive ("ulong", "UIntPtr", "UIntPtr.Zero"));
90 | AddType (new Primitive ("gulong", "UIntPtr", "IntPtr.Zero"));
91 | AddType (new Primitive ("unsigned long", "UIntPtr", "IntPtr.Zero"));
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/SymbolTable.RegistrationError.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class SymbolTable
5 | {
6 | [System.Diagnostics.DebuggerDisplay ("{DebuggerDisplay}")]
7 | class AliasRegistrationError : Error
8 | {
9 | readonly Alias alias;
10 |
11 | public AliasRegistrationError (Alias alias)
12 | {
13 | this.alias = alias;
14 | }
15 |
16 | public override string Message => $"Alias {alias.Name} pointing to non-registered {alias.Type.Name}, setting to 'none'";
17 |
18 | string DebuggerDisplay => $"{alias.Name} alias failure to {alias.Type.Name}";
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/SymbolTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace Gir
7 | {
8 | public partial class SymbolTable : IEnumerable
9 | {
10 | readonly Dictionary typeMap = new Dictionary ();
11 | Statistics statistics;
12 |
13 | public SymbolTable (Statistics statistics, bool nativeWin64)
14 | {
15 | this.statistics = statistics;
16 |
17 | RegisterBuiltIn (nativeWin64);
18 | }
19 |
20 | public void AddTypes (IEnumerable symbols, Repository repository = null)
21 | {
22 | string nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty;
23 |
24 | foreach (var symbol in symbols)
25 | AddTypeCommon (nsPrefix + symbol.Name, symbol);
26 | }
27 |
28 | public void AddType (ISymbol symbol, Repository repository = null)
29 | {
30 | string nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty;
31 | AddTypeCommon (nsPrefix + symbol.Name, symbol);
32 | }
33 |
34 | void AddTypeCommon (string key, ISymbol symbol)
35 | {
36 | typeMap [key] = symbol;
37 |
38 | // Maybe do not register the type if we didn't pass in the repository, so we don't count things twice.
39 | statistics.RegisterType(symbol);
40 | }
41 |
42 | public ISymbol this [string type] => typeMap[type];
43 |
44 | public void ProcessAliases ()
45 | {
46 | char [] separator = { '.' };
47 |
48 | var copy = typeMap.ToDictionary (x => x.Key, x => x.Value);
49 | foreach (var kvp in copy) {
50 | if (kvp.Value is Alias alias) {
51 | // This is inside a resolved repository
52 | string repository = null;
53 | if (kvp.Key.Contains ('.')) {
54 | repository = kvp.Key.Split (separator) [0];
55 | }
56 | typeMap[kvp.Key] = Dealias (alias, repository);
57 | }
58 | }
59 | }
60 |
61 | ISymbol Dealias (Alias original, string repository = null)
62 | {
63 | ISymbol target = original;
64 | while (target is Alias alias) {
65 | var toType = alias.Type.Name;
66 | if (typeMap.TryGetValue (toType, out target))
67 | continue;
68 |
69 | if (repository != null) {
70 | // HACK?!: this might be in a included repository but these are prefixed in symbol table
71 | toType = $"{repository}.{alias.Type.Name}";
72 | if (typeMap.TryGetValue (toType, out target))
73 | continue;
74 | }
75 |
76 | statistics.RegisterError(new AliasRegistrationError(alias));
77 | return this["none"];
78 | }
79 |
80 | return target;
81 | }
82 |
83 | // This might contain duplicate symbols since we register the main repo as fully qualified and non-fully qualified.
84 | // Perhaps the better fix is for generatables to handle appending the namespace so it's fully qualified?
85 | public IEnumerator GetEnumerator ()
86 | {
87 | return typeMap.Values.GetEnumerator ();
88 | }
89 |
90 | IEnumerator IEnumerable.GetEnumerator ()
91 | {
92 | return GetEnumerator ();
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Type.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public partial class Type
5 | {
6 | public ISymbol GetSymbol (GenerationOptions opts)
7 | {
8 | return opts.SymbolTable [Name];
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Gir/Marshal/Varargs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Gir
3 | {
4 | public partial class Varargs : ISymbol
5 | {
6 | public string CSharpType => "...";
7 |
8 | public string Name => "va_list";
9 |
10 | public string DefaultValue => "";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Gir/Model/Alias.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Alias : IDocumented
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name { get; set; }
9 |
10 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
11 | public string CType { get; set; }
12 |
13 | [XmlElement ("doc")]
14 | public Documentation Doc { get; set; }
15 |
16 | [XmlElement ("type")]
17 | public Type Type;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Array.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Array
6 | {
7 | [XmlAttribute ("fixed-size")]
8 | public int FixedSize;
9 |
10 | [XmlAttribute ("length")]
11 | public int Length;
12 |
13 | [XmlAttribute ("name")]
14 | public string Name { get; set; }
15 |
16 | [XmlAttribute ("zero-terminated")]
17 | public bool ZeroTerminated;
18 |
19 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
20 | public string CType { get; set; }
21 |
22 | [XmlElement("type")]
23 | public Type Type { get; set; }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Bitfield.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Bitfield
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public bool Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("name")]
15 | public string Name { get; set; }
16 |
17 | [XmlAttribute ("version")]
18 | public string Version;
19 |
20 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
21 | public string CType { get; set; }
22 |
23 | [XmlAttribute ("get-type", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
24 | public string GLibGetType;
25 |
26 | [XmlAttribute ("type-name", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
27 | public string GLibTypeName;
28 |
29 | [XmlElement ("doc")]
30 | public Documentation Doc { get; set; }
31 |
32 | [XmlElement ("member")]
33 | public List Members;
34 |
35 | [XmlElement ("function")]
36 | public List Function;
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Gir/Model/CInclude.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class CInclude
6 | {
7 | [XmlAttribute ("name", Namespace = "http://www.gtk.org/introspection/core/1.0")]
8 | public string Name;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Callback.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Callback
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("introspectable")]
15 | public bool Introspectable;
16 |
17 | [XmlAttribute ("name")]
18 | public string Name { get; set; }
19 |
20 | [XmlAttribute ("throws")]
21 | public bool Throws;
22 |
23 | [XmlAttribute ("version")]
24 | public string Version;
25 |
26 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
27 | public string CType { get; set; }
28 |
29 | [XmlArray ("parameters")]
30 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
31 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
32 | public List Parameters { get; set; }
33 |
34 | [XmlElement ("return-value")]
35 | public ReturnValue ReturnValue { get; set; }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Class.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Class
7 | {
8 | [XmlAttribute ("abstract")]
9 | public bool Abstract;
10 |
11 | [XmlAttribute ("name")]
12 | public string Name { get; set; }
13 |
14 | [XmlAttribute ("parent")]
15 | public string Parent;
16 |
17 | [XmlAttribute ("version")]
18 | public string Version;
19 |
20 | [XmlAttribute ("symbol-prefix", Namespace = "http://www.gtk.org/introspection/c/1.0")]
21 | public string CSymbolPrefix;
22 |
23 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
24 | public string CType { get; set; }
25 |
26 | [XmlAttribute ("fundamental", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
27 | public bool Fundamental;
28 |
29 | [XmlAttribute ("get-type", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
30 | public string GLibGetType;
31 |
32 | [XmlAttribute ("get-value-func", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
33 | public string GLibGetValueFunct;
34 |
35 | [XmlAttribute ("ref-func", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
36 | public string GLibRefFunc;
37 |
38 | [XmlAttribute ("set-value-func", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
39 | public string GLibSetValueFunc;
40 |
41 | [XmlAttribute ("type-name", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
42 | public string GLibTypeName;
43 |
44 | [XmlAttribute ("type-struct", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
45 | public string GLibTypeStruct;
46 |
47 | [XmlAttribute ("unref-func", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
48 | public string GLibUnrefFunc;
49 |
50 | [XmlElement ("doc")]
51 | public Documentation Doc { get; set; }
52 |
53 | [XmlElement ("implements")]
54 | public List Implements;
55 |
56 | [XmlElement ("constructor")]
57 | public List Constructors;
58 |
59 | [XmlElement ("field")]
60 | public List Fields;
61 |
62 | [XmlElement ("property")]
63 | public List Properties;
64 |
65 | [XmlElement ("union")]
66 | public List Unions;
67 |
68 | [XmlElement ("method")]
69 | public List Methods;
70 |
71 | [XmlElement ("virtual-method")]
72 | public List VirtualMethods;
73 |
74 | [XmlElement ("function")]
75 | public List Functions;
76 |
77 | [XmlElement ("signal", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
78 | public List Signals;
79 | }
80 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Constant.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Constant : IDocumented
6 | {
7 | [XmlAttribute ("deprecated")]
8 | public string Deprecated;
9 |
10 | [XmlAttribute ("deprecated-version")]
11 | public string DeprecatedVersion;
12 |
13 | [XmlAttribute ("name")]
14 | public string Name { get; set; }
15 |
16 | [XmlAttribute ("value")]
17 | public string Value;
18 |
19 | [XmlAttribute ("version")]
20 | public string Version;
21 |
22 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
23 | public string CType { get; set; }
24 |
25 | [XmlElement ("doc")]
26 | public Documentation Doc { get; set; }
27 |
28 | [XmlElement ("type")]
29 | public Type Type;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Constructor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Constructor
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("introspectable")]
15 | public bool Introspectable;
16 |
17 | [XmlAttribute ("name")]
18 | public string Name { get; set; }
19 |
20 | [XmlAttribute ("shadowed-by")]
21 | public string ShadowedBy;
22 |
23 | [XmlAttribute ("shadows")]
24 | public string Shadows;
25 |
26 | [XmlAttribute ("throws")]
27 | public bool Throws;
28 |
29 | [XmlAttribute ("version")]
30 | public string Version;
31 |
32 | [XmlAttribute ("identifier", Namespace = "http://www.gtk.org/introspection/c/1.0")]
33 | public string CIdentifier { get; set; }
34 |
35 | [XmlElement ("doc")]
36 | public Documentation Doc { get; set; }
37 |
38 | [XmlElement ("return-value")]
39 | public ReturnValue ReturnValue { get; set; }
40 |
41 | [XmlArray ("parameters")]
42 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
43 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
44 | public List Parameters { get; set; }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Gir/Model/Direction.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public enum Direction
6 | {
7 | [XmlEnum ("out")]
8 | Out,
9 | [XmlEnum ("in")]
10 | In,
11 | [XmlEnum ("inout")]
12 | InOut
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/src/Gir/Model/Documentation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Documentation
7 | {
8 | [XmlText]
9 | public string Text;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Gir/Model/Enumeration.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Enumeration
7 | {
8 | [XmlAttribute ("name")]
9 | public string Name { get; set; }
10 |
11 | [XmlAttribute ("version")]
12 | public string Version;
13 |
14 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
15 | public string CType { get; set; }
16 |
17 | [XmlAttribute ("error-domain", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
18 | public string GLibErrorDomain;
19 |
20 | [XmlAttribute ("get-type", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
21 | public string GLibGetType;
22 |
23 | [XmlAttribute ("type-name", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
24 | public string GLibTypeName;
25 |
26 | [XmlElement ("doc")]
27 | public Documentation Doc { get; set; }
28 |
29 | [XmlElement ("member")]
30 | public List Members;
31 |
32 | [XmlElement ("function")]
33 | public List Function;
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Field.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Field
6 | {
7 | [XmlAttribute ("bits")]
8 | public int Bits;
9 |
10 | [XmlAttribute ("introspectable")]
11 | public bool Introspectable;
12 |
13 | [XmlAttribute ("name")]
14 | public string Name { get; set; }
15 |
16 | [XmlAttribute ("private")]
17 | public bool Private;
18 |
19 | [XmlAttribute ("readable")]
20 | public bool Readable;
21 |
22 | [XmlAttribute ("writable")]
23 | public bool Writable;
24 |
25 | [XmlElement ("doc")]
26 | public Documentation Doc { get; set; }
27 |
28 | [XmlElement ("type")]
29 | public Type Type { get; set; }
30 |
31 | [XmlElement ("callback")]
32 | public Callback Callback { get; set; }
33 |
34 | [XmlElement("array")]
35 | public Array Array { get; set; }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Gir/Model/Function.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Function
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("introspectable")]
15 | public bool Introspectable;
16 |
17 | [XmlAttribute ("moved-to")]
18 | public string MovedTo;
19 |
20 | [XmlAttribute ("name")]
21 | public string Name { get; set; }
22 |
23 | [XmlAttribute ("shadowed-by")]
24 | public string ShadowedBy;
25 |
26 | [XmlAttribute ("shadows")]
27 | public string Shadows;
28 |
29 | [XmlAttribute ("throws")]
30 | public bool Throws;
31 |
32 | [XmlAttribute ("version")]
33 | public string Version;
34 |
35 | [XmlAttribute ("identifier", Namespace = "http://www.gtk.org/introspection/c/1.0")]
36 | public string CIdentifier { get; set; }
37 |
38 | [XmlElement ("doc")]
39 | public Documentation Doc { get; set; }
40 |
41 | [XmlElement ("return-value")]
42 | public ReturnValue ReturnValue { get; set; }
43 |
44 | [XmlArray ("parameters")]
45 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
46 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
47 | public List Parameters { get; set; }
48 | }
49 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Implements.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Implements
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Gir/Model/Include.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Include
7 | {
8 | [XmlAttribute ("name")]
9 | public string Name { get; set; }
10 |
11 | [XmlAttribute ("version")]
12 | public string Version { get; set; }
13 |
14 | public string GirName => $"{Name}-{Version}.gir";
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Gir/Model/InstanceParameter.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Gir
3 | {
4 | public partial class InstanceParameter : Parameter
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Gir/Model/Interface.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Interface
7 | {
8 | [XmlAttribute ("name")]
9 | public string Name { get; set; }
10 |
11 | [XmlAttribute ("version")]
12 | public string Version;
13 |
14 | [XmlAttribute ("symbol-prefix", Namespace = "http://www.gtk.org/introspection/c/1.0")]
15 | public string CSymbolPrefix;
16 |
17 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
18 | public string CType { get; set; }
19 |
20 | [XmlAttribute ("get-type", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
21 | public string GLibGetType;
22 |
23 | [XmlAttribute ("type-name", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
24 | public string GLibTypeName;
25 |
26 | [XmlAttribute ("type-struct", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
27 | public string GLibTypeStruct;
28 |
29 | [XmlElement ("doc")]
30 | public Documentation Doc { get; set; }
31 |
32 | [XmlElement ("prerequisite")]
33 | public List Prerequisites;
34 |
35 | [XmlElement ("property")]
36 | public List Properties;
37 |
38 | [XmlElement ("method")]
39 | public List Methods;
40 |
41 | [XmlElement ("virtual-method")]
42 | public List VirtualMethods;
43 |
44 | [XmlElement ("function")]
45 | public List Functions;
46 |
47 | [XmlElement ("signal", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
48 | public List Signals;
49 |
50 | }
51 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Member.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Member
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name { get; set; }
9 |
10 | [XmlAttribute ("value")]
11 | public string Value;
12 |
13 | [XmlAttribute ("identifier", Namespace = "http://www.gtk.org/introspection/c/1.0")]
14 | public string CIdentifier;
15 |
16 | [XmlAttribute ("nick", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
17 | public string GLibNick;
18 |
19 | [XmlElement ("doc")]
20 | public Documentation Doc { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Method.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Method
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("introspectable")]
15 | public bool Introspectable;
16 |
17 | [XmlAttribute ("moved-to")]
18 | public string MovedTo;
19 |
20 | [XmlAttribute ("name")]
21 | public string Name { get; set; }
22 |
23 | [XmlAttribute ("shadowed-by")]
24 | public string ShadowedBy;
25 |
26 | [XmlAttribute ("shadows")]
27 | public string Shadows;
28 |
29 | [XmlAttribute ("throws")]
30 | public bool Throws;
31 |
32 | [XmlAttribute ("version")]
33 | public string Version;
34 |
35 | [XmlAttribute ("identifier", Namespace = "http://www.gtk.org/introspection/c/1.0")]
36 | public string CIdentifier { get; set; }
37 |
38 | [XmlElement ("doc")]
39 | public Documentation Doc { get; set; }
40 |
41 | [XmlElement("doc-deprecated")]
42 | public Documentation DocDeprecated { get; set; }
43 |
44 | [XmlElement("return-value")]
45 | public ReturnValue ReturnValue { get; set; }
46 |
47 | [XmlArray ("parameters")]
48 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
49 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
50 | public List Parameters { get; set; }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Namespace.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml;
3 | using System.Xml.Serialization;
4 |
5 | namespace Gir
6 | {
7 | public partial class Namespace
8 | {
9 | [XmlAttribute ("name")]
10 | public string Name { get; set; }
11 |
12 | [XmlAttribute ("version")]
13 | public string Version { get; set; }
14 |
15 | [XmlAttribute ("shared-library")]
16 | public string SharedLibrary { get; set; }
17 |
18 | [XmlAttribute ("identifier-prefix", Namespace = "http://www.gtk.org/introspection/c/1.0")]
19 | public string IdentifierPrefix { get; set; }
20 |
21 | [XmlAttribute ("symbol-prefixes", Namespace = "http://www.gtk.org/introspection/c/1.0")]
22 | public string SymbolPrefixes { get; set; }
23 |
24 | [XmlElement ("alias")]
25 | public List Aliases { get; set; }
26 |
27 | [XmlElement ("record")]
28 | public List Records { get; set; }
29 |
30 | [XmlElement ("class")]
31 | public List Classes { get; set; }
32 |
33 | [XmlElement ("constant")]
34 | public List Constants { get; set; }
35 |
36 | [XmlElement ("interface")]
37 | public List Interfaces { get; set; }
38 |
39 | [XmlElement ("callback")]
40 | public List Callbacks { get; set; }
41 |
42 | [XmlElement ("function")]
43 | public List Functions { get; set; }
44 |
45 | [XmlElement ("union")]
46 | public List Unions { get; set; }
47 |
48 | [XmlElement ("enumeration")]
49 | public List Enumerations { get; set; }
50 |
51 | [XmlElement ("bitfield")]
52 | public List Bitfields { get; set; }
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/src/Gir/Model/Package.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Package
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Parameter.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | [XmlInclude (typeof (InstanceParameter))]
6 | public partial class Parameter : ITypeOrArray
7 | {
8 | [XmlAttribute ("allow-none")]
9 | public bool AllowNone;
10 |
11 | [XmlAttribute ("caller-allocates")]
12 | public bool CallerAllocates;
13 |
14 | [XmlAttribute ("closure")]
15 | public int Closure;
16 |
17 | [XmlAttribute ("destroy")]
18 | public int Destroy;
19 |
20 | [XmlAttribute ("direction")]
21 | public Direction Direction;
22 |
23 | [XmlAttribute ("name")]
24 | public string Name;
25 |
26 | [XmlAttribute ("nullable")]
27 | public bool Nullable;
28 |
29 | [XmlAttribute ("optional")]
30 | public bool Optional;
31 |
32 | [XmlAttribute ("skip")]
33 | public bool Skip;
34 |
35 | [XmlAttribute ("transfer-ownership")]
36 | public TransferOwnership TransferOwnership;
37 |
38 | [XmlElement ("doc")]
39 | public Documentation Doc { get; set; }
40 |
41 | [XmlElement ("type")]
42 | public Type Type { get; set; }
43 |
44 | [XmlElement ("array")]
45 | public Array Array { get; set; }
46 |
47 | [XmlElement ("varargs")]
48 | public Varargs Varargs { get; set; }
49 |
50 | [XmlElement ("callback")]
51 | public Callback Callback { get; set; }
52 |
53 | public bool IsPointer => Type.CType.EndsWith ("*", System.StringComparison.Ordinal);
54 |
55 | public bool IsArray => Type.Array != null;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Gir/Model/Prerequisite.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Prerequisite
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Property.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Property
6 | {
7 | [XmlAttribute ("construct")]
8 | public bool Construct;
9 |
10 | [XmlAttribute ("construct-only")]
11 | public bool ConstructOnly;
12 |
13 | [XmlAttribute ("deprecated")]
14 | public string Deprecated;
15 |
16 | [XmlAttribute ("deprecated-version")]
17 | public string DeprecatedVersion;
18 |
19 | [XmlAttribute ("introspectable")]
20 | public bool Introspectable;
21 |
22 | [XmlAttribute ("name")]
23 | public string Name { get; set; }
24 |
25 | [XmlAttribute ("readable")]
26 | public bool Readable;
27 |
28 | [XmlAttribute ("transfer-ownership")]
29 | public TransferOwnership TransferOwnership;
30 |
31 | [XmlAttribute ("version")]
32 | public string Version;
33 |
34 | [XmlAttribute ("writable")]
35 | public bool Writable;
36 |
37 | [XmlElement ("doc")]
38 | public Documentation Doc { get; set; }
39 |
40 | [XmlElement ("type")]
41 | public Type Type;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Gir/Model/Record.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Record
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("disguised")]
15 | public bool Disguised;
16 |
17 | [XmlAttribute ("foreign")]
18 | public bool Foreign;
19 |
20 | [XmlAttribute ("introspectable")]
21 | public bool Introspectable;
22 |
23 | [XmlAttribute ("name")]
24 | public string Name { get; set; }
25 |
26 | [XmlAttribute ("version")]
27 | public string Version;
28 |
29 | [XmlAttribute ("symbol-prefix", Namespace = "http://www.gtk.org/introspection/c/1.0")]
30 | public string CSymbolPrefix;
31 |
32 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
33 | public string CType { get; set; }
34 |
35 | [XmlAttribute ("get-type", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
36 | public string GLibGetType;
37 |
38 | [XmlAttribute ("is-gtype-struct-for", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
39 | public string GLibIsGTypeStructFor;
40 |
41 | [XmlAttribute ("type-name", Namespace = "http://www.gtk.org/introspection/glib/1.0")]
42 | public string GLibTypeName;
43 |
44 | [XmlElement ("doc")]
45 | public Documentation Doc { get; set; }
46 |
47 | [XmlElement ("field")]
48 | public List Fields;
49 |
50 | [XmlElement ("union")]
51 | public List Unions;
52 |
53 | [XmlElement ("constructor")]
54 | public List Constructors;
55 |
56 | [XmlElement ("method")]
57 | public List Methods;
58 |
59 | [XmlElement ("function")]
60 | public List Function;
61 | }
62 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Repository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml.Serialization;
4 |
5 | namespace Gir
6 | {
7 | [XmlRoot ("repository", Namespace = "http://www.gtk.org/introspection/core/1.0")]
8 | public partial class Repository
9 | {
10 | [XmlAttribute ("version")]
11 | public string Version { get; set; }
12 |
13 | [XmlElement ("include")]
14 | public List Includes { get; set; }
15 |
16 | [XmlElement ("package")]
17 | public Package Package { get; set; }
18 |
19 | [XmlElement ("include", Namespace = "http://www.gtk.org/introspection/c/1.0")]
20 | public CInclude CInclude { get; set; }
21 |
22 | [XmlElement ("namespace")]
23 | public Namespace Namespace { get; set; }
24 |
25 | public string GirName => $"{Namespace.Name}-{Namespace.Version}.gir";
26 |
27 | public override string ToString ()
28 | {
29 | return $"{Package.Name}";
30 | }
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/Gir/Model/ReturnValue.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class ReturnValue : IDocumented, ITypeOrArray
6 | {
7 | [XmlAttribute ("nullable")]
8 | public bool Nullable;
9 |
10 | [XmlAttribute ("transfer-ownership")]
11 | public TransferOwnership TransferOwnership;
12 |
13 | [XmlElement ("doc")]
14 | public Documentation Doc { get; set; }
15 |
16 | [XmlElement ("type")]
17 | public Type Type { get; set; }
18 |
19 | [XmlElement ("array")]
20 | public Array Array { get; set; }
21 |
22 | [XmlElement ("varargs")]
23 | public Varargs Varargs { get; set; }
24 |
25 | [XmlElement ("callback")]
26 | public Callback Callback { get; set; }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Gir/Model/Scope.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public enum Scope
6 | {
7 | [XmlEnum ("call")]
8 | Call,
9 | [XmlEnum ("async")]
10 | Async,
11 | [XmlEnum ("notified")]
12 | Notified
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/src/Gir/Model/Signal.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Signal
7 | {
8 | [XmlAttribute ("action")]
9 | public string Action;
10 |
11 | [XmlAttribute ("deprecated")]
12 | public string Deprecated;
13 |
14 | [XmlAttribute ("deprecated-version")]
15 | public string DeprecatedVersion;
16 |
17 | [XmlAttribute ("detailed")]
18 | public bool Detailed;
19 |
20 | [XmlAttribute ("introspectable")]
21 | public bool Introspectable;
22 |
23 | [XmlAttribute ("name")]
24 | public string Name { get; set; }
25 |
26 | [XmlAttribute ("no-hooks")]
27 | public bool NoHooks;
28 |
29 | [XmlAttribute ("no-recurse")]
30 | public bool NoRecurse;
31 |
32 | [XmlAttribute ("version")]
33 | public string Version;
34 |
35 | [XmlAttribute ("when")]
36 | public string When;
37 |
38 | [XmlElement ("doc", Namespace = "http://www.gtk.org/introspection/core/1.0")]
39 | public Documentation Doc { get; set; }
40 |
41 | [XmlElement ("return-value", Namespace = "http://www.gtk.org/introspection/core/1.0")]
42 | public ReturnValue ReturnValue { get; set; }
43 |
44 | [XmlArray ("parameters")]
45 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
46 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
47 | public List Parameters { get; set; }
48 | }
49 | }
--------------------------------------------------------------------------------
/src/Gir/Model/TransferOwnership.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public enum TransferOwnership
6 | {
7 | [XmlEnum ("full")]
8 | Full,
9 | [XmlEnum ("none")]
10 | None,
11 | [XmlEnum ("container")]
12 | Container,
13 | [XmlEnum ("floating")]
14 | Floating
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Type.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Gir
4 | {
5 | public partial class Type
6 | {
7 | [XmlAttribute ("name")]
8 | public string Name;
9 |
10 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
11 | public string CType;
12 |
13 | [XmlElement ("array")]
14 | public Array Array;
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Union.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class Union
7 | {
8 | [XmlAttribute ("name")]
9 | public string Name;
10 |
11 | [XmlAttribute ("type", Namespace = "http://www.gtk.org/introspection/c/1.0")]
12 | public string CType { get; set; }
13 |
14 | [XmlElement ("doc")]
15 | public Documentation Doc { get; set; }
16 |
17 | [XmlElement ("field")]
18 | public List Fields;
19 |
20 | [XmlElement ("method")]
21 | public List Methods;
22 |
23 | [XmlElement ("record")]
24 | public List Records;
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Gir/Model/Varargs.cs:
--------------------------------------------------------------------------------
1 | namespace Gir
2 | {
3 | public partial class Varargs
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/src/Gir/Model/VirtualMethod.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Serialization;
3 |
4 | namespace Gir
5 | {
6 | public partial class VirtualMethod
7 | {
8 | [XmlAttribute ("deprecated")]
9 | public string Deprecated;
10 |
11 | [XmlAttribute ("deprecated-version")]
12 | public string DeprecatedVersion;
13 |
14 | [XmlAttribute ("introspectable")]
15 | public bool Introspectable;
16 |
17 | [XmlAttribute ("invoker")]
18 | public string Invoker;
19 |
20 | [XmlAttribute ("name")]
21 | public string Name;
22 |
23 | [XmlAttribute ("throws")]
24 | public bool Throws;
25 |
26 | [XmlAttribute ("version")]
27 | public string Version;
28 |
29 | [XmlElement ("doc")]
30 | public Documentation Doc { get; set; }
31 |
32 | [XmlElement ("return-value")]
33 | public ReturnValue ReturnValue { get; set; }
34 |
35 | [XmlArray ("parameters")]
36 | [XmlArrayItem ("parameter", Type = typeof (Parameter))]
37 | [XmlArrayItem ("instance-parameter", Type = typeof (InstanceParameter))]
38 | public List Parameters { get; set; }
39 |
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Gir/Parser.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Linq;
4 |
5 | namespace Gir
6 | {
7 | public static class Parser
8 | {
9 |
10 | public static IEnumerable Parse (string fileName, string includeDir, out Repository mainRepository)
11 | {
12 | using (var fs = File.OpenRead (fileName)) {
13 | return Parse (fs, includeDir, out mainRepository);
14 | }
15 | }
16 |
17 | public static IEnumerable Parse (Stream s, string includeDir, out Repository mainRepository)
18 | {
19 | var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository));
20 | mainRepository = (Repository)serializer.Deserialize (s);
21 |
22 | var repositories = ParseRecursive (mainRepository, includeDir, new Dictionary ()).ToList ();
23 | // The first repository is the main repository
24 | return repositories;
25 | }
26 |
27 | public static IEnumerable ParseRecursive (Repository repository, string includeDir, Dictionary resolvedRepositories)
28 | {
29 | if (!resolvedRepositories.ContainsKey (repository.GirName)) {
30 | resolvedRepositories [repository.GirName] = repository;
31 |
32 | yield return repository;
33 |
34 | foreach (var include in repository.Includes) {
35 | using (var fs = File.OpenRead (Path.Combine (includeDir, include.GirName))) {
36 | var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository));
37 | var repo = (Repository)serializer.Deserialize (fs);
38 |
39 |
40 | foreach (var incRepo in ParseRecursive (repo, includeDir, resolvedRepositories)) {
41 | yield return incRepo;
42 | }
43 | }
44 | }
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Gir/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace Gir
6 | {
7 | class MainClass
8 | {
9 | class OptionSet
10 | {
11 | public string CustomGeneratedAssemblyName;
12 | public string OutputDirectory = "generated";
13 |
14 | public string GeneratedAssemblyName => CustomGeneratedAssemblyName ?? GenerationRepository.Namespace.Name;
15 | public string IncludeSearchDirectory = GetDefaultSearchDirectory ();
16 |
17 | public Repository GenerationRepository;
18 | public IEnumerable AllRepositories;
19 |
20 | public string custom_dir = "";
21 | public string glue_filename = "";
22 | public string glue_includes = "";
23 | public string gluelib_name = "";
24 |
25 | static string GetDefaultSearchDirectory ()
26 | {
27 | // if (IsLinux)
28 | return "/usr/share/gir-1.0/";
29 | }
30 | }
31 |
32 | public static int Main (string[] args)
33 | {
34 | if (args.Length < 1) {
35 | Console.WriteLine ("Usage: gir.exe ");
36 | return 0;
37 | }
38 |
39 | var opt = new OptionSet ();
40 | foreach (string arg in args)
41 | ParseArg (opt, arg);
42 |
43 | opt.AllRepositories = Parser.Parse (args [0], opt.IncludeSearchDirectory, out opt.GenerationRepository);
44 |
45 | //GenerationInfo gen_info = null;
46 | //if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "")
47 | //gen_info = new GenerationInfo(dir, custom_dir, assembly_name, glue_filename, glue_includes, gluelib_name);
48 |
49 | var genOpts = new GenerationOptions (opt.OutputDirectory, opt.AllRepositories, opt.GenerationRepository);
50 |
51 | if (!Directory.Exists (opt.OutputDirectory))
52 | Directory.CreateDirectory (opt.OutputDirectory);
53 |
54 | foreach (IGeneratable gen in genOpts.AllGeneratables) {
55 | gen.Generate (genOpts);
56 | }
57 |
58 | genOpts.Statistics.ReportStatistics ();
59 | return 0;
60 | }
61 |
62 | const string customOutputDir = "--outdir=";
63 | const string customAssemblyNameArg = "--assembly-name=";
64 | const string customIncludeDirArg = "--include-dir=";
65 |
66 | static void ParseArg (OptionSet opt, string arg)
67 | {
68 | if (arg.StartsWith (customOutputDir)) {
69 | opt.OutputDirectory = arg.Substring (customOutputDir.Length);
70 | return;
71 | }
72 | if (arg.StartsWith ("--customdir=")) {
73 | opt.custom_dir = arg.Substring (12);
74 | return;
75 | }
76 | if (arg.StartsWith (customAssemblyNameArg)) {
77 | opt.CustomGeneratedAssemblyName = arg.Substring (customAssemblyNameArg.Length);
78 | return;
79 | }
80 | if (arg.StartsWith ("--glue-filename=")) {
81 | opt.glue_filename = arg.Substring (16);
82 | return;
83 | }
84 | if (arg.StartsWith ("--glue-includes=")) {
85 | opt.glue_includes = arg.Substring (16);
86 | return;
87 | }
88 | if (arg.StartsWith ("--gluelib-name=")) {
89 | opt.gluelib_name = arg.Substring (15);
90 | return;
91 | }
92 | if (arg.StartsWith (customIncludeDirArg)) {
93 | opt.IncludeSearchDirectory = arg.Substring (customIncludeDirArg.Length);
94 | return;
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/Gir/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | // Information about this assembly is defined by the following attributes.
5 | // Change them to the values specific to your project.
6 |
7 | [assembly: AssemblyTitle("Gir")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("Microsoft")]
11 | [assembly: AssemblyProduct("")]
12 | [assembly: AssemblyCopyright("")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
19 |
20 | [assembly: AssemblyVersion("1.0.*")]
21 |
22 | // The following attributes are used to specify the signing key for the assembly,
23 | // if desired. See the Mono documentation for more information about signing.
24 |
25 | //[assembly: AssemblyDelaySign(false)]
26 | //[assembly: AssemblyKeyFile("")]
27 |
--------------------------------------------------------------------------------
/src/Gir/Schema/c.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Gir/Schema/glib.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/Gir/Schema/xml.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Gir/Statistics.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace Gir
6 | {
7 | public class Statistics
8 | {
9 | readonly Dictionary RegisteredCount = new Dictionary ();
10 |
11 | // Bucket errors by the same kind to make for easy reviewing of error output
12 | readonly Dictionary> RegisteredErrors = new Dictionary> ();
13 |
14 | public void ReportStatistics ()
15 | {
16 | foreach (var line in GetStatistics ()) {
17 | Console.WriteLine (line);
18 | }
19 |
20 | foreach (var line in GetErrorsContent ()) {
21 | Console.Error.WriteLine (line);
22 | }
23 | }
24 |
25 | public IEnumerable GetStatistics ()
26 | {
27 | foreach (var kvp in RegisteredCount) {
28 | yield return string.Format ("Registered {0} {1}s", kvp.Value.ToString (), kvp.Key);
29 | }
30 | }
31 |
32 | public IEnumerable GetErrorsContent ()
33 | {
34 | foreach (var kvp in RegisteredErrors) {
35 | yield return kvp.Key.ToString ();
36 |
37 | foreach (var error in kvp.Value) {
38 | yield return string.Format ("\t{0}", error.Message);
39 | }
40 | }
41 | }
42 |
43 | public IEnumerable Errors => RegisteredErrors.SelectMany (x => x.Value);
44 |
45 | public void RegisterType (ISymbol symbol)
46 | {
47 | var type = symbol.GetType ();
48 | RegisteredCount.TryGetValue (type, out int count);
49 | RegisteredCount [type] = ++count;
50 | }
51 |
52 | public void RegisterError (Error error)
53 | {
54 | var type = error.GetType ();
55 | if (!RegisteredErrors.TryGetValue (type, out var list)) {
56 | RegisteredErrors [type] = list = new List ();
57 | }
58 | list.Add (error);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/Gir/Utils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 |
7 | namespace Gir
8 | {
9 | public static class Utils
10 | {
11 | // Perf - maybe cache this?
12 | public static string ToCSharp (this string cname)
13 | {
14 | // Capitalize the first letter, and parse for underscores, capitalizing the letters after them
15 | var sb = new StringBuilder (cname.Length);
16 |
17 | bool isUpper = true;
18 | foreach (var c in cname) {
19 | if (c == '_' || c == '-') {
20 | isUpper = true;
21 | continue;
22 | }
23 |
24 | sb.Append (isUpper ? char.ToUpper (c) : c);
25 | isUpper = false;
26 | }
27 |
28 | return sb.ToString ();
29 | }
30 |
31 | internal static IEnumerable GetAllCollectionMembers (object container)
32 | {
33 | // This doesn't yield things like:
34 | foreach (var collection in GetCollectionsOf (container)) {
35 | foreach (var item in collection)
36 | yield return (T)item;
37 | }
38 | }
39 |
40 | static IEnumerable GetCollectionsOf (object obj)
41 | {
42 | var type = obj.GetType ();
43 |
44 | foreach (var field in type.GetFields ().Where (x => IsCollectionOf (x.FieldType))) {
45 | yield return (ICollection)field.GetValue (obj);
46 | }
47 |
48 | foreach (var prop in type.GetProperties ().Where (x => IsCollectionOf (x.PropertyType))) {
49 | yield return (ICollection)prop.GetValue (obj);
50 | }
51 | }
52 |
53 | static bool IsCollectionOf (System.Type t)
54 | {
55 | foreach (var @interface in t.GetInterfaces ()) {
56 | if (!@interface.IsGenericType || !@interface.GetGenericTypeDefinition ().IsAssignableFrom (typeof (ICollection<>)))
57 | continue;
58 |
59 | var args = @interface.GetGenericArguments ();
60 | bool isOfT = typeof (T).IsAssignableFrom (args [0]);
61 | if (isOfT)
62 | return true;
63 | }
64 |
65 | return false;
66 | }
67 |
68 | internal static IEnumerable GetTypesImplementing ()
69 | {
70 | var assembly = Assembly.GetExecutingAssembly ();
71 |
72 | var implementors = assembly
73 | .DefinedTypes
74 | // Filter out all the types implementing the interface
75 | .Where (type => typeof (T).IsAssignableFrom (type));
76 | return implementors;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------