/// <summary> /// Get the bracketed (structured) linearization of an expression. /// </summary> /// <param name="e"></param> /// <returns></returns> public Bracket BracketedLinearize(Expression e) { var tmp_pool = new NativeGU.NativeMemoryPool(); var exn = new NativeGU.NativeExceptionContext(tmp_pool); var cts = Native.pgf_lzr_concretize(Ptr, e.Ptr, exn.Ptr, tmp_pool.Ptr); var ctree = IntPtr.Zero; NativeGU.gu_enum_next(cts, ref ctree, tmp_pool.Ptr); if (ctree == IntPtr.Zero) { return(null); } ctree = Native.pgf_lzr_wrap_linref(ctree, tmp_pool.Ptr); var builder = new Bracket.BracketBuilder(); var mem = Marshal.AllocHGlobal(Marshal.SizeOf <Native.PgfLinFuncs>()); Marshal.StructureToPtr <Native.PgfLinFuncs>(builder.LinFuncs, mem, false); Native.pgf_lzr_linearize(Ptr, ctree, 0, ref mem, tmp_pool.Ptr); var b = builder.Build(); Marshal.FreeHGlobal(mem); return(b); }
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 PGF.Exceptions.PGFException("Could not linearize abstract tree."); } var cstr = NativeGU.gu_string_buf_freeze(sbuf, tmp_pool.Ptr); return(Native.NativeString.StringFromNativeUtf8(cstr)); }