annotate InteropCodeGen/gendotnet.cs @ 0:e1ec7bf71313

Initial commit
author Ivo Smits
date Wed, 04 May 2011 00:59:43 +0200
parents
children f1deea9c97a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
1 //+reference System.dll
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
2 //+reference System.Xml.dll
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
3 using System;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
4 using System.Xml.XPath;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
5 using System.IO;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
6 using System.Collections.Generic;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
7 class Program {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
8 enum ParameterType {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
9 In,
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
10 Out,
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
11 Reference,
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
12 Return,
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
13 Param,
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
14 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
15 class TypeInfo {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
16 public String Name { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
17 public String[] Attributes { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
18 //public Boolean InputOnly { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
19 public String Members { get; set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
20
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
21 public TypeInfo(String name, params String[] attributes) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
22 this.Name = name;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
23 this.Attributes = attributes;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
24 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
25 /*public TypeInfo(String name, bool inputOnly, params String[] attributes)
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
26 : this(name, attributes) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
27 this.InputOnly = inputOnly;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
28 }*/
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
29 /*public static TypeInfo CreateInterfaceWithMembers(String name, String members) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
30 TypeInfo ret = new TypeInfo(name, "MarshalAs(UnmanagedType.Interface)");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
31 ret.Members = members;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
32 return ret;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
33 }*/
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
34 //Todo: if attribute mod="string"/"ptr" ...
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
35 public void WriteDeclaration(TextWriter o, ParameterType vartype) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
36 WriteAttributes(o, vartype);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
37 o.Write(Name);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
38 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
39 public void WriteAttributes(TextWriter o, ParameterType vartype) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
40 //if (InputOnly && vartype != ParameterType.In) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
41 foreach (String attribute in Attributes) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
42 o.Write("[");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
43 if (vartype == ParameterType.Return) o.Write("return: ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
44 else if (vartype == ParameterType.Param) o.Write("param: ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
45 o.Write(attribute);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
46 o.Write("] ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
47 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
48 if (vartype == ParameterType.Out) o.Write("out ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
49 else if (vartype == ParameterType.Reference) o.Write("ref ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
50 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
51 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
52 static Dictionary<String, TypeInfo> Types = new Dictionary<string, TypeInfo>();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
53 static void InitTypes() {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
54 Types.Add("short", new TypeInfo("Int16"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
55 Types.Add("unsigned short", new TypeInfo("UInt16"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
56 Types.Add("unsigned long", new TypeInfo("UInt32"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
57 Types.Add("long long", new TypeInfo("Int64"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
58 Types.Add("long", new TypeInfo("Int32"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
59 Types.Add("octet", new TypeInfo("Byte"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
60 Types.Add("unsigned long long", new TypeInfo("UInt32"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
61 //Types.Add("boolean", new TypeInfo("Boolean", "MarshalAs(UnmanagedType.Bool)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
62 Types.Add("boolean", new TypeInfo("Int32"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
63 Types.Add("wstring", new TypeInfo("String", "MarshalAs(UnmanagedType.LPWStr)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
64 //Types.Add("uuid", new TypeInfo("Guid", true, "MarshalAs(UnmanagedType.LPStruct)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
65 Types.Add("uuid", new TypeInfo("Guid", "MarshalAs(UnmanagedType.LPStruct)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
66
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
67 Types.Add("IMachine", new TypeInfo("IMachine", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
68 Types.Add("ISession", new TypeInfo("ISession", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
69 Types.Add("IVirtualBox", new TypeInfo("IVirtualBox", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
70 Types.Add("IHost", new TypeInfo("IHost", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
71 Types.Add("IConsole", new TypeInfo("IConsole", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
72 Types.Add("ISystemProperties", new TypeInfo("ISystemProperties", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
73 Types.Add("IProgress", new TypeInfo("IProgress", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
74 Types.Add("IDisplay", new TypeInfo("IDisplay", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
75 Types.Add("IMouse", new TypeInfo("IMouse", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
76 Types.Add("IKeyboard", new TypeInfo("IKeyboard", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
77 Types.Add("IFramebuffer", new TypeInfo("IFramebuffer", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
78 Types.Add("IFramebufferOverlay", new TypeInfo("IFramebufferOverlay", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
79 Types.Add("IMachineDebugger", new TypeInfo("IMachineDebugger", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
80 Types.Add("IVirtualBoxErrorInfo", new TypeInfo("IVirtualBoxErrorInfo", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
81 Types.Add("IEventSource", new TypeInfo("IEventSource", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
82 Types.Add("IEventListener", new TypeInfo("IEventListener", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
83 Types.Add("IEventContext", new TypeInfo("IEventContext", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
84 Types.Add("IConsoleCallback", new TypeInfo("IConsoleCallback", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
85 Types.Add("IEvent", new TypeInfo("IEvent", "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
86
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
87 Types.Add("LockType", new TypeInfo("LockType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
88 Types.Add("MediumVariant", new TypeInfo("MediumVariant"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
89 Types.Add("AccessMode", new TypeInfo("AccessMode"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
90 Types.Add("NATProtocol", new TypeInfo("NATProtocol"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
91 Types.Add("FirmwareType", new TypeInfo("FirmwareType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
92 Types.Add("StorageControllerType", new TypeInfo("StorageControllerType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
93 Types.Add("StorageBus", new TypeInfo("StorageBus"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
94 Types.Add("SessionType", new TypeInfo("SessionType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
95 Types.Add("SessionState", new TypeInfo("SessionState"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
96 Types.Add("USBDeviceState", new TypeInfo("USBDeviceState"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
97 Types.Add("USBDeviceFilterAction", new TypeInfo("USBDeviceFilterAction"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
98 Types.Add("AudioControllerType", new TypeInfo("AudioControllerType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
99 Types.Add("AudioDriverType", new TypeInfo("AudioDriverType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
100 Types.Add("VRDPAuthType", new TypeInfo("VRDPAuthType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
101 Types.Add("MachineState", new TypeInfo("MachineState"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
102 Types.Add("NetworkAdapterType", new TypeInfo("NetworkAdapterType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
103 Types.Add("NetworkAttachmentType", new TypeInfo("NetworkAttachmentType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
104 Types.Add("PortMode", new TypeInfo("PortMode"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
105 Types.Add("DeviceType", new TypeInfo("DeviceType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
106 Types.Add("MediumState", new TypeInfo("MediumState"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
107 Types.Add("MediumType", new TypeInfo("MediumType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
108 Types.Add("HostNetworkInterfaceType", new TypeInfo("HostNetworkInterfaceType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
109 Types.Add("DeviceActivity", new TypeInfo("DeviceActivity"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
110 Types.Add("HostNetworkInterfaceMediumType", new TypeInfo("HostNetworkInterfaceMediumType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
111 Types.Add("HostNetworkInterfaceStatus", new TypeInfo("HostNetworkInterfaceStatus"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
112 Types.Add("ProcessorFeature", new TypeInfo("ProcessorFeature"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
113 Types.Add("VFSType", new TypeInfo("VFSType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
114 Types.Add("BIOSBootMenuMode", new TypeInfo("BIOSBootMenuMode"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
115 Types.Add("VirtualSystemDescriptionType", new TypeInfo("VirtualSystemDescriptionType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
116 Types.Add("VirtualSystemDescriptionValueType", new TypeInfo("VirtualSystemDescriptionValueType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
117 Types.Add("KeyboardHidType", new TypeInfo("KeyboardHidType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
118 Types.Add("ClipboardMode", new TypeInfo("ClipboardMode"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
119 Types.Add("PointingHidType", new TypeInfo("PointingHidType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
120 Types.Add("CPUPropertyType", new TypeInfo("CPUPropertyType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
121 Types.Add("HWVirtExPropertyType", new TypeInfo("HWVirtExPropertyType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
122 Types.Add("Scope", new TypeInfo("Scope"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
123 Types.Add("ChipsetType", new TypeInfo("ChipsetType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
124 Types.Add("FaultToleranceState", new TypeInfo("FaultToleranceState"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
125 Types.Add("BandwidthGroupType", new TypeInfo("BandwidthGroupType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
126 Types.Add("VBoxEventType", new TypeInfo("VBoxEventType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
127 Types.Add("GuestMonitorChangedEventType", new TypeInfo("GuestMonitorChangedEventType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
128 Types.Add("AuthType", new TypeInfo("AuthType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
129 Types.Add("NetworkAdapterPromiscModePolicy", new TypeInfo("NetworkAdapterPromiscModePolicy"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
130 Types.Add("ExecuteProcessStatus", new TypeInfo("ExecuteProcessStatus"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
131 Types.Add("AdditionsRunLevelType", new TypeInfo("AdditionsRunLevelType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
132 Types.Add("AdditionsFacilityStatus", new TypeInfo("AdditionsFacilityStatus"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
133 Types.Add("AdditionsFacilityType", new TypeInfo("AdditionsFacilityType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
134 Types.Add("AdditionsFacilityClass", new TypeInfo("AdditionsFacilityClass"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
135 Types.Add("CleanupMode", new TypeInfo("CleanupMode"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
136 Types.Add("DataType", new TypeInfo("DataType"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
137
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
138 Types.Add("IBandwidthControl", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
139 Types.Add("IVRDEServerInfo", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
140 Types.Add("IAdditionsFacility", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
141 Types.Add("IExtPackPlugIn", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
142 Types.Add("IExtPackFile", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
143 Types.Add("IExtPack", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
144 Types.Add("IBIOSSettings", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
145 Types.Add("IVFSExplorer", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
146 Types.Add("IUSBController", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
147 Types.Add("IStorageController", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
148 Types.Add("IVRDPServer", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
149 Types.Add("ISnapshot", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
150 Types.Add("INATEngine", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
151 Types.Add("IUSBDeviceFilter", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
152 Types.Add("IMediumAttachment", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
153 Types.Add("IUSBDevice", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
154 Types.Add("IParallelPort", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
155 Types.Add("ISerialPort", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
156 Types.Add("INetworkAdapter", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
157 Types.Add("IMedium", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
158 Types.Add("IGuestOSType", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
159 Types.Add("ISharedFolder", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
160 Types.Add("IPerformanceCollector", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
161 Types.Add("IDHCPServer", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
162 Types.Add("IAppliance", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
163 Types.Add("IVirtualBoxCallback", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
164 Types.Add("IPerformanceMetric", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
165 Types.Add("IMediumFormat", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
166 Types.Add("IHostUSBDevice", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
167 Types.Add("IHostNetworkInterface", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
168 Types.Add("IHostUSBDeviceFilter", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
169 Types.Add("IRemoteDisplayInfo", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
170 Types.Add("IGuest", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
171 Types.Add("IVirtualSystemDescription", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
172 Types.Add("IAudioAdapter", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
173 Types.Add("IExtPackManager", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
174 Types.Add("IVRDEServer", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
175 Types.Add("IPciDeviceAttachment", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
176 Types.Add("IBandwidthGroup", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
177
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
178 Types.Add("$unknown", new TypeInfo("IntPtr"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
179 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
180 static void Main(string[] args) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
181 InitTypes();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
182
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
183 XPathDocument doc = new XPathDocument("VirtualBox.xidl");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
184 XPathNavigator nav = doc.CreateNavigator();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
185 nav = nav.SelectSingleNode("/idl/library[@name='VirtualBox']");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
186 TextWriter o = Console.Out;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
187 o.WriteLine("using System;");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
188 o.WriteLine("using System.Runtime.CompilerServices;");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
189 o.WriteLine("using System.Runtime.InteropServices;");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
190 o.WriteLine("namespace VirtualBox {");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
191 foreach (XPathNavigator intf in nav.Select("interface")) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
192 ProcessInterface(intf, o, nav);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
193 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
194 foreach (XPathNavigator intf in nav.Select("enum")) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
195 ProcessEnum(intf, o);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
196 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
197 o.WriteLine("}");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
198 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
199 static void ProcessEnum(XPathNavigator nav, TextWriter o) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
200 String typeName = nav.SelectSingleNode("@name").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
201 if (!Types.ContainsKey(typeName)) Types.Add(typeName, new TypeInfo(typeName));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
202 o.WriteLine("[Guid(\"{0}\")]", nav.SelectSingleNode("@uuid").Value);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
203 o.WriteLine("enum " + typeName + " {");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
204 foreach (XPathNavigator member in nav.SelectChildren(XPathNodeType.Element)) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
205 switch (member.Name) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
206 case "desc":
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
207 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
208 case "const":
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
209 o.WriteLine("\t{0} = {1},", member.SelectSingleNode("@name").Value, member.SelectSingleNode("@value").Value);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
210 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
211 default:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
212 Console.Error.WriteLine("Unknown member type {0}", member.Name);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
213 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
214 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
215 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
216 o.WriteLine("}");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
217 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
218 static void ProcessInterface(XPathNavigator nav, TextWriter o, XPathNavigator parentNav) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
219 String typeName = nav.SelectSingleNode("@name").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
220 if (!Types.ContainsKey(typeName)) Types.Add(typeName, new TypeInfo(typeName, "MarshalAs(UnmanagedType.Interface)"));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
221 o.WriteLine("[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
222 o.WriteLine("[Guid(\"{0}\")]", nav.SelectSingleNode("@uuid").Value);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
223 o.WriteLine("[ComImport()]");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
224 o.Write("interface " + typeName);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
225 o.WriteLine(" {");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
226 ProcessInterfaceMembersAndInherited(nav, o, parentNav);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
227 o.WriteLine("}");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
228 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
229 static void ProcessInterfaceMembersAndInherited(XPathNavigator nav, TextWriter o, XPathNavigator parentNav) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
230 XPathItem item = nav.SelectSingleNode("@extends");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
231 if (item != null && item.Value[0] != '$') {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
232 XPathNavigator inav = parentNav.SelectSingleNode("interface[@name='" + item.Value + "']");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
233 ProcessInterfaceMembersAndInherited(inav, o, parentNav);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
234 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
235 ProcessInterfaceMembers(nav.SelectChildren(XPathNodeType.Element), o);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
236 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
237 static void ProcessInterfaceMembers(XPathNodeIterator members, TextWriter oattribute) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
238 XPathItem item;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
239 StringWriter omethod = new StringWriter();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
240 foreach (XPathNavigator member in members) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
241 switch (member.Name) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
242 case "desc":
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
243 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
244 case "attribute": {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
245 String mName = member.SelectSingleNode("@name").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
246 //String mType = member.SelectSingleNode("@type").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
247 item = member.SelectSingleNode("@readonly");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
248 Boolean mReadOnly = item == null ? false : item.Value == "yes";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
249 //item = member.SelectSingleNode("@mod");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
250 //String mMod = item == null ? null : item.Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
251 mName = mName.Substring(0, 1).ToUpper() + mName.Substring(1);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
252 oattribute.Write("\t");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
253 /*TypeInfo t;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
254 if (mMod == "ptr") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
255 t = new TypeInfo("IntPtr");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
256 } else if (mMod == "string") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
257 t = new TypeInfo("String", "MarshalAs(UnmanagedType.LPWStr)");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
258 } else if (mMod == null) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
259 if (!Types.TryGetValue(mType, out t)) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
260 Console.Error.WriteLine("Type {0} is not supported", mType);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
261 t = new TypeInfo("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
262 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
263 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
264 Console.Error.WriteLine("Type modifier {0} is not supported", mMod);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
265 t = new TypeInfo("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
266 }*/
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
267 TypeInfo t = GetTypeDeclaration(member);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
268 oattribute.Write(t.Name);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
269 oattribute.Write(" ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
270 oattribute.Write(mName);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
271 oattribute.WriteLine(" {");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
272 oattribute.Write("\t\t[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
273 t.WriteAttributes(oattribute, ParameterType.Return);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
274 oattribute.WriteLine("get;");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
275 if (!mReadOnly) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
276 oattribute.Write("\t\t[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
277 t.WriteAttributes(oattribute, ParameterType.Param);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
278 oattribute.WriteLine("set;");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
279 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
280 oattribute.WriteLine("\t}");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
281 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
282 case "method": {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
283 String mName = member.SelectSingleNode("@name").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
284 XPathNodeIterator mParamReturn = member.Select("param[@dir='return']");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
285 omethod.WriteLine("\t[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
286 omethod.Write("\t");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
287 bool mReturn = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
288 if (mParamReturn == null || mParamReturn.Count != 1) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
289 omethod.Write("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
290 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
291 mParamReturn.MoveNext();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
292 mReturn = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
293 TypeInfo t = GetTypeDeclaration(mParamReturn.Current);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
294 /*String mType = mParamReturn.Current.SelectSingleNode("@type").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
295 TypeInfo t;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
296 if (!Types.TryGetValue(mType, out t)) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
297 Console.Error.WriteLine("Type {0} is not supported", mType);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
298 t = new TypeInfo("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
299 mReturn = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
300 }*/
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
301 t.WriteDeclaration(omethod, ParameterType.Return);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
302 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
303 mName = mName.Substring(0, 1).ToUpper() + mName.Substring(1);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
304 omethod.Write(" ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
305 omethod.Write(mName);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
306 omethod.Write("(");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
307 XPathNodeIterator mParams = member.Select("param");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
308 bool first = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
309 if (mParams.MoveNext()) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
310 while (true) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
311 XPathNavigator mParam = mParams.Current;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
312 String pDir = mParam.SelectSingleNode("@dir").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
313 //item = mParam.SelectSingleNode("@safearray");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
314 //Boolean pArray = item == null ? false : item.Value == "yes";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
315 //item = mParam.SelectSingleNode("@mod");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
316 //String pMod = item == null ? null : item.Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
317 if (pDir == "return" && mReturn) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
318 if (mParams.MoveNext()) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
319 continue;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
320 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
321 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
322 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
323 } else if (pDir == "in") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
324 } else if (pDir == "out") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
325 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
326 Console.Error.WriteLine("Unsupported parameter direction {0}", pDir);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
327 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
328 if (first) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
329 first = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
330 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
331 omethod.Write(", ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
332 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
333 ParameterType pt = ParameterType.In;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
334 if (pDir == "out") pt = ParameterType.Out;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
335 TypeInfo t = GetTypeDeclaration(mParam, ref pt);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
336 t.WriteDeclaration(omethod, pt);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
337 /*if (pArray) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
338 omethod.Write("[MarshalAs(UnmanagedType.SafeArray)] ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
339 if (pDir == "out") omethod.Write("out ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
340 else omethod.Write("ref ");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
341 omethod.Write("System.Array");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
342 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
343 String pType = mParam.SelectSingleNode("@type").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
344 TypeInfo t;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
345 if (!Types.TryGetValue(pType, out t)) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
346 Console.Error.WriteLine("Type {0} is not supported", pType);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
347 t = new TypeInfo("IntPtr");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
348 mReturn = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
349 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
350 if (pMod == "ptr") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
351 t.WriteDeclaration(omethod, ParameterType.Reference);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
352 } else if (pDir == "out") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
353 t.WriteDeclaration(omethod, ParameterType.Out);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
354 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
355 t.WriteDeclaration(omethod, ParameterType.In);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
356 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
357 }*/
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
358 omethod.Write(" p");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
359 omethod.Write(mParam.SelectSingleNode("@name").Value);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
360 if (!mParams.MoveNext()) break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
361 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
362 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
363 omethod.WriteLine(");");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
364 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
365 default:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
366 Console.Error.WriteLine("Unknown member type {0}", member.Name);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
367 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
368 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
369 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
370 oattribute.Write((omethod as StringWriter).ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
371 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
372 private static TypeInfo GetTypeDeclaration(XPathNavigator nav) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
373 ParameterType pt = ParameterType.Param;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
374 return GetTypeDeclaration(nav, ref pt);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
375 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
376 private static TypeInfo GetTypeDeclaration(XPathNavigator nav, ref ParameterType paramType) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
377 String mType = nav.SelectSingleNode("@type").Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
378 XPathItem item;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
379 item = nav.SelectSingleNode("@mod");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
380 String mMod = item == null ? null : item.Value;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
381 item = nav.SelectSingleNode("@safearray");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
382 Boolean pArray = item == null ? false : item.Value == "yes";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
383
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
384 TypeInfo t;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
385 if (!Types.TryGetValue(mType, out t)) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
386 Console.Error.WriteLine("Type {0} is not supported", mType);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
387 t = new TypeInfo("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
388 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
389 if (mMod == "ptr") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
390 if (paramType == ParameterType.In) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
391 paramType = ParameterType.Reference;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
392 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
393 t = new TypeInfo("IntPtr");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
394 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
395 } else if (mMod == "string") {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
396 t = new TypeInfo("String", "MarshalAs(UnmanagedType.LPWStr)");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
397 } else if (mMod != null) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
398 Console.Error.WriteLine("Type modifier {0} is not supported", mMod);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
399 t = new TypeInfo("void");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
400 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
401 if (pArray) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
402 t = new TypeInfo("Array", "MarshalAs(UnmanagedType.SafeArray)");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
403 if (paramType == ParameterType.In || paramType == ParameterType.Out) paramType = ParameterType.Reference;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
404 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
405 return t;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
406 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
407 }