public static ApiProfile BakeOverloads([NotNull] ApiProfile profile) { var pipeline = new OverloaderPipeline(); var functionsThatNeedOverloads = profile.NativeSignatures.Where(f => pipeline.HasApplicableStage(f)); var newOverloads = pipeline.ConsumeSignatures(functionsThatNeedOverloads).ToList(); // Discard duplicate overloads var optimizedOverloads = new List <FunctionSignature>(profile.Overloads); foreach (var extensionGroup in newOverloads.GroupBy(f => f.Extension)) { var uniqueOverloads = new List <FunctionSignature>(); foreach (var function in extensionGroup) { if (uniqueOverloads.Any(f => f.HasSameSignatureAs(function))) { continue; } uniqueOverloads.Add(function); } optimizedOverloads.AddRange(uniqueOverloads); } return(new ApiProfileBuilder(profile).WithOverloads(optimizedOverloads).Build()); }
/// <summary> /// Gets the overloads for the given signatures. /// </summary> /// <param name="sigs">The signatures to overload.</param> /// <returns>The overloads.</returns> public static IEnumerable <(FunctionSignature, StringBuilder)> GetOverloads(IEnumerable <FunctionSignature> sigs) { var pipeline = new OverloaderPipeline(); var functionsThatNeedOverloads = sigs.ToList(); var newOverloads = pipeline.ConsumeSignatures(functionsThatNeedOverloads).ToList(); // Discard duplicate overloads var uniqueOverloads = new List <(FunctionSignature, StringBuilder)>(); foreach (var function in newOverloads) { if (uniqueOverloads.Any(f => f.Item1.HasSameSignatureAs(function.Item1))) { continue; } uniqueOverloads.Add(function); } return(uniqueOverloads.Where(x => functionsThatNeedOverloads.All(y => !y.HasSameSignatureAs(x.Item1))).ToList()); }