/// <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); }
/// <summary> /// Get all possible linearization for an expression (see <see cref="Linearize(Expression)"/>). /// </summary> /// <param name="e"></param> /// <returns></returns> public IEnumerable <string> LinearizeAll(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); if (exn.IsRaised || cts == IntPtr.Zero) { throw new PGF.Exceptions.PGFException("Could not linearize the abstract tree."); } return(NativeGU.IteratorToIEnumerable(cts, tmp_pool.Ptr).Select(LinearizeCnc)); }