static void GenerateTypeStaticCpp (GlobalInfo all) { string header; List<string> headers = new List<string> (); StringBuilder text = new StringBuilder (); Helper.WriteWarningGenerated (text); text.AppendLine ("#include <config.h>"); text.AppendLine (); text.AppendLine ("#include <stdlib.h>"); headers.Add ("factory.h"); headers.Add ("cbinding.h"); foreach (TypeInfo t in all.Children.SortedTypesByKind) { if (t.C_Constructor == string.Empty || t.C_Constructor == null || !t.GenerateCBindingCtor) { //Console.WriteLine ("{0} does not have a C ctor", t.FullName); if (t.GetTotalEventCount () == 0) continue; } if (string.IsNullOrEmpty (t.Header)) { // Console.WriteLine ("{0} does not have a header", t.FullName); continue; } //Console.WriteLine ("{0}'s header is {1}", t.FullName, t.Header); header = Path.GetFileName (t.Header); if (!headers.Contains (header)) headers.Add (header); } // Loop through all the classes and check which headers // are needed for the c constructors text.AppendLine (""); headers.Sort (); foreach (string h in headers) { text.Append ("#include \""); text.Append (h); text.AppendLine ("\""); } text.AppendLine (); text.AppendLine ("namespace Moonlight {"); text.AppendLine (); foreach (TypeInfo t in all.Children.SortedTypesByKind) { if (t.GetEventCount () == 0) continue; foreach (FieldInfo field in t.Events) { text.Append ("const int "); text.Append (t.Name); text.Append ("::"); text.Append (field.EventName); text.Append ("Event = "); text.Append (t.GetEventId (field)); text.AppendLine (";"); } } // Create the arrays of event names for the classes which have events text.AppendLine (""); foreach (TypeInfo t in all.Children.SortedTypesByKind) { if (t.Events.Count > 0) { text.Append ("const char *"); text.Append (t.KindName); text.Append ("_Events [] = { "); foreach (FieldInfo field in t.Events) { text.Append ("\""); text.Append (field.EventName); text.Append ("\", "); } text.AppendLine ("NULL };"); } if (t.Interfaces.Count > 0) { text.Append ("const Type::Kind "); text.Append (t.KindName); text.Append ("_Interfaces[] = { "); for (int i = 0; i < t.Interfaces.Count; i ++) { text.Append ("Type::"); text.Append (t.Interfaces[i].KindName); if (i < t.Interfaces.Count - 1) text.Append (", "); } text.AppendLine (" };"); } } // Create the array of type data text.AppendLine (""); text.AppendLine ("void"); text.AppendLine ("Types::RegisterNativeTypes ()"); text.AppendLine ("{"); text.AppendLine ("\tDeployment *deployment = Deployment::GetCurrent ();"); text.AppendLine ("\ttypes [(int) Type::INVALID] = new Type (deployment, Type::INVALID, Type::INVALID, false, false, false, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL );"); text.AppendLine ("\ttypes [(int) Type::ENUM] = new Type (deployment, Type::ENUM, Type::OBJECT, false, false, false, \"Enum\", 0, 0, NULL, 0, NULL, false, NULL, NULL );"); foreach (TypeInfo type in all.Children.SortedTypesByKind) { MemberInfo member; TypeInfo parent = null; string events = "NULL"; string interfaces = "NULL"; if (!type.Annotations.ContainsKey ("IncludeInKinds")) continue; if (type.Base != null && type.Base.Value != null && all.Children.TryGetValue (type.Base.Value, out member)) parent = (TypeInfo) member; if (type.Events != null && type.Events.Count != 0) events = type.KindName + "_Events"; if (type.Interfaces.Count != 0) interfaces = type.KindName + "_Interfaces"; string parentKind; if (type.KindName == "OBJECT") { parentKind = "INVALID"; } else { if (parent != null) parentKind = parent.KindName; else if (type.IsEnum) parentKind = "ENUM"; else parentKind = "OBJECT"; } text.AppendLine (string.Format (@" types [(int) {0}] = new Type (deployment, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13});", "Type::" + type.KindName, "Type::" + parentKind, type.IsEnum ? "true" : "false", type.IsValueType || type.IsEnum ? "true" : "false", type.IsInterface ? "true" : "false", "\"" + type.Name + "\"", type.GetEventCount (), type.GetTotalEventCount (), events, type.Interfaces.Count, interfaces, type.DefaultCtorVisible || type.IsValueType || type.IsEnum ? "true" : "false", ((type.C_Constructor != null && type.GenerateCBindingCtor && (all.GetDependencyObjects ().Contains (type) || type.Name == "DependencyObject")) ? (type.ConstructorSkipsFactories ? string.Concat ("(create_inst_func *) ", type.C_Constructor) : string.Concat ("(create_inst_func *) MoonUnmanagedFactory::Create", type.Name)) : "NULL"), type.ContentProperty != null ? string.Concat ("\"", type.ContentProperty, "\"") : "NULL" ) ); } text.AppendLine ("\ttypes [(int) Type::LASTTYPE] = new Type (deployment, Type::LASTTYPE, Type::INVALID, false, false, false, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL);"); text.AppendLine ("}"); text.AppendLine (); text.AppendLine ("};"); text.AppendLine (); Helper.WriteAllText ("src/type-generated.cpp", text.ToString ()); }
static void GenerateManagedDOs (GlobalInfo all) { string base_dir = Environment.CurrentDirectory; string class_dir = Path.Combine (base_dir, "class"); string sys_win_dir = Path.Combine (Path.Combine (class_dir, "System.Windows"), "System.Windows"); string filename = Path.Combine (sys_win_dir, "DependencyObject.g.cs"); string previous_namespace = ""; StringBuilder text = new StringBuilder (); List<TypeInfo> types = all.GetDependencyObjects (); Helper.WriteWarningGenerated (text); text.AppendLine ("using Mono;"); text.AppendLine ("using System;"); text.AppendLine ("using System.Collections.Generic;"); text.AppendLine ("using System.Windows;"); text.AppendLine ("using System.Windows.Controls;"); text.AppendLine ("using System.Windows.Documents;"); text.AppendLine ("using System.Windows.Ink;"); text.AppendLine ("using System.Windows.Input;"); text.AppendLine ("using System.Windows.Markup;"); text.AppendLine ("using System.Windows.Media;"); text.AppendLine ("using System.Windows.Media.Media3D;"); text.AppendLine ("using System.Windows.Media.Animation;"); text.AppendLine ("using System.Windows.Shapes;"); text.AppendLine (); for (int i = 0; i < types.Count; i++) { TypeInfo type = types [i]; bool call_initialize = type.Annotations.ContainsKey ("CallInitialize"); string ns; ns = type.Namespace; if (string.IsNullOrEmpty (ns)) { Console.WriteLine ("The type '{0}' in {1} does not have a namespace annotation.", type.FullName, Path.GetFileName (type.Header)); continue; } if (ns == "None") { //Console.WriteLine ("The type '{0}''s Namespace annotation is 'None'.", type.FullName); continue; } string check_ns = Path.Combine (Path.Combine (Path.Combine (class_dir, "System.Windows"), ns), type.ManagedName.Replace ("`1", "") + ".cs"); if (!File.Exists (check_ns)) throw new Exception (string.Format ("The file {0} does not exist, did you annotate the class with the wrong namespace?", check_ns)); if (previous_namespace != ns) { if (previous_namespace != string.Empty) { text.AppendLine ("}"); text.AppendLine (); } text.Append ("namespace "); text.Append (ns); text.AppendLine (" {"); previous_namespace = ns; } else { text.AppendLine (); } if (type.ContentProperty != null) text.AppendFormat ("\t[ContentProperty (\"{0}\")]\n", type.ContentProperty); text.Append ("\tpartial class "); text.Append (type.ManagedName.Replace ("`1", "<T>")); text.AppendLine (" {"); // Public ctor if (!string.IsNullOrEmpty (type.C_Constructor)) { string access = "Public"; foreach (MemberInfo member in type.Children.Values) { MethodInfo method = member as MethodInfo; if (method == null || !method.IsConstructor || method.IsStatic) continue; if (method.Parameters.Count != 0) continue; if (method.Annotations.ContainsKey ("ManagedAccess")) access = method.Annotations.GetValue ("ManagedAccess"); break; } text.Append ("\t\t"); Helper.WriteAccess (text, access); text.Append (" "); text.Append (type.ManagedName.Replace ("`1", "")); text.Append (" () : base (SafeNativeMethods."); text.Append (type.C_Constructor); text.Append (" (), true)"); if (call_initialize) { text.AppendLine (); text.AppendLine ("\t\t{"); text.AppendLine ("\t\t\tInitialize ();"); text.AppendLine ("\t\t}"); } else { text.AppendLine (" {}"); } } // Internal ctor text.Append ("\t\tinternal "); text.Append (type.ManagedName.Replace ("`1", "")); text.Append (" (IntPtr raw, bool dropref) : base (raw, dropref)"); if (call_initialize) { text.AppendLine (); text.AppendLine ("\t\t{"); text.AppendLine ("\t\t\tInitialize ();"); text.AppendLine ("\t\t}"); } else { text.AppendLine (" {}"); } text.AppendLine ("\t}"); } text.AppendLine ("}"); Helper.WriteAllText (filename, text.ToString ()); }
public void GenerateTypes_G (GlobalInfo all) { string base_dir = Environment.CurrentDirectory; string class_dir = Path.Combine (base_dir, "class"); string moon_moonlight_dir = Path.Combine (class_dir, "System.Windows"); List<TypeInfo> types = new List<TypeInfo> (all.GetDependencyObjects ()); StringBuilder text = new StringBuilder (); Helper.WriteWarningGenerated (text); text.AppendLine ("using Mono;"); text.AppendLine ("using System;"); text.AppendLine ("using System.Reflection;"); text.AppendLine ("using System.Collections.Generic;"); text.AppendLine (""); text.AppendLine ("namespace Mono {"); text.AppendLine ("\tpartial class Types {"); text.AppendLine ("\t\tprivate void CreateNativeTypes ()"); text.AppendLine ("\t\t{"); text.AppendLine ("\t\t\tType t;"); text.AppendLine ("\t\t\ttry {"); foreach (MemberInfo m in all.Children.Values) { TypeInfo t = m as TypeInfo; if (t == null) continue; if (types.Contains (t)) continue; types.Add (t); } types.Sort (new Members.MembersSortedByManagedFullName <TypeInfo> ()); for (int i = 0; i < types.Count; i++) { TypeInfo t = types [i]; string type = t.ManagedName; if (String.IsNullOrEmpty (t.Namespace) || t.Namespace == "None" || t.Name.StartsWith ("MoonWindow")) continue; type = type.Replace ("`1", "<>"); //Log.WriteLine ("Found Kind.{0} in {1} which result in type: {2}.{3}", kind, file, ns, type); text.Append ("\t\t\t\tt = typeof ("); text.Append (t.Namespace); text.Append ("."); text.Append (type); text.AppendLine ("); "); text.Append ("\t\t\t\tAddBuiltinType (t, new ManagedType (t, Kind."); text.Append (t.KindName); text.AppendLine ("));"); } // now handle the primitive types output_native_type_delegate f = delegate (string t, string k) { text.Append ("\t\t\t\tt = typeof ("); text.Append (t); text.AppendLine (");"); text.Append ("\t\t\t\tAddBuiltinType (t, new ManagedType (t, Kind."); text.Append (k); text.AppendLine ("));"); }; f ("char", "CHAR"); f ("object", "OBJECT"); f ("bool", "BOOL"); f ("double", "DOUBLE"); f ("float", "FLOAT"); f ("ulong", "UINT64"); f ("long", "INT64"); f ("uint", "UINT32"); f ("int", "INT32"); f ("string", "STRING"); f ("TimeSpan", "TIMESPAN"); f ("Enum", "ENUM"); f ("System.Windows.Application", "APPLICATION"); f ("System.Windows.Thickness", "THICKNESS"); f ("System.Windows.CornerRadius", "CORNERRADIUS"); f ("System.Windows.PropertyPath", "PROPERTYPATH"); f ("System.Windows.Point", "POINT"); f ("System.Windows.Rect", "RECT"); f ("System.Windows.Size", "SIZE"); f ("System.Windows.FontStretch", "FONTSTRETCH"); f ("System.Windows.FontWeight", "FONTWEIGHT"); f ("System.Windows.FontStyle", "FONTSTYLE"); f ("System.Windows.Documents.TextSelection", "TEXTSELECTION"); f ("System.Windows.Documents.TextPointer", "TEXTPOINTER"); f ("System.Windows.Media.FontFamily", "FONTFAMILY"); f ("System.Windows.Markup.XmlLanguage", "XMLLANGUAGE"); f ("System.Windows.Input.Cursor", "CURSORTYPE"); f ("System.Windows.Messaging.LocalMessageReceiver", "LOCALMESSAGERECEIVER"); f ("System.Windows.Messaging.LocalMessageSender", "LOCALMESSAGESENDER"); text.AppendLine ("\t\t\t} catch (Exception ex) {"); text.AppendLine ("\t\t\t\tConsole.WriteLine (\"There was an error while loading native types: \" + ex.ToString ());"); text.AppendLine ("\t\t\t}"); text.AppendLine ("\t\t}"); text.AppendLine ("\t}"); text.AppendLine ("}"); Log.WriteLine ("typeandkidngen done"); Helper.WriteAllText (Path.Combine (Path.Combine (moon_moonlight_dir, "Mono"), "Types.g.cs"), text.ToString ()); }