From e84acb90ea15f9488a18648c8dd7229d83b7e892 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 19 Nov 2026 21:05:50 +0100 Subject: [PATCH] Read every aggregate of the catalog as a static method of its values' class The catalog's aggregates state, for each SQL aggregate, the MEOS functions of its transition and final steps. #aggregate_methods of tools/objectgen.py, built beside #method_for and calling its #map_param and #map_return, emits one static method per aggregate on the class of the value its transition takes after its state, as #aggregateMethods of MEOS.js's codegen/ObjectGenerator.ts does: the method takes the values as an array and the transition's other arguments, threads the transition over the values from a NULL state, as MEOS's C callers do, and answers the final function's result, the final function freeing the state. The method takes the name an engine holding one function per name calls the aggregate, its altSqlName or else its sqlName, in the PascalCase of every method: Raster.RasterUnion, Raster.SummaryStatsAgg and Raster.SameAlignmentAgg among the 27 emitted. An aggregate several transitions serve under one name over one class, as tMinAgg over the integer, float and text temporal values, takes no method, and GAP-LEDGER.md lists it under a kind of its own beside the two other reasons an aggregate stays out. MEOS.NET.Tests/AggregateTests.cs unions two tiles and states their statistics. Why: the object layer projected no aggregate, so a caller threaded RasterUnionTransfn and RasterUnionFinalfn by hand, and rasterUnion and summaryStatsAgg were the two raster functions MEOS.NET lacked. Measured: dotnet build reports 0 warnings and 0 errors, and dotnet test passes 120 of 120 with none skipped, against the libmeos of the catalog of MobilityDB master eb44541013. --- GAP-LEDGER.md | 30 +++++++++ MEOS.NET.Tests/AggregateTests.cs | 55 ++++++++++++++++ MEOS.NET/Types/CBuffer.g.cs | 11 ++++ MEOS.NET/Types/Geo.g.cs | 11 ++++ MEOS.NET/Types/Jsonb.g.cs | 11 ++++ MEOS.NET/Types/NPoint.g.cs | 11 ++++ MEOS.NET/Types/PCPatch.g.cs | 11 ++++ MEOS.NET/Types/PCPoint.g.cs | 11 ++++ MEOS.NET/Types/Pose.g.cs | 11 ++++ MEOS.NET/Types/PoseChain.g.cs | 11 ++++ MEOS.NET/Types/Raster.g.cs | 33 ++++++++++ MEOS.NET/Types/Set.g.cs | 22 +++++++ MEOS.NET/Types/Span.g.cs | 22 +++++++ MEOS.NET/Types/SpanSet.g.cs | 22 +++++++ MEOS.NET/Types/Temporal.g.cs | 99 ++++++++++++++++++++++++++++ MEOS.NET/Types/Text.g.cs | 11 ++++ tools/objectgen.py | 108 ++++++++++++++++++++++++++++++- 17 files changed, 489 insertions(+), 1 deletion(-) create mode 100644 MEOS.NET.Tests/AggregateTests.cs diff --git a/GAP-LEDGER.md b/GAP-LEDGER.md index 8c16085..b605345 100644 --- a/GAP-LEDGER.md +++ b/GAP-LEDGER.md @@ -4578,4 +4578,34 @@ An operator takes the name and parameter types of a member of an ancestor, a sec None in this run. +### aggregate served by several transitions — 7 + +Several transition functions serve one aggregate name over values of the class, and nothing in the values tells them apart. + +| class | member | what is missing | +| --- | --- | --- | +| Temporal | tCentroid | tpoint_tcentroid_transfn, tnpoint_tcentroid_transfn | +| Temporal | tMaxAgg | tint_tmax_transfn, tbigint_tmax_transfn, tfloat_tmax_transfn, ttext_tmax_transfn | +| Temporal | tMinAgg | tint_tmin_transfn, tbigint_tmin_transfn, tfloat_tmin_transfn, ttext_tmin_transfn | +| Temporal | tSum | tint_tsum_transfn, tbigint_tsum_transfn, tfloat_tsum_transfn | +| Temporal | wMax | tint_wmax_transfn, tbigint_wmax_transfn, tfloat_wmax_transfn | +| Temporal | wMin | tint_wmin_transfn, tbigint_wmin_transfn, tfloat_wmin_transfn | +| Temporal | wSum | tint_wsum_transfn, tbigint_wsum_transfn, tfloat_wsum_transfn | + +### aggregate state not threadable — 0 + +The transition and the final function of the aggregate do not pass one state pointer from call to call. + +None in this run. + +### aggregate argument or result needs marshalling — 3 + +An argument of the transition or the result of the final function has no rule of this generator. + +| class | member | what is missing | +| --- | --- | --- | +| Temporal | appendInstantAgg | temporal_app_tinst_transfn / temporal_append_finalfn | +| Temporal | wAvgAgg | tnumber_wavg_transfn / tnumber_tavg_finalfn | +| Temporal | wCount | temporal_wcount_transfn / temporal_tagg_finalfn | + diff --git a/MEOS.NET.Tests/AggregateTests.cs b/MEOS.NET.Tests/AggregateTests.cs new file mode 100644 index 0000000..444553c --- /dev/null +++ b/MEOS.NET.Tests/AggregateTests.cs @@ -0,0 +1,55 @@ +using MEOS.NET.Types; + +namespace MEOS.NET.Tests +{ + /// + /// An aggregate of the catalog's `aggregates` is a static method of the + /// class of its values: the transition threaded over the values from a NULL + /// state, then the final function. Each answer is the one MobilityDB's + /// 500_raster test states for the same tiles. + /// + [TestClass] + public class AggregateTests : MeosTest + { + // The example of the manual: two 2x2 tiles of one 32BF band, the second + // one pixel east and one south of the first, holding 1 and 3. + private static Raster[] Tiles() => new[] + { + Raster.MakeEmpty(2, 2, 0, 2, 1, -1, 0, 0, 3857)!.AddBand(1, "32BF", 1, -9999, true)!, + Raster.MakeEmpty(2, 2, 1, 1, 1, -1, 0, 0, 3857)!.AddBand(1, "32BF", 3, -9999, true)!, + }; + + [TestMethod] + public void TheUnionOfTwoTilesTakesTheMeanWhereTheyOverlap() + { + Raster union = Raster.RasterUnion(Tiles(), 1, "MEAN")!; + + // {{1,1,NULL},{1,2,3},{NULL,3,3}} + var (values, nodata) = union.DumpValues(1, true); + CollectionAssert.AreEqual( + new[] { false, false, true, false, false, false, true, false, false }, nodata); + CollectionAssert.AreEqual(new[] { 1.0, 1, 1, 2, 3, 3, 3 }, + values.Where((_v, i) => !nodata[i]).ToArray()); + } + + [TestMethod] + public void TheStatisticsOfABandSpanTheTiles() + { + BandStats stats = Raster.SummaryStatsAgg(Tiles(), 1, true)!; + + Assert.AreEqual(8, stats.Count()); + Assert.AreEqual(16.0, stats.Sum()); + Assert.AreEqual(2.0, stats.Mean()); + Assert.AreEqual(1.0, stats.Stddev()); + Assert.AreEqual(1.0, stats.Min()); + Assert.AreEqual(3.0, stats.Max()); + } + + [TestMethod] + public void AnAggregateOverNoValuesIsNull() + { + Assert.IsNull(Raster.RasterUnion(Array.Empty(), 1, "MEAN")); + Assert.IsNull(Raster.SummaryStatsAgg(Array.Empty(), 1, true)); + } + } +} diff --git a/MEOS.NET/Types/CBuffer.g.cs b/MEOS.NET/Types/CBuffer.g.cs index 82a121a..0c84019 100644 --- a/MEOS.NET/Types/CBuffer.g.cs +++ b/MEOS.NET/Types/CBuffer.g.cs @@ -289,5 +289,16 @@ public int Touches(CBuffer cb2) public static CBuffer? Make(Geo point, double radius) => MEOSFactory.WrapCBuffer(Meos.CbufferMake(point.Ptr, radius)); + public static Set? SetUnionAgg(CBuffer[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.CbufferUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Geo.g.cs b/MEOS.NET/Types/Geo.g.cs index 936871b..ea74dd9 100644 --- a/MEOS.NET/Types/Geo.g.cs +++ b/MEOS.NET/Types/Geo.g.cs @@ -439,6 +439,17 @@ public static int[] ClusterKmeans(Geo[] geoms, uint k) } } + public static Set? SetUnionAgg(Geo[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.GeoUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + public static string? Typename(int type) => Meos.GeoTypename(type); diff --git a/MEOS.NET/Types/Jsonb.g.cs b/MEOS.NET/Types/Jsonb.g.cs index 4168804..3db52c7 100644 --- a/MEOS.NET/Types/Jsonb.g.cs +++ b/MEOS.NET/Types/Jsonb.g.cs @@ -410,5 +410,16 @@ public long ToInt64() } } + public static Set? SetUnionAgg(Jsonb[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.JsonbUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/NPoint.g.cs b/MEOS.NET/Types/NPoint.g.cs index 7c95d1b..995853e 100644 --- a/MEOS.NET/Types/NPoint.g.cs +++ b/MEOS.NET/Types/NPoint.g.cs @@ -199,5 +199,16 @@ public bool SameRid(TNPoint temp) public static NPoint? Make(long rid, double pos) => MEOSFactory.WrapNPoint(Meos.NpointMake(rid, pos)); + public static Set? SetUnionAgg(NPoint[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.NpointUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/PCPatch.g.cs b/MEOS.NET/Types/PCPatch.g.cs index f1a7316..7bdb4bb 100644 --- a/MEOS.NET/Types/PCPatch.g.cs +++ b/MEOS.NET/Types/PCPatch.g.cs @@ -183,5 +183,16 @@ public uint Npoints() } } + public static Set? SetUnionAgg(PCPatch[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.PcpatchUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/PCPoint.g.cs b/MEOS.NET/Types/PCPoint.g.cs index f91cabc..1ec8477 100644 --- a/MEOS.NET/Types/PCPoint.g.cs +++ b/MEOS.NET/Types/PCPoint.g.cs @@ -221,5 +221,16 @@ public bool Ne(PCPoint pt2) } } + public static Set? SetUnionAgg(PCPoint[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.PcpointUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Pose.g.cs b/MEOS.NET/Types/Pose.g.cs index def305f..aaf2d80 100644 --- a/MEOS.NET/Types/Pose.g.cs +++ b/MEOS.NET/Types/Pose.g.cs @@ -268,5 +268,16 @@ public double[] Ypr() public static Pose? MakePoint3dYpr(Geo gs, double yaw, double pitch, double roll) => MEOSFactory.WrapPose(Meos.PoseMakePoint3dYpr(gs.Ptr, yaw, pitch, roll)); + public static Set? SetUnionAgg(Pose[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.PoseUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/PoseChain.g.cs b/MEOS.NET/Types/PoseChain.g.cs index 66773be..d32bbce 100644 --- a/MEOS.NET/Types/PoseChain.g.cs +++ b/MEOS.NET/Types/PoseChain.g.cs @@ -254,5 +254,16 @@ public int SRID() } } + public static Set? SetUnionAgg(PoseChain[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.PosechainUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Raster.g.cs b/MEOS.NET/Types/Raster.g.cs index ef166bd..8ecbda0 100644 --- a/MEOS.NET/Types/Raster.g.cs +++ b/MEOS.NET/Types/Raster.g.cs @@ -473,6 +473,39 @@ public static int EValueGdal(Temporal traj, string path, int band, Span vspan) public static Temporal? MinusValueGdal(Temporal traj, string path, int band, Span vspan) => MEOSFactory.WrapTemporal(Meos.RasterMinusValueGdal(traj.Ptr, path, band, vspan.Ptr)); + public static Raster? RasterUnion(Raster[] values, int band, string uniontype) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.RasterUnionTransfn(_state, _v.Ptr, band, uniontype); + } + + return MEOSFactory.WrapRaster(Meos.RasterUnionFinalfn(_state)); + } + + public static bool SameAlignmentAgg(Raster[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.RasterSameAlignmentTransfn(_state, _v.Ptr); + } + + return Meos.RasterSameAlignmentFinalfn(_state); + } + + public static BandStats? SummaryStatsAgg(Raster[] values, int band, bool exclude_nodata) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.RasterSummaryStatsTransfn(_state, _v.Ptr, band, exclude_nodata); + } + + return MEOSFactory.WrapBandStats(Meos.RasterSummaryStatsFinalfn(_state)); + } + public static Temporal? TileAtValue(Temporal traj, RaQuet rq, Span vspan) => MEOSFactory.WrapTemporal(Meos.RasterTileAtValue(traj.Ptr, rq.Ptr, vspan.Ptr)); diff --git a/MEOS.NET/Types/Set.g.cs b/MEOS.NET/Types/Set.g.cs index 581d47b..2df52cd 100644 --- a/MEOS.NET/Types/Set.g.cs +++ b/MEOS.NET/Types/Set.g.cs @@ -174,5 +174,27 @@ public bool Right(Set s2) } } + public static Set? SetUnionAgg(Set[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.SetUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + + public static Temporal? TCount(Set[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TstzsetTcountTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Span.g.cs b/MEOS.NET/Types/Span.g.cs index 32a35b8..4899ad2 100644 --- a/MEOS.NET/Types/Span.g.cs +++ b/MEOS.NET/Types/Span.g.cs @@ -193,5 +193,27 @@ public bool UpperInc() } } + public static SpanSet? SpanUnionAgg(Span[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.SpanUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSpanSet(Meos.SpansetUnionFinalfn(_state)); + } + + public static Temporal? TCount(Span[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TstzspanTcountTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/SpanSet.g.cs b/MEOS.NET/Types/SpanSet.g.cs index f4da7f2..b57f506 100644 --- a/MEOS.NET/Types/SpanSet.g.cs +++ b/MEOS.NET/Types/SpanSet.g.cs @@ -246,5 +246,27 @@ public bool UpperInc() } } + public static SpanSet? SpansetUnionAgg(SpanSet[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.SpansetUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSpanSet(Meos.SpansetUnionFinalfn(_state)); + } + + public static Temporal? TCount(SpanSet[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TstzspansetTcountTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Temporal.g.cs b/MEOS.NET/Types/Temporal.g.cs index cd4ec8b..7787805 100644 --- a/MEOS.NET/Types/Temporal.g.cs +++ b/MEOS.NET/Types/Temporal.g.cs @@ -587,6 +587,17 @@ public bool UpperInc() public Set? Valueset() => MEOSFactory.WrapSet(Meos.TemporalValueset(this.Ptr)); + public static Temporal? AppendSequenceAgg(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TemporalAppTseqTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalAppendFinalfn(_state)); + } + public static Temporal? FromHexWKB(string hexwkb) => MEOSFactory.WrapTemporal(Meos.TemporalFromHexwkb(hexwkb)); @@ -603,6 +614,17 @@ public bool UpperInc() } } + public static Temporal? MergeAgg(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TemporalMergeTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + public static Temporal? MergeArray(Temporal[] temparr) { IntPtr[] _temparrValues = new IntPtr[temparr.Length]; @@ -622,5 +644,82 @@ public bool UpperInc() } } + public static Temporal? ReachabilityFilterAgg(Temporal[] values, double maxspeed) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TemporalReachabilityFilterTransfn(_state, _v.Ptr, maxspeed); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalReachabilityFilterFinalfn(_state)); + } + + public static Temporal? TAndAgg(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TboolTandTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + + public static Temporal? TAvg(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TnumberTavgTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TnumberTavgFinalfn(_state)); + } + + public static Temporal? TCount(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TemporalTcountTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + + public static Temporal? TOrAgg(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TboolTorTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + + public static Temporal? Tdensity(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TpcpatchTdensityTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + + public static Temporal? Tnpoints(Temporal[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TpcpatchTnpointsTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapTemporal(Meos.TemporalTaggFinalfn(_state)); + } + } } diff --git a/MEOS.NET/Types/Text.g.cs b/MEOS.NET/Types/Text.g.cs index 0017088..14c7ecb 100644 --- a/MEOS.NET/Types/Text.g.cs +++ b/MEOS.NET/Types/Text.g.cs @@ -129,5 +129,16 @@ public bool Right(TextSet s) public static Text? FromCstring(string str) => MEOSFactory.WrapText(Meos.CstringToText(str)); + public static Set? SetUnionAgg(Text[] values) + { + IntPtr _state = IntPtr.Zero; + foreach (var _v in values) + { + _state = Meos.TextUnionTransfn(_state, _v.Ptr); + } + + return MEOSFactory.WrapSet(Meos.SetUnionFinalfn(_state)); + } + } } diff --git a/tools/objectgen.py b/tools/objectgen.py index cd6ea64..5ec60e0 100644 --- a/tools/objectgen.py +++ b/tools/objectgen.py @@ -63,6 +63,15 @@ "ancestor, a second function for one call, or would take the calls of " "an ancestor's member the layer does not emit and so cannot declare " "again beside it.", + "aggregate served by several transitions": + "Several transition functions serve one aggregate name over values of " + "the class, and nothing in the values tells them apart.", + "aggregate state not threadable": + "The transition and the final function of the aggregate do not pass " + "one state pointer from call to call.", + "aggregate argument or result needs marshalling": + "An argument of the transition or the result of the final function has " + "no rule of this generator.", } GENERATOR_VERSION = "0.1.0" @@ -414,6 +423,9 @@ def __init__(self, name: str, ret: str, params: list[tuple[str, str]], # (parameter name, struct) for each array of structs of scalars and # strings the method lays out for MEOS (#written_struct). self.written: list[tuple[str, str]] = [] + # The whole body, braces included, of a method no call template + # spells, as an aggregate threads its transition over the values. + self.lines: list[str] | None = None def needs_a_body(self) -> bool: """Whether the call needs anything allocated, pinned or read around it.""" @@ -1352,6 +1364,90 @@ def inherited_names(self, cls: str) -> set[tuple]: p = self.m.parent.get(p) return names + def aggregate_methods(self, cls: str) -> list[Method]: + """The aggregates over the values of a class, one static method each. + + Built beside #method_for, whose #map_param and #map_return it calls for + the transition's arguments and the final function's result, as + #aggregateMethods of MEOS.js's codegen/ObjectGenerator.ts builds them: + the catalog's `aggregates` whose transition takes the class's C type + after its state, named as an engine holding one function per name calls + them, the aggregate's `altSqlName` or else its `sqlName`, as MobilityDuck + registers one. The method threads the transition over the values from a + NULL state, as MEOS's C callers do, and answers the final function's + result; the final function frees the state. An aggregate two transitions + serve under one name over this class has no method of its own: its + overloads take the same values and nothing tells them apart.""" + by_name: dict[str, list[tuple[str, str]]] = {} + for agg in self.m.idl.get("aggregates") or []: + transition = (agg.get("transition") or {}).get("meos") + final = (agg.get("final") or {}).get("meos") + f = transition and self.m.functions.get(transition) + if not f or not final or len(f.get("params", [])) < 2: + continue + if self.m.class_for_ctype(clean(f["params"][1]["canonical"])) != cls: + continue + name = agg.get("altSqlName") or agg["sqlName"] + seen = by_name.setdefault(name, []) + if (transition, final) not in seen: + seen.append((transition, final)) + methods = [] + for name, overloads in by_name.items(): + if len({t for t, _f in overloads}) > 1: + self.defer(cls, name, "aggregate served by several transitions", + ", ".join(t for t, _f in overloads)) + continue + transition, final = overloads[0] + tsig = codegen.SIGNATURES.get(transition) + fsig = codegen.SIGNATURES.get(final) + ff = self.m.functions.get(final) + if (not tsig or not fsig or not ff or tsig[0] != "IntPtr" + or len(tsig[1]) < 2 or tsig[1][0][0] != "IntPtr" + or len(fsig[1]) != 1): + self.defer(cls, name, "aggregate state not threadable", + f"{transition} and {final} do not pass one state pointer") + continue + f = self.m.functions[transition] + c_by_name = { + (codegen.csharp_param_name(p["name"]) if p["name"] else "arg"): p + for p in f.get("params", []) + } + mapped = [] + for i, (cs_type, pname) in enumerate(tsig[1][1:]): + p = c_by_name.get(pname, {}) + arg = "_v" if i == 0 else ident(pname) + m = self.map_param(p.get("canonical", cs_type), cs_type, arg, + self.m.class_for_value(p) if p else None) + if m is None or m[1] == scratch(arg): + mapped = None + break + mapped.append((m, pname)) + ret = self.map_return(ff, fsig[0]) if mapped else None + if not mapped or ret is None: + self.defer(cls, name, "aggregate argument or result needs marshalling", + f"{transition} / {final}") + continue + (item_type, item_arg), _ = mapped[0] + params = [(f"{item_type}[]", "values")] + [ + (t, pname) for (t, _a), pname in mapped[1:]] + args = ", ".join(["_state", item_arg] + [a for (_t, a), _p in mapped[1:]]) + call = f"Meos.{codegen.public_name(transition)}({args})" + answer = ret[1].replace("$", f"Meos.{codegen.public_name(final)}(_state)") + method = Method(pascal(name), ret[0], params, answer, True) + method.lines = [ + " {", + " IntPtr _state = IntPtr.Zero;", + " foreach (var _v in values)", + " {", + f" _state = {call};", + " }", + "", + f" return {answer};", + " }", + ] + methods.append(method) + return methods + def emit_class(self, cls: str) -> str: parent = self.m.parent.get(cls) or "MEOSObject" entries = [e for e in self.m.om["classes"].get(cls, {}).get("methods", []) @@ -1359,6 +1455,14 @@ def emit_class(self, cls: str) -> str: paired = [(e["function"], self.method_for(cls, e)) for e in entries] paired = self.take_portable_names(cls, paired, entries) methods = [m for _f, m in paired if m] + inherited_names = self.inherited_names(cls) + for m in self.aggregate_methods(cls): + if any(o.name == m.name for o in methods) or any( + name == m.name for name, _t in inherited_names): + self.defer(cls, m.name, "signature taken by a method", + "an aggregate takes the name of a method") + continue + methods.append(m) methods.sort(key=lambda m: (m.static, m.name)) self.emitted += len(methods) # The C function behind each instance method this class or an ancestor @@ -1411,7 +1515,9 @@ def emit_class(self, cls: str) -> str: new = "new " if (m.name, tuple(t for t, _ in m.params)) in inherited else "" kind = "static " if m.static else "" lines.append(f" public {new}{kind}{m.ret} {m.name}({args})") - if m.needs_a_body(): + if m.lines is not None: + lines.extend(m.lines) + elif m.needs_a_body(): lines.extend(self.call_body(m)) else: lines.append(f" => {m.body};")