Ejemplo n.º 1
0
 public void GenerateValueTypesABI(CsTreeWriter file)
 {
     foreach (var type in AllGeneratedStructs.Where(t => CsRender.RequiresABITranslation(t.ToVariable())))
     {
         file.DefineStruct(type);
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void GenerateValueTypes(CsTreeWriter file)
        {
            foreach (var type in AllGeneratedEnums)
            {
                file.DefineEnum(type);
            }

            foreach (var type in AllGeneratedDelegates)
            {
                file.DefineDelegate(type);
            }

            foreach (var type in AllGeneratedStructs.Where(t => t.Origin != TypeOrigin.Managed))
            {
                file.DefineStruct(type);
            }
        }
Ejemplo n.º 4
0
        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);
                    }
                });
            });
        }
Ejemplo n.º 5
0
        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('.', '_'));
                });
            });
        }
Ejemplo n.º 6
0
 public void GenerateClass(CsTreeWriter file, AST.Object type)
 {
     file.DefineClass(type);
 }