private CsTreeWriter CreateSourceFile() { var tok = new CsTreeWriter(Settings.Mode == CSharpMode.Mono); tok.BlockComment(() => tok.Line(Disclaimer)); tok.Line(); tok.Use(Definition.LookupNamespace("Gluon")); tok.Use(Definition.LookupNamespace("System")); tok.Use(Definition.LookupNamespace(typeof(Marshal).Namespace)); tok.Use(_assemblyNS, true); tok.Use(_gluonNS, true); tok.DeferredUsings(); return(tok); }
public void GenerateNativeDecl(CsTreeWriter file) { file.Namespace(_assemblyNS, true, () => { file.Line("public static class Native"); file.Block(() => { file.Line(@"static Native()"); file.Block(() => { foreach (var type in AllGeneratedClasses.Where(t => t.Origin != TypeOrigin.Managed && t.Origin != TypeOrigin.Native && !t.IsAbstract)) { file.Line("GluonObject.RegisterType<global::{0}>(new Guid(\"{1}\"), native => new global::{0}(new AbiPtr(native)));", type.FullName("."), type.PrivateId); } }); file.Line( @"public const string DllPath = ""{0}""; [DllImport(DllPath, EntryPoint = ""$_GetGluonExceptionDetails"")] private static extern int GetGluonExceptionDetails(out int outHR, out ExceptionType outType, out IntPtr outText); internal static void RegisterTypes() {{ }} public static void Throw(int hr) {{ if (hr == (int)HResult.S_OK) return; int checkhr; ExceptionType type; IntPtr msgPtr; string msg; var chk = GetGluonExceptionDetails(out checkhr, out type, out msgPtr); if (chk != 0 || hr != checkhr) throw new GluonExceptionAssertionFail(); msg = Marshal.PtrToStringAnsi(msgPtr); throw Translate.Exception(type, msg); }}", Settings.ImportedDll, Definition.Assembly.Name.Replace('.', '_')); }); }); }
public void GenerateConverters(CsTreeWriter file) { file.Namespace(_assemblyNS, true, () => { foreach (var d in AllTranslatedDelegates) { file.DefineDelegateWrapper(d); } file.Line("internal static partial class MConv"); file.Block(() => { foreach (var t in Definition.SelectArrayedTypes().Where(t => t.IsStruct || t.IsDelegate || t.IsObject)) { file.WriteArrayMemberConverter(t); } }); }); }