redefrec

MetaSearch

Jun 8th, 2018
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module meta.search;
  2.  
  3. public import std.meta;
  4. public import std.traits;
  5. public import meta.seq;
  6. public import std.algorithm;
  7.  
  8. private import net.test;
  9.  
  10. @TestUDA
  11. struct Y {
  12.     int y;
  13. }
  14.  
  15. template MapMemberStringToSymbol(alias Unit, alias Member) {
  16.     alias MapMemberStringToSymbol = Alias!(__traits(getMember, Unit, Member));
  17. }
  18.  
  19. template AllMemberSymbols (alias Unit) {
  20.     alias AllMemberSymbols = staticMap!(ApplyLeft!(MapMemberStringToSymbol, Unit), AliasSeq!(__traits(allMembers, Unit)));
  21. }
  22.  
  23. bool isPackage(alias Member)() {
  24.     static if (__traits(isStaticFunction, Member)) return false;
  25.     else return startsWith(Member.stringof, "package ");
  26. }
  27.  
  28. bool isModule(alias Member)() {
  29.     static if (__traits(isStaticFunction, Member)) return false;
  30.     else return startsWith(Member.stringof, "module ");
  31. }
  32.  
  33. template SubPackages(alias Unit) {
  34.     alias SubPackages = Filter!(isPackage, AllMemberSymbols!(Unit));
  35. }
  36.  
  37. template SubModules(alias Unit) {
  38.     alias SubModules = Filter!(isModule, AllMemberSymbols!(Unit));
  39. }
  40.  
  41. template SubSymbols(alias Unit) {
  42.     alias SubSymbols = Difference!(AllMemberSymbols!Unit).To!(SubPackages!Unit, SubModules!Unit);
  43. }
  44.  
  45. template RecurseTransitiveSearchUDA (alias UDA, Ignored...) {
  46.     template Call (alias Unit) {
  47.         pragma (msg, "Searching in: " ~ Unit.stringof);
  48.         alias OwnSymbols = Filter!(ApplyRight!(hasUDA, UDA), SubSymbols!Unit);
  49.         pragma (msg, "Symbols: ");
  50.         pragma (msg, staticMap!(fullyQualifiedName, SubSymbols!Unit));
  51.         pragma (msg, "UDA Symbols: ");
  52.         pragma (msg, staticMap!(fullyQualifiedName, OwnSymbols));
  53.  
  54.         alias NewPackages = Difference!(SubPackages!(Unit)).To!(Ignored);
  55.         alias NewModules = Difference!(SubModules!(Unit)).To!(Ignored);
  56.         alias NewModulesAndPackages = AliasSeq!(NewPackages,NewModules);
  57.         alias NewIgnored = NoDuplicates!(Ignored, NewModulesAndPackages);
  58.         pragma (msg, "Modules and Packages: ");
  59.         pragma (msg, staticMap!(fullyQualifiedName, NewModulesAndPackages));
  60.  
  61.         alias Recursor = RecurseTransitiveSearchUDA!(UDA, NewIgnored).Call;
  62.         alias SubModuleSymbols = staticMap!(Recursor, NewModulesAndPackages);
  63.  
  64.         alias Call = AliasSeq!(OwnSymbols, SubModuleSymbols);
  65.     }
  66. }
  67.  
  68. template TransitiveSearchUDA (alias UDA, alias Unit) {
  69.     alias TransitiveSearchUDA = RecurseTransitiveSearchUDA!(UDA, AliasSeq!(object, std)).Call!(Unit);
  70. }
RAW Paste Data