/* * [StructLayout(LayoutKind.Sequential)] * public struct PGFClosure * { * public GuMapItor fn; * public IntPtr grammar; * public IntPtr obj; * }*/ public static string ReadString(Action <IntPtr, NativeGU.NativeExceptionContext> f) { var pool = new NativeGU.NativeMemoryPool(); var exn = new NativeGU.NativeExceptionContext(pool); var sbuf = NativeGU.gu_new_string_buf(pool.Ptr); var output = NativeGU.gu_string_buf_out(sbuf); f(output, exn); if (exn.IsRaised) { throw new Exception(); } var strPtr = NativeGU.gu_string_buf_freeze(sbuf, pool.Ptr); var str = Native.NativeString.StringFromNativeUtf8(strPtr); return(str); }
/// <summary> /// Linearize expression, i.e. produce a string in the concrete grammar from an expression in the abstract grammar. /// </summary> /// <param name="e"></param> /// <returns></returns> public string Linearize(Expr e) { var tmp_pool = new NativeGU.NativeMemoryPool(); var exn = new NativeGU.NativeExceptionContext(tmp_pool); var buf = NativeGU.gu_new_string_buf(tmp_pool.Ptr); var out_ = NativeGU.gu_string_buf_out(buf); Native.pgf_linearize(Ptr, e.Ptr, out_, exn.Ptr); if (exn.IsRaised) { throw new PGFError(); } else { var cstr = NativeGU.gu_string_buf_freeze(buf, tmp_pool.Ptr); return(Native.NativeString.StringFromNativeUtf8(cstr)); } }
private string LinearizeCnc(IntPtr cnc) { var tmp_pool = new NativeGU.NativeMemoryPool(); var exn = new NativeGU.NativeExceptionContext(tmp_pool); var sbuf = NativeGU.gu_new_string_buf(tmp_pool.Ptr); var out_ = NativeGU.gu_string_buf_out(sbuf); var wrapped = Native.pgf_lzr_wrap_linref(cnc, tmp_pool.Ptr); Native.pgf_lzr_linearize_simple(Ptr, wrapped, 0, out_, exn.Ptr, tmp_pool.Ptr); if (exn.IsRaised) { throw new PGFError("Could not linearize abstract tree."); } var cstr = NativeGU.gu_string_buf_freeze(sbuf, tmp_pool.Ptr); return(Native.NativeString.StringFromNativeUtf8(cstr)); }