kibi-swipl-linux-x64-gnu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,3090 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jan Wielemaker
4
+ E-mail: J.Wielemaker@vu.nl
5
+ WWW: http://www.swi-prolog.org/projects/xpce/
6
+ Copyright (c) 2006-2025, University of Amsterdam
7
+ VU University Amsterdam
8
+ CWI, Amsterdam
9
+ SWI-Prolog Solutions b.v.
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions
14
+ are met:
15
+
16
+ 1. Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+
19
+ 2. Redistributions in binary form must reproduce the above copyright
20
+ notice, this list of conditions and the following disclaimer in
21
+ the documentation and/or other materials provided with the
22
+ distribution.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
+ POSSIBILITY OF SUCH DAMAGE.
36
+ */
37
+
38
+ :- module(prolog_xref,
39
+ [ xref_source/1, % +Source
40
+ xref_source/2, % +Source, +Options
41
+ xref_called/3, % ?Source, ?Callable, ?By
42
+ xref_called/4, % ?Source, ?Callable, ?By, ?Cond
43
+ xref_called/5, % ?Source, ?Callable, ?By, ?Cond, ?Line
44
+ xref_defined/3, % ?Source. ?Callable, -How
45
+ xref_definition_line/2, % +How, -Line
46
+ xref_exported/2, % ?Source, ?Callable
47
+ xref_module/2, % ?Source, ?Module
48
+ xref_uses_file/3, % ?Source, ?Spec, ?Path
49
+ xref_op/2, % ?Source, ?Op
50
+ xref_prolog_flag/4, % ?Source, ?Flag, ?Value, ?Line
51
+ xref_comment/3, % ?Source, ?Title, ?Comment
52
+ xref_comment/4, % ?Source, ?Head, ?Summary, ?Comment
53
+ xref_mode/3, % ?Source, ?Mode, ?Det
54
+ xref_option/2, % ?Source, ?Option
55
+ xref_clean/1, % +Source
56
+ xref_current_source/1, % ?Source
57
+ xref_done/2, % +Source, -When
58
+ xref_built_in/1, % ?Callable
59
+ xref_source_file/3, % +Spec, -Path, +Source
60
+ xref_source_file/4, % +Spec, -Path, +Source, +Options
61
+ xref_public_list/3, % +File, +Src, +Options
62
+ xref_public_list/4, % +File, -Path, -Export, +Src
63
+ xref_public_list/6, % +File, -Path, -Module, -Export, -Meta, +Src
64
+ xref_public_list/7, % +File, -Path, -Module, -Export, -Public, -Meta, +Src
65
+ xref_meta/3, % +Source, +Goal, -Called
66
+ xref_meta/2, % +Goal, -Called
67
+ xref_hook/1, % ?Callable
68
+ % XPCE class references
69
+ xref_used_class/2, % ?Source, ?ClassName
70
+ xref_defined_class/3 % ?Source, ?ClassName, -How
71
+ ]).
72
+ :- autoload(library(apply),[maplist/2,partition/4,maplist/3]).
73
+ :- use_module(library(debug),[debug/3]).
74
+ :- autoload(library(dialect),[expects_dialect/1]).
75
+ :- autoload(library(error),[must_be/2,instantiation_error/1]).
76
+ :- autoload(library(lists),[member/2,append/2,append/3,select/3]).
77
+ :- autoload(library(operators),[push_op/3]).
78
+ :- autoload(library(option),[option/2,option/3]).
79
+ :- autoload(library(ordsets),[ord_intersect/2,ord_intersection/3]).
80
+ :- autoload(library(prolog_code), [pi_head/2]).
81
+ :- autoload(library(prolog_source),
82
+ [ prolog_canonical_source/2,
83
+ prolog_open_source/2,
84
+ prolog_close_source/1,
85
+ prolog_read_source_term/4,
86
+ prolog_file_directives/3
87
+ ]).
88
+
89
+ :- if(exists_source(library(shlib))).
90
+ :- autoload(library(shlib),[current_foreign_library/2]).
91
+ :- endif.
92
+ :- autoload(library(solution_sequences),[distinct/2,limit/2]).
93
+
94
+ :- if(exists_source(library(pldoc))).
95
+ :- use_module(library(pldoc), []). % Must be loaded before doc_process
96
+ :- use_module(library(pldoc/doc_process)).
97
+
98
+ :- endif.
99
+
100
+ :- predicate_options(xref_source/2, 2,
101
+ [ silent(boolean),
102
+ module(atom),
103
+ register_called(oneof([all,non_iso,non_built_in])),
104
+ comments(oneof([store,collect,ignore])),
105
+ process_include(boolean),
106
+ stream(stream)
107
+ ]).
108
+
109
+
110
+ :- dynamic
111
+ called/5, % Head, Src, From, Cond, Line
112
+ (dynamic)/3, % Head, Src, Line
113
+ (thread_local)/3, % Head, Src, Line
114
+ (multifile)/3, % Head, Src, Line
115
+ (public)/3, % Head, Src, Line
116
+ (declared)/4, % Head, How, Src, Line
117
+ defined/3, % Head, Src, Line
118
+ meta_goal/3, % Head, Called, Src
119
+ foreign/3, % Head, Src, Line
120
+ constraint/3, % Head, Src, Line
121
+ imported/3, % Head, Src, From
122
+ exported/2, % Head, Src
123
+ xmodule/2, % Module, Src
124
+ uses_file/3, % Spec, Src, Path
125
+ xop/2, % Src, Op
126
+ source/2, % Src, Time
127
+ used_class/2, % Name, Src
128
+ defined_class/5, % Name, Super, Summary, Src, Line
129
+ (mode)/2, % Mode, Src
130
+ xoption/2, % Src, Option
131
+ xflag/4, % Name, Value, Src, Line
132
+ grammar_rule/2, % Head, Src
133
+ module_comment/3, % Src, Title, Comment
134
+ pred_comment/4, % Head, Src, Summary, Comment
135
+ pred_comment_link/3, % Head, Src, HeadTo
136
+ pred_mode/3. % Head, Src, Det
137
+
138
+ :- create_prolog_flag(xref, false, [type(boolean)]).
139
+
140
+ /** <module> Prolog cross-referencer data collection
141
+
142
+ This library collects information on defined and used objects in Prolog
143
+ source files. Typically these are predicates, but we expect the library
144
+ to deal with other types of objects in the future. The library is a
145
+ building block for tools doing dependency tracking in applications.
146
+ Dependency tracking is useful to reveal the structure of an unknown
147
+ program or detect missing components at compile time, but also for
148
+ program transformation or minimising a program saved state by only
149
+ saving the reachable objects.
150
+
151
+ The library is exploited by two graphical tools in the SWI-Prolog
152
+ environment: the XPCE front-end started by gxref/0, and
153
+ library(prolog_colour), which exploits this library for its syntax
154
+ highlighting.
155
+
156
+ For all predicates described below, `Source` is the source that is
157
+ processed. This is normally a filename in any notation acceptable to the
158
+ file loading predicates (see load_files/2). Input handling is done by
159
+ the library(prolog_source), which may be hooked to process any source
160
+ that can be translated into a Prolog stream holding Prolog source text.
161
+ `Callable` is a callable term (see callable/1). Callables do not
162
+ carry a module qualifier unless the referred predicate is not in the
163
+ module defined by `Source`.
164
+
165
+ @bug meta_predicate/1 declarations take the module into consideration.
166
+ Predicates that are both available as meta-predicate and normal
167
+ (in different modules) are handled as meta-predicate in all
168
+ places.
169
+ @see Where this library analyses _source text_, library(prolog_codewalk)
170
+ may be used to analyse _loaded code_. The library(check) exploits
171
+ library(prolog_codewalk) to report on e.g., undefined
172
+ predicates.
173
+ */
174
+
175
+ :- predicate_options(xref_source_file/4, 4,
176
+ [ file_type(oneof([txt,prolog,directory])),
177
+ silent(boolean)
178
+ ]).
179
+ :- predicate_options(xref_public_list/3, 3,
180
+ [ path(-atom),
181
+ module(-atom),
182
+ exports(-list(any)),
183
+ public(-list(any)),
184
+ meta(-list(any)),
185
+ silent(boolean)
186
+ ]).
187
+
188
+
189
+ /*******************************
190
+ * HOOKS *
191
+ *******************************/
192
+
193
+ %! prolog:called_by(+Goal, +Module, +Context, -Called) is semidet.
194
+ %
195
+ % True when Called is a list of callable terms called from Goal,
196
+ % handled by the predicate Module:Goal and executed in the context
197
+ % of the module Context. Elements of Called may be qualified. If
198
+ % not, they are called in the context of the module Context.
199
+
200
+ %! prolog:called_by(+Goal, -ListOfCalled)
201
+ %
202
+ % If this succeeds, the cross-referencer assumes Goal may call any
203
+ % of the goals in ListOfCalled. If this call fails, default
204
+ % meta-goal analysis is used to determine additional called goals.
205
+ %
206
+ % @deprecated New code should use prolog:called_by/4
207
+
208
+ %! prolog:meta_goal(+Goal, -Pattern)
209
+ %
210
+ % Define meta-predicates. See the examples in this file for
211
+ % details.
212
+
213
+ %! prolog:hook(Goal)
214
+ %
215
+ % True if Goal is a hook that is called spontaneously (e.g., from
216
+ % foreign code).
217
+
218
+ :- multifile
219
+ prolog:called_by/4, % +Goal, +Module, +Context, -Called
220
+ prolog:called_by/2, % +Goal, -Called
221
+ prolog:meta_goal/2, % +Goal, -Pattern
222
+ prolog:hook/1, % +Callable
223
+ prolog:generated_predicate/1, % :PI
224
+ prolog:no_autoload_module/1, % Module is not suitable for autoloading.
225
+ prolog:xref_source_time/2. % +Source, =Modified
226
+
227
+ :- meta_predicate
228
+ prolog:generated_predicate(:).
229
+
230
+ :- meta_predicate
231
+ process_predicates(2, +, +).
232
+
233
+ /*******************************
234
+ * BUILT-INS *
235
+ *******************************/
236
+
237
+ %! hide_called(:Callable, +Src) is semidet.
238
+ %
239
+ % True when the cross-referencer should not include Callable as
240
+ % being called. This is determined by the option
241
+ % `register_called`.
242
+
243
+ hide_called(Callable, Src) :-
244
+ xoption(Src, register_called(Which)),
245
+ !,
246
+ mode_hide_called(Which, Callable).
247
+ hide_called(Callable, _) :-
248
+ mode_hide_called(non_built_in, Callable).
249
+
250
+ mode_hide_called(all, _) :- !, fail.
251
+ mode_hide_called(non_iso, _:Goal) :-
252
+ goal_name_arity(Goal, Name, Arity),
253
+ current_predicate(system:Name/Arity),
254
+ predicate_property(system:Goal, iso).
255
+ mode_hide_called(non_built_in, _:Goal) :-
256
+ goal_name_arity(Goal, Name, Arity),
257
+ current_predicate(system:Name/Arity),
258
+ predicate_property(system:Goal, built_in).
259
+ mode_hide_called(non_built_in, M:Goal) :-
260
+ goal_name_arity(Goal, Name, Arity),
261
+ current_predicate(M:Name/Arity),
262
+ predicate_property(M:Goal, built_in).
263
+
264
+ %! built_in_predicate(+Callable)
265
+ %
266
+ % True if Callable is a built-in
267
+
268
+ system_predicate(Goal) :-
269
+ goal_name_arity(Goal, Name, Arity),
270
+ current_predicate(system:Name/Arity), % avoid autoloading
271
+ predicate_property(system:Goal, built_in),
272
+ !.
273
+
274
+
275
+ /********************************
276
+ * TOPLEVEL *
277
+ ********************************/
278
+
279
+ verbose(Src) :-
280
+ \+ xoption(Src, silent(true)).
281
+
282
+ :- thread_local
283
+ xref_input/2. % File, Stream
284
+
285
+
286
+ %! xref_source(+Source) is det.
287
+ %! xref_source(+Source, +Options) is det.
288
+ %
289
+ % Generate the cross-reference data for Source if not already
290
+ % done and the source is not modified. Checking for modifications
291
+ % is only done for files. Options processed:
292
+ %
293
+ % - silent(+Boolean)
294
+ % If `true` (default `false`), emit warning messages.
295
+ % - module(+Module)
296
+ % Define the initial context module to work in.
297
+ % - register_called(+Which)
298
+ % Determines which calls are registerd. Which is one of
299
+ % `all`, `non_iso` or `non_built_in` (default).
300
+ % - comments(+CommentHandling)
301
+ % How to handle comments. If `store`, comments are stored into the
302
+ % database as if the file was compiled. If `collect`, comments are
303
+ % entered to the xref database and made available through
304
+ % xref_mode/2 and xref_comment/4. If `ignore`, comments are simply
305
+ % ignored. Default is to `collect` comments.
306
+ % - process_include(+Boolean)
307
+ % Process the content of included files (default is `true`).
308
+ % - stream(+Stream)
309
+ % Process the input from Stream rather than opening Source.
310
+ %
311
+ % @arg Source File specification or XPCE buffer
312
+
313
+ xref_source(Source) :-
314
+ xref_source(Source, []).
315
+
316
+ xref_source(Source, Options) :-
317
+ prolog_canonical_source(Source, Src),
318
+ ( last_modified(Source, Modified)
319
+ -> ( source(Src, Modified)
320
+ -> true
321
+ ; xref_clean(Src),
322
+ assert(source(Src, Modified)),
323
+ do_xref(Src, Options)
324
+ )
325
+ ; xref_clean(Src),
326
+ get_time(Now),
327
+ assert(source(Src, Now)),
328
+ do_xref(Src, Options)
329
+ ).
330
+
331
+ do_xref(Src, Options) :-
332
+ must_be(list, Options),
333
+ setup_call_cleanup(
334
+ xref_setup(Src, In, Options, State),
335
+ collect(Src, Src, In, Options),
336
+ xref_cleanup(State)).
337
+
338
+ last_modified(Source, Modified) :-
339
+ prolog:xref_source_time(Source, Modified),
340
+ !.
341
+ last_modified(Source, Modified) :-
342
+ atom(Source),
343
+ \+ is_global_url(Source),
344
+ exists_file(Source),
345
+ time_file(Source, Modified).
346
+
347
+ is_global_url(File) :-
348
+ sub_atom(File, B, _, _, '://'),
349
+ !,
350
+ B > 1,
351
+ sub_atom(File, 0, B, _, Scheme),
352
+ atom_codes(Scheme, Codes),
353
+ maplist(between(0'a, 0'z), Codes).
354
+
355
+ xref_setup(Src, In, Options, state(CleanIn, Dialect, Xref, [SRef|HRefs])) :-
356
+ maplist(assert_option(Src), Options),
357
+ assert_default_options(Src),
358
+ current_prolog_flag(emulated_dialect, Dialect),
359
+ ( option(stream(Stream), Options)
360
+ -> In = Stream,
361
+ CleanIn = true
362
+ ; prolog_open_source(Src, In),
363
+ CleanIn = prolog_close_source(In)
364
+ ),
365
+ set_initial_mode(In, Options),
366
+ asserta(xref_input(Src, In), SRef),
367
+ set_xref(Xref),
368
+ ( verbose(Src)
369
+ -> HRefs = []
370
+ ; asserta((user:thread_message_hook(_,Level,_) :-
371
+ hide_message(Level)),
372
+ Ref),
373
+ HRefs = [Ref]
374
+ ).
375
+
376
+ hide_message(warning).
377
+ hide_message(error).
378
+ hide_message(informational).
379
+
380
+ assert_option(_, Var) :-
381
+ var(Var),
382
+ !,
383
+ instantiation_error(Var).
384
+ assert_option(Src, silent(Boolean)) :-
385
+ !,
386
+ must_be(boolean, Boolean),
387
+ assert(xoption(Src, silent(Boolean))).
388
+ assert_option(Src, register_called(Which)) :-
389
+ !,
390
+ must_be(oneof([all,non_iso,non_built_in]), Which),
391
+ assert(xoption(Src, register_called(Which))).
392
+ assert_option(Src, comments(CommentHandling)) :-
393
+ !,
394
+ must_be(oneof([store,collect,ignore]), CommentHandling),
395
+ assert(xoption(Src, comments(CommentHandling))).
396
+ assert_option(Src, module(Module)) :-
397
+ !,
398
+ must_be(atom, Module),
399
+ assert(xoption(Src, module(Module))).
400
+ assert_option(Src, process_include(Boolean)) :-
401
+ !,
402
+ must_be(boolean, Boolean),
403
+ assert(xoption(Src, process_include(Boolean))).
404
+ assert_option(_, _).
405
+
406
+ assert_default_options(Src) :-
407
+ ( xref_option_default(Opt),
408
+ generalise_term(Opt, Gen),
409
+ ( xoption(Src, Gen)
410
+ -> true
411
+ ; assertz(xoption(Src, Opt))
412
+ ),
413
+ fail
414
+ ; true
415
+ ).
416
+
417
+ xref_option_default(silent(false)).
418
+ xref_option_default(register_called(non_built_in)).
419
+ xref_option_default(comments(collect)).
420
+ xref_option_default(process_include(true)).
421
+
422
+ %! xref_cleanup(+State) is det.
423
+ %
424
+ % Restore processing state according to the saved State.
425
+
426
+ xref_cleanup(state(CleanIn, Dialect, Xref, Refs)) :-
427
+ call(CleanIn),
428
+ set_prolog_flag(emulated_dialect, Dialect),
429
+ set_prolog_flag(xref, Xref),
430
+ maplist(erase, Refs).
431
+
432
+ set_xref(Xref) :-
433
+ current_prolog_flag(xref, Xref),
434
+ set_prolog_flag(xref, true).
435
+
436
+ :- meta_predicate
437
+ with_xref(0).
438
+
439
+ with_xref(Goal) :-
440
+ current_prolog_flag(xref, Xref),
441
+ ( Xref == true
442
+ -> call(Goal)
443
+ ; setup_call_cleanup(
444
+ set_prolog_flag(xref, true),
445
+ Goal,
446
+ set_prolog_flag(xref, Xref))
447
+ ).
448
+
449
+
450
+ %! set_initial_mode(+Stream, +Options) is det.
451
+ %
452
+ % Set the initial mode for processing this file in the
453
+ % cross-referencer. If the file is loaded, we use information from
454
+ % the previous load context, setting the appropriate module and
455
+ % dialect.
456
+
457
+ set_initial_mode(_Stream, Options) :-
458
+ option(module(Module), Options),
459
+ !,
460
+ '$set_source_module'(Module).
461
+ set_initial_mode(Stream, _) :-
462
+ stream_property(Stream, file_name(Path)),
463
+ source_file_property(Path, load_context(M, _, Opts)),
464
+ !,
465
+ '$set_source_module'(M),
466
+ ( option(dialect(Dialect), Opts)
467
+ -> expects_dialect(Dialect)
468
+ ; true
469
+ ).
470
+ set_initial_mode(_, _) :-
471
+ '$set_source_module'(user).
472
+
473
+ %! xref_input_stream(-Stream) is det.
474
+ %
475
+ % Current input stream for cross-referencer.
476
+
477
+ xref_input_stream(Stream) :-
478
+ xref_input(_, Var),
479
+ !,
480
+ Stream = Var.
481
+
482
+ %! xref_push_op(Source, +Prec, +Type, :Name)
483
+ %
484
+ % Define operators into the default source module and register
485
+ % them to be undone by pop_operators/0.
486
+
487
+ xref_push_op(Src, P, T, N0) :-
488
+ '$current_source_module'(M0),
489
+ strip_module(M0:N0, M, N),
490
+ ( is_list(N),
491
+ N \== []
492
+ -> maplist(push_op(Src, P, T, M), N)
493
+ ; push_op(Src, P, T, M, N)
494
+ ).
495
+
496
+ push_op(Src, P, T, M0, N0) :-
497
+ strip_module(M0:N0, M, N),
498
+ Name = M:N,
499
+ valid_op(op(P,T,Name)),
500
+ push_op(P, T, Name),
501
+ assert_op(Src, op(P,T,Name)),
502
+ debug(xref(op), ':- ~w.', [op(P,T,Name)]).
503
+
504
+ valid_op(op(P,T,M:N)) :-
505
+ atom(M),
506
+ valid_op_name(N),
507
+ integer(P),
508
+ between(0, 1200, P),
509
+ atom(T),
510
+ op_type(T).
511
+
512
+ valid_op_name(N) :-
513
+ atom(N),
514
+ !.
515
+ valid_op_name(N) :-
516
+ N == [].
517
+
518
+ op_type(xf).
519
+ op_type(yf).
520
+ op_type(fx).
521
+ op_type(fy).
522
+ op_type(xfx).
523
+ op_type(xfy).
524
+ op_type(yfx).
525
+
526
+ %! xref_set_prolog_flag(+Flag, +Value, +Src, +Line)
527
+ %
528
+ % Called when a directive sets a Prolog flag.
529
+
530
+ xref_set_prolog_flag(Flag, Value, Src, Line) :-
531
+ atom(Flag),
532
+ !,
533
+ assertz(xflag(Flag, Value, Src, Line)).
534
+ xref_set_prolog_flag(_, _, _, _).
535
+
536
+ %! xref_clean(+Source) is det.
537
+ %
538
+ % Reset the database for the given source.
539
+
540
+ xref_clean(Source) :-
541
+ prolog_canonical_source(Source, Src),
542
+ retractall(called(_, Src, _Origin, _Cond, _Line)),
543
+ retractall(dynamic(_, Src, Line)),
544
+ retractall(multifile(_, Src, Line)),
545
+ retractall(public(_, Src, Line)),
546
+ retractall(declared(_, _, Src, Line)),
547
+ retractall(defined(_, Src, Line)),
548
+ retractall(meta_goal(_, _, Src)),
549
+ retractall(foreign(_, Src, Line)),
550
+ retractall(constraint(_, Src, Line)),
551
+ retractall(imported(_, Src, _From)),
552
+ retractall(exported(_, Src)),
553
+ retractall(uses_file(_, Src, _)),
554
+ retractall(xmodule(_, Src)),
555
+ retractall(xop(Src, _)),
556
+ retractall(grammar_rule(_, Src)),
557
+ retractall(xoption(Src, _)),
558
+ retractall(xflag(_Name, _Value, Src, Line)),
559
+ retractall(source(Src, _)),
560
+ retractall(used_class(_, Src)),
561
+ retractall(defined_class(_, _, _, Src, _)),
562
+ retractall(mode(_, Src)),
563
+ retractall(module_comment(Src, _, _)),
564
+ retractall(pred_comment(_, Src, _, _)),
565
+ retractall(pred_comment_link(_, Src, _)),
566
+ retractall(pred_mode(_, Src, _)).
567
+
568
+
569
+ /*******************************
570
+ * READ RESULTS *
571
+ *******************************/
572
+
573
+ %! xref_current_source(?Source)
574
+ %
575
+ % Check what sources have been analysed.
576
+
577
+ xref_current_source(Source) :-
578
+ source(Source, _Time).
579
+
580
+
581
+ %! xref_done(+Source, -Time) is det.
582
+ %
583
+ % Cross-reference executed at Time
584
+
585
+ xref_done(Source, Time) :-
586
+ prolog_canonical_source(Source, Src),
587
+ source(Src, Time).
588
+
589
+
590
+ %! xref_called(?Source, ?Called, ?By) is nondet.
591
+ %! xref_called(?Source, ?Called, ?By, ?Cond) is nondet.
592
+ %! xref_called(?Source, ?Called, ?By, ?Cond, ?Line) is nondet.
593
+ %
594
+ % True when By is called from Called in Source. Note that
595
+ % xref_called/3 and xref_called/4 use distinct/2 to return only
596
+ % distinct `Called-By` pairs. The xref_called/5 version may return
597
+ % duplicate `Called-By` if Called is called from multiple clauses in
598
+ % By, but at most one call per clause.
599
+ %
600
+ % @arg By is a head term or one of the reserved terms
601
+ % `'<directive>'(Line)` or `'<public>'(Line)`, indicating the call
602
+ % is from an (often initialization/1) directive or there is a public/1
603
+ % directive that claims the predicate is called from in some
604
+ % untractable way.
605
+ % @arg Cond is the (accumulated) condition as defined by
606
+ % ``:- if(Cond)`` under which the calling code is compiled.
607
+ % @arg Line is the _start line_ of the calling clause.
608
+
609
+ xref_called(Source, Called, By) :-
610
+ xref_called(Source, Called, By, _).
611
+
612
+ xref_called(Source, Called, By, Cond) :-
613
+ canonical_source(Source, Src),
614
+ distinct(Called-By, called(Called, Src, By, Cond, _)).
615
+
616
+ xref_called(Source, Called, By, Cond, Line) :-
617
+ canonical_source(Source, Src),
618
+ called(Called, Src, By, Cond, Line).
619
+
620
+ %! xref_defined(?Source, +Goal, ?How) is nondet.
621
+ %
622
+ % Test if Goal is accessible in Source. If this is the case, How
623
+ % specifies the reason why the predicate is accessible. Note that
624
+ % this predicate does not deal with built-in or global predicates,
625
+ % just locally defined and imported ones. How is one of of the
626
+ % terms below. Location is one of Line (an integer) or File:Line
627
+ % if the definition comes from an included (using :-
628
+ % include(File)) directive.
629
+ %
630
+ % * dynamic(Location)
631
+ % * thread_local(Location)
632
+ % * multifile(Location)
633
+ % * public(Location)
634
+ % * local(Location)
635
+ % * foreign(Location)
636
+ % * constraint(Location)
637
+ % * imported(From)
638
+ % * dcg
639
+
640
+ xref_defined(Source, Called, How) :-
641
+ nonvar(Source),
642
+ !,
643
+ canonical_source(Source, Src),
644
+ xref_defined2(How, Src, Called).
645
+ xref_defined(Source, Called, How) :-
646
+ xref_defined2(How, Src, Called),
647
+ canonical_source(Source, Src).
648
+
649
+ xref_defined2(dynamic(Line), Src, Called) :-
650
+ dynamic(Called, Src, Line).
651
+ xref_defined2(thread_local(Line), Src, Called) :-
652
+ thread_local(Called, Src, Line).
653
+ xref_defined2(multifile(Line), Src, Called) :-
654
+ multifile(Called, Src, Line).
655
+ xref_defined2(public(Line), Src, Called) :-
656
+ public(Called, Src, Line).
657
+ xref_defined2(local(Line), Src, Called) :-
658
+ defined(Called, Src, Line).
659
+ xref_defined2(foreign(Line), Src, Called) :-
660
+ foreign(Called, Src, Line).
661
+ xref_defined2(constraint(Line), Src, Called) :-
662
+ ( constraint(Called, Src, Line)
663
+ -> true
664
+ ; declared(Called, chr_constraint, Src, Line)
665
+ ).
666
+ xref_defined2(imported(From), Src, Called) :-
667
+ imported(Called, Src, From).
668
+ xref_defined2(dcg, Src, Called) :-
669
+ grammar_rule(Called, Src).
670
+
671
+
672
+ %! xref_definition_line(+How, -Line)
673
+ %
674
+ % If the 3th argument of xref_defined contains line info, return
675
+ % this in Line.
676
+
677
+ xref_definition_line(local(Line), Line).
678
+ xref_definition_line(dynamic(Line), Line).
679
+ xref_definition_line(thread_local(Line), Line).
680
+ xref_definition_line(multifile(Line), Line).
681
+ xref_definition_line(public(Line), Line).
682
+ xref_definition_line(constraint(Line), Line).
683
+ xref_definition_line(foreign(Line), Line).
684
+
685
+
686
+ %! xref_exported(?Source, ?Head) is nondet.
687
+ %
688
+ % True when Source exports Head.
689
+
690
+ xref_exported(Source, Called) :-
691
+ prolog_canonical_source(Source, Src),
692
+ exported(Called, Src).
693
+
694
+ %! xref_module(?Source, ?Module) is nondet.
695
+ %
696
+ % True if Module is defined in Source.
697
+
698
+ xref_module(Source, Module) :-
699
+ nonvar(Source),
700
+ !,
701
+ prolog_canonical_source(Source, Src),
702
+ xmodule(Module, Src).
703
+ xref_module(Source, Module) :-
704
+ xmodule(Module, Src),
705
+ prolog_canonical_source(Source, Src).
706
+
707
+ %! xref_uses_file(?Source, ?Spec, ?Path) is nondet.
708
+ %
709
+ % True when Source tries to load a file using Spec.
710
+ %
711
+ % @param Spec is a specification for absolute_file_name/3
712
+ % @param Path is either an absolute file name of the target
713
+ % file or the atom =|<not_found>|=.
714
+
715
+ xref_uses_file(Source, Spec, Path) :-
716
+ prolog_canonical_source(Source, Src),
717
+ uses_file(Spec, Src, Path).
718
+
719
+ %! xref_op(?Source, Op) is nondet.
720
+ %
721
+ % Give the operators active inside the module. This is intended to
722
+ % setup the environment for incremental parsing of a term from the
723
+ % source-file.
724
+ %
725
+ % @param Op Term of the form op(Priority, Type, Name)
726
+
727
+ xref_op(Source, Op) :-
728
+ prolog_canonical_source(Source, Src),
729
+ xop(Src, Op).
730
+
731
+ %! xref_prolog_flag(?Source, ?Flag, ?Value, ?Line) is nondet.
732
+ %
733
+ % True when Flag is set to Value at Line in Source. This is
734
+ % intended to support incremental parsing of a term from the
735
+ % source-file.
736
+
737
+ xref_prolog_flag(Source, Flag, Value, Line) :-
738
+ prolog_canonical_source(Source, Src),
739
+ xflag(Flag, Value, Src, Line).
740
+
741
+ xref_built_in(Head) :-
742
+ system_predicate(Head).
743
+
744
+ xref_used_class(Source, Class) :-
745
+ prolog_canonical_source(Source, Src),
746
+ used_class(Class, Src).
747
+
748
+ xref_defined_class(Source, Class, local(Line, Super, Summary)) :-
749
+ prolog_canonical_source(Source, Src),
750
+ defined_class(Class, Super, Summary, Src, Line),
751
+ integer(Line),
752
+ !.
753
+ xref_defined_class(Source, Class, file(File)) :-
754
+ prolog_canonical_source(Source, Src),
755
+ defined_class(Class, _, _, Src, file(File)).
756
+
757
+ :- thread_local
758
+ current_cond/1,
759
+ source_line/1,
760
+ current_test_unit/2.
761
+
762
+ current_source_line(Line) :-
763
+ source_line(Var),
764
+ !,
765
+ Line = Var.
766
+
767
+ %! collect(+Source, +File, +Stream, +Options)
768
+ %
769
+ % Process data from Source. If File \== Source, we are processing
770
+ % an included file. Stream is the stream from which we read the
771
+ % program.
772
+
773
+ collect(Src, File, In, Options) :-
774
+ ( Src == File
775
+ -> SrcSpec = Line
776
+ ; SrcSpec = (File:Line)
777
+ ),
778
+ ( current_prolog_flag(xref_store_comments, OldStore)
779
+ -> true
780
+ ; OldStore = false
781
+ ),
782
+ option(comments(CommentHandling), Options, collect),
783
+ ( CommentHandling == ignore
784
+ -> CommentOptions = [],
785
+ Comments = []
786
+ ; CommentHandling == store
787
+ -> CommentOptions = [ process_comment(true) ],
788
+ Comments = [],
789
+ set_prolog_flag(xref_store_comments, true)
790
+ ; CommentOptions = [ comments(Comments) ]
791
+ ),
792
+ repeat,
793
+ E = error(_,_),
794
+ catch(prolog_read_source_term(
795
+ In, Term, Expanded,
796
+ [ term_position(TermPos)
797
+ | CommentOptions
798
+ ]),
799
+ E, report_syntax_error(E, Src, [])),
800
+ update_condition(Term),
801
+ stream_position_data(line_count, TermPos, Line),
802
+ setup_call_cleanup(
803
+ asserta(source_line(SrcSpec), Ref),
804
+ catch(process(Expanded, Comments, Term, TermPos, Src, EOF),
805
+ E, print_message(error, E)),
806
+ erase(Ref)),
807
+ EOF == true,
808
+ !,
809
+ set_prolog_flag(xref_store_comments, OldStore).
810
+
811
+ report_syntax_error(_, _, Options) :-
812
+ option(silent(true), Options),
813
+ !,
814
+ fail.
815
+ report_syntax_error(E, Src, _Options) :-
816
+ ( verbose(Src)
817
+ -> print_message(error, E)
818
+ ; true
819
+ ),
820
+ fail.
821
+
822
+ %! update_condition(+Term) is det.
823
+ %
824
+ % Update the condition under which the current code is compiled.
825
+
826
+ update_condition((:-Directive)) :-
827
+ !,
828
+ update_cond(Directive).
829
+ update_condition(_).
830
+
831
+ update_cond(if(Cond)) :-
832
+ !,
833
+ asserta(current_cond(Cond)).
834
+ update_cond(else) :-
835
+ retract(current_cond(C0)),
836
+ !,
837
+ assert(current_cond(\+C0)).
838
+ update_cond(elif(Cond)) :-
839
+ retract(current_cond(C0)),
840
+ !,
841
+ assert(current_cond((\+C0,Cond))).
842
+ update_cond(endif) :-
843
+ retract(current_cond(_)),
844
+ !.
845
+ update_cond(_).
846
+
847
+ %! current_condition(-Condition) is det.
848
+ %
849
+ % Condition is the current compilation condition as defined by the
850
+ % :- if/1 directive and friends.
851
+
852
+ current_condition(Condition) :-
853
+ \+ current_cond(_),
854
+ !,
855
+ Condition = true.
856
+ current_condition(Condition) :-
857
+ findall(C, current_cond(C), List),
858
+ list_to_conj(List, Condition).
859
+
860
+ list_to_conj([], true).
861
+ list_to_conj([C], C) :- !.
862
+ list_to_conj([H|T], (H,C)) :-
863
+ list_to_conj(T, C).
864
+
865
+
866
+ /*******************************
867
+ * PROCESS *
868
+ *******************************/
869
+
870
+ %! process(+Expanded, +Comments, +Term, +TermPos, +Src, -EOF) is det.
871
+ %
872
+ % Process a source term that has been subject to term expansion as
873
+ % well as its optional leading structured comments.
874
+ %
875
+ % @arg TermPos is the term position that describes the start of the
876
+ % term. We need this to find _leading_ comments.
877
+ % @arg EOF is unified with a boolean to indicate whether or not
878
+ % processing was stopped because `end_of_file` was processed.
879
+
880
+ process(Expanded, Comments, Term0, TermPos, Src, EOF) :-
881
+ is_list(Expanded), % term_expansion into list.
882
+ !,
883
+ ( member(Term, Expanded),
884
+ process(Term, Term0, Src),
885
+ Term == end_of_file
886
+ -> EOF = true
887
+ ; EOF = false
888
+ ),
889
+ xref_comments(Comments, TermPos, Src).
890
+ process(end_of_file, _, _, _, _, true) :-
891
+ !.
892
+ process(Term, Comments, Term0, TermPos, Src, false) :-
893
+ process(Term, Term0, Src),
894
+ xref_comments(Comments, TermPos, Src).
895
+
896
+ %! process(+Term, +Term0, +Src) is det.
897
+
898
+ process(_, Term0, _) :-
899
+ ignore_raw_term(Term0),
900
+ !.
901
+ process(Head :- Body, Head0 --> _, Src) :-
902
+ pi_head(F/A, Head),
903
+ pi_head(F/A0, Head0),
904
+ A =:= A0 + 2,
905
+ !,
906
+ assert_grammar_rule(Src, Head),
907
+ process((Head :- Body), Src).
908
+ process(Term, _Term0, Src) :-
909
+ process(Term, Src).
910
+
911
+ ignore_raw_term((:- predicate_options(_,_,_))).
912
+
913
+ %! process(+Term, +Src) is det.
914
+
915
+ process(Var, _) :-
916
+ var(Var),
917
+ !. % Warn?
918
+ process(end_of_file, _) :- !.
919
+ process((:- Directive), Src) :-
920
+ !,
921
+ process_directive(Directive, Src),
922
+ !.
923
+ process((?- Directive), Src) :-
924
+ !,
925
+ process_directive(Directive, Src),
926
+ !.
927
+ process((Head :- Body), Src) :-
928
+ !,
929
+ assert_defined(Src, Head),
930
+ process_body(Body, Head, Src).
931
+ process((Left => Body), Src) :-
932
+ !,
933
+ ( nonvar(Left),
934
+ Left = (Head, Guard)
935
+ -> assert_defined(Src, Head),
936
+ process_body(Guard, Head, Src),
937
+ process_body(Body, Head, Src)
938
+ ; assert_defined(Src, Left),
939
+ process_body(Body, Left, Src)
940
+ ).
941
+ process(?=>(Head, Body), Src) :-
942
+ !,
943
+ assert_defined(Src, Head),
944
+ process_body(Body, Head, Src).
945
+ process('$source_location'(_File, _Line):Clause, Src) :-
946
+ !,
947
+ process(Clause, Src).
948
+ process(Term, Src) :-
949
+ process_chr(Term, Src),
950
+ !.
951
+ process(M:(Head :- Body), Src) :-
952
+ !,
953
+ process((M:Head :- M:Body), Src).
954
+ process(Head, Src) :-
955
+ assert_defined(Src, Head).
956
+
957
+
958
+ /*******************************
959
+ * COMMENTS *
960
+ *******************************/
961
+
962
+ %! xref_comments(+Comments, +FilePos, +Src) is det.
963
+
964
+ xref_comments([], _Pos, _Src).
965
+ :- if(current_predicate(parse_comment/3)).
966
+ xref_comments([Pos-Comment|T], TermPos, Src) :-
967
+ ( Pos @> TermPos % comments inside term
968
+ -> true
969
+ ; stream_position_data(line_count, Pos, Line),
970
+ FilePos = Src:Line,
971
+ ( parse_comment(Comment, FilePos, Parsed)
972
+ -> assert_comments(Parsed, Src)
973
+ ; true
974
+ ),
975
+ xref_comments(T, TermPos, Src)
976
+ ).
977
+
978
+ assert_comments([], _).
979
+ assert_comments([H|T], Src) :-
980
+ assert_comment(H, Src),
981
+ assert_comments(T, Src).
982
+
983
+ assert_comment(section(_Id, Title, Comment), Src) :-
984
+ assertz(module_comment(Src, Title, Comment)).
985
+ assert_comment(predicate(PI, Summary, Comment), Src) :-
986
+ pi_to_head(PI, Src, Head),
987
+ assertz(pred_comment(Head, Src, Summary, Comment)).
988
+ assert_comment(link(PI, PITo), Src) :-
989
+ pi_to_head(PI, Src, Head),
990
+ pi_to_head(PITo, Src, HeadTo),
991
+ assertz(pred_comment_link(Head, Src, HeadTo)).
992
+ assert_comment(mode(Head, Det), Src) :-
993
+ assertz(pred_mode(Head, Src, Det)).
994
+
995
+ pi_to_head(PI, Src, Head) :-
996
+ pi_to_head(PI, Head0),
997
+ ( Head0 = _:_
998
+ -> strip_module(Head0, M, Plain),
999
+ ( xmodule(M, Src)
1000
+ -> Head = Plain
1001
+ ; Head = M:Plain
1002
+ )
1003
+ ; Head = Head0
1004
+ ).
1005
+ :- endif.
1006
+
1007
+ %! xref_comment(?Source, ?Title, ?Comment) is nondet.
1008
+ %
1009
+ % Is true when Source has a section comment with Title and Comment
1010
+
1011
+ xref_comment(Source, Title, Comment) :-
1012
+ canonical_source(Source, Src),
1013
+ module_comment(Src, Title, Comment).
1014
+
1015
+ %! xref_comment(?Source, ?Head, ?Summary, ?Comment) is nondet.
1016
+ %
1017
+ % Is true when Head in Source has the given PlDoc comment.
1018
+
1019
+ xref_comment(Source, Head, Summary, Comment) :-
1020
+ canonical_source(Source, Src),
1021
+ ( pred_comment(Head, Src, Summary, Comment)
1022
+ ; pred_comment_link(Head, Src, HeadTo),
1023
+ pred_comment(HeadTo, Src, Summary, Comment)
1024
+ ).
1025
+
1026
+ %! xref_mode(?Source, ?Mode, ?Det) is nondet.
1027
+ %
1028
+ % Is true when Source provides a predicate with Mode and
1029
+ % determinism.
1030
+
1031
+ xref_mode(Source, Mode, Det) :-
1032
+ canonical_source(Source, Src),
1033
+ pred_mode(Mode, Src, Det).
1034
+
1035
+ %! xref_option(?Source, ?Option) is nondet.
1036
+ %
1037
+ % True when Source was processed using Option. Options are defined
1038
+ % with xref_source/2.
1039
+
1040
+ xref_option(Source, Option) :-
1041
+ canonical_source(Source, Src),
1042
+ xoption(Src, Option).
1043
+
1044
+
1045
+ /********************************
1046
+ * DIRECTIVES *
1047
+ ********************************/
1048
+
1049
+ process_directive(Var, _) :-
1050
+ var(Var),
1051
+ !. % error, but that isn't our business
1052
+ process_directive(Dir, _Src) :-
1053
+ debug(xref(directive), 'Processing :- ~q', [Dir]),
1054
+ fail.
1055
+ process_directive((A,B), Src) :- % TBD: what about other control
1056
+ !,
1057
+ process_directive(A, Src), % structures?
1058
+ process_directive(B, Src).
1059
+ process_directive(List, Src) :-
1060
+ is_list(List),
1061
+ !,
1062
+ process_directive(consult(List), Src).
1063
+ process_directive(use_module(File, Import), Src) :-
1064
+ process_use_module2(File, Import, Src, false).
1065
+ process_directive(autoload(File, Import), Src) :-
1066
+ process_use_module2(File, Import, Src, false).
1067
+ process_directive(require(Import), Src) :-
1068
+ process_requires(Import, Src).
1069
+ process_directive(expects_dialect(Dialect), Src) :-
1070
+ process_directive(use_module(library(dialect/Dialect)), Src),
1071
+ expects_dialect(Dialect).
1072
+ process_directive(reexport(File, Import), Src) :-
1073
+ process_use_module2(File, Import, Src, true).
1074
+ process_directive(reexport(Modules), Src) :-
1075
+ process_use_module(Modules, Src, true).
1076
+ process_directive(autoload(Modules), Src) :-
1077
+ process_use_module(Modules, Src, false).
1078
+ process_directive(use_module(Modules), Src) :-
1079
+ process_use_module(Modules, Src, false).
1080
+ process_directive(consult(Modules), Src) :-
1081
+ process_use_module(Modules, Src, false).
1082
+ process_directive(ensure_loaded(Modules), Src) :-
1083
+ process_use_module(Modules, Src, false).
1084
+ process_directive(load_files(Files, _Options), Src) :-
1085
+ process_use_module(Files, Src, false).
1086
+ process_directive(include(Files), Src) :-
1087
+ process_include(Files, Src).
1088
+ process_directive(dynamic(Dynamic), Src) :-
1089
+ process_predicates(assert_dynamic, Dynamic, Src).
1090
+ process_directive(dynamic(Dynamic, _Options), Src) :-
1091
+ process_predicates(assert_dynamic, Dynamic, Src).
1092
+ process_directive(thread_local(Dynamic), Src) :-
1093
+ process_predicates(assert_thread_local, Dynamic, Src).
1094
+ process_directive(multifile(Dynamic), Src) :-
1095
+ process_predicates(assert_multifile, Dynamic, Src).
1096
+ process_directive(public(Public), Src) :-
1097
+ process_predicates(assert_public, Public, Src).
1098
+ process_directive(export(Export), Src) :-
1099
+ process_predicates(assert_export, Export, Src).
1100
+ process_directive(import(Import), Src) :-
1101
+ process_import(Import, Src).
1102
+ process_directive(module(Module, Export), Src) :-
1103
+ assert_module(Src, Module),
1104
+ assert_module_export(Src, Export).
1105
+ process_directive(module(Module, Export, Import), Src) :-
1106
+ assert_module(Src, Module),
1107
+ assert_module_export(Src, Export),
1108
+ assert_module3(Import, Src).
1109
+ process_directive(begin_tests(Unit, _Options), Src) :-
1110
+ enter_test_unit(Unit, Src).
1111
+ process_directive(begin_tests(Unit), Src) :-
1112
+ enter_test_unit(Unit, Src).
1113
+ process_directive(end_tests(Unit), Src) :-
1114
+ leave_test_unit(Unit, Src).
1115
+ process_directive('$set_source_module'(system), Src) :-
1116
+ assert_module(Src, system). % hack for handling boot/init.pl
1117
+ process_directive(pce_begin_class_definition(Name, Meta, Super, Doc), Src) :-
1118
+ assert_defined_class(Src, Name, Meta, Super, Doc).
1119
+ process_directive(pce_autoload(Name, From), Src) :-
1120
+ assert_defined_class(Src, Name, imported_from(From)).
1121
+
1122
+ process_directive(op(P, A, N), Src) :-
1123
+ xref_push_op(Src, P, A, N).
1124
+ process_directive(set_prolog_flag(Flag, Value), Src) :-
1125
+ ( Flag == character_escapes
1126
+ -> set_prolog_flag(character_escapes, Value)
1127
+ ; true
1128
+ ),
1129
+ current_source_line(Line),
1130
+ xref_set_prolog_flag(Flag, Value, Src, Line).
1131
+ process_directive(style_check(X), _) :-
1132
+ style_check(X).
1133
+ process_directive(encoding(Enc), _) :-
1134
+ ( xref_input_stream(Stream)
1135
+ -> catch(set_stream(Stream, encoding(Enc)), error(_,_), true)
1136
+ ; true % can this happen?
1137
+ ).
1138
+ process_directive(pce_expansion:push_compile_operators, _) :-
1139
+ '$current_source_module'(SM),
1140
+ call(pce_expansion:push_compile_operators(SM)). % call to avoid xref
1141
+ process_directive(pce_expansion:pop_compile_operators, _) :-
1142
+ call(pce_expansion:pop_compile_operators).
1143
+ process_directive(meta_predicate(Meta), Src) :-
1144
+ process_meta_predicate(Meta, Src).
1145
+ process_directive(arithmetic_function(FSpec), Src) :-
1146
+ arith_callable(FSpec, Goal),
1147
+ !,
1148
+ current_source_line(Line),
1149
+ assert_called(Src, '<directive>'(Line), Goal, Line).
1150
+ process_directive(format_predicate(_, Goal), Src) :-
1151
+ !,
1152
+ current_source_line(Line),
1153
+ assert_called(Src, '<directive>'(Line), Goal, Line).
1154
+ process_directive(if(Cond), Src) :-
1155
+ !,
1156
+ current_source_line(Line),
1157
+ assert_called(Src, '<directive>'(Line), Cond, Line).
1158
+ process_directive(elif(Cond), Src) :-
1159
+ !,
1160
+ current_source_line(Line),
1161
+ assert_called(Src, '<directive>'(Line), Cond, Line).
1162
+ process_directive(else, _) :- !.
1163
+ process_directive(endif, _) :- !.
1164
+ process_directive(Goal, Src) :-
1165
+ current_source_line(Line),
1166
+ process_body(Goal, '<directive>'(Line), Src).
1167
+
1168
+ %! process_meta_predicate(+Decl, +Src)
1169
+ %
1170
+ % Create meta_goal/3 facts from the meta-goal declaration.
1171
+
1172
+ process_meta_predicate((A,B), Src) :-
1173
+ !,
1174
+ process_meta_predicate(A, Src),
1175
+ process_meta_predicate(B, Src).
1176
+ process_meta_predicate(Decl, Src) :-
1177
+ process_meta_head(Src, Decl).
1178
+
1179
+ process_meta_head(Src, Decl) :- % swapped arguments for maplist
1180
+ compound(Decl),
1181
+ compound_name_arity(Decl, Name, Arity),
1182
+ compound_name_arity(Head, Name, Arity),
1183
+ meta_args(1, Arity, Decl, Head, Meta),
1184
+ ( ( prolog:meta_goal(Head, _)
1185
+ ; prolog:called_by(Head, _, _, _)
1186
+ ; prolog:called_by(Head, _)
1187
+ ; meta_goal(Head, Meta, _Src)
1188
+ )
1189
+ -> true
1190
+ ; warn_late_meta_predicate(Decl, Src),
1191
+ retractall(meta_goal(Head, _, Src)),
1192
+ assert(meta_goal(Head, Meta, Src))
1193
+ ).
1194
+
1195
+ meta_args(I, Arity, _, _, []) :-
1196
+ I > Arity,
1197
+ !.
1198
+ meta_args(I, Arity, Decl, Head, [H|T]) :- % 0
1199
+ arg(I, Decl, 0),
1200
+ !,
1201
+ arg(I, Head, H),
1202
+ I2 is I + 1,
1203
+ meta_args(I2, Arity, Decl, Head, T).
1204
+ meta_args(I, Arity, Decl, Head, [H|T]) :- % ^
1205
+ arg(I, Decl, ^),
1206
+ !,
1207
+ arg(I, Head, EH),
1208
+ setof_goal(EH, H),
1209
+ I2 is I + 1,
1210
+ meta_args(I2, Arity, Decl, Head, T).
1211
+ meta_args(I, Arity, Decl, Head, [//(H)|T]) :-
1212
+ arg(I, Decl, //),
1213
+ !,
1214
+ arg(I, Head, H),
1215
+ I2 is I + 1,
1216
+ meta_args(I2, Arity, Decl, Head, T).
1217
+ meta_args(I, Arity, Decl, Head, [H+A|T]) :- % I --> H+I
1218
+ arg(I, Decl, A),
1219
+ integer(A), A > 0,
1220
+ !,
1221
+ arg(I, Head, H),
1222
+ I2 is I + 1,
1223
+ meta_args(I2, Arity, Decl, Head, T).
1224
+ meta_args(I, Arity, Decl, Head, Meta) :-
1225
+ I2 is I + 1,
1226
+ meta_args(I2, Arity, Decl, Head, Meta).
1227
+
1228
+
1229
+ warn_late_meta_predicate(Decl, Src) :-
1230
+ xref_called(Src, Decl, By),
1231
+ !,
1232
+ print_message(warning, meta_predicate_after_call(Decl, By)).
1233
+ warn_late_meta_predicate(_, _).
1234
+
1235
+
1236
+ /********************************
1237
+ * BODY *
1238
+ ********************************/
1239
+
1240
+ %! xref_meta(+Source, +Head, -Called) is semidet.
1241
+ %
1242
+ % True when Head calls Called in Source.
1243
+ %
1244
+ % @arg Called is a list of called terms, terms of the form
1245
+ % Term+Extra or terms of the form //(Term).
1246
+
1247
+ xref_meta(Source, Head, Called) :-
1248
+ canonical_source(Source, Src),
1249
+ xref_meta_src(Head, Called, Src).
1250
+
1251
+ %! xref_meta(+Head, -Called) is semidet.
1252
+ %! xref_meta_src(+Head, -Called, +Src) is semidet.
1253
+ %
1254
+ % True when Called is a list of terms called from Head. Each
1255
+ % element in Called can be of the form Term+Int, which means that
1256
+ % Term must be extended with Int additional arguments. The variant
1257
+ % xref_meta/3 first queries the local context.
1258
+ %
1259
+ % @tbd Split predifined in several categories. E.g., the ISO
1260
+ % predicates cannot be redefined.
1261
+ % @tbd Rely on the meta_predicate property for many predicates.
1262
+ % @deprecated New code should use xref_meta/3.
1263
+
1264
+ xref_meta_src(Head, Called, Src) :-
1265
+ meta_goal(Head, Called, Src),
1266
+ !.
1267
+ xref_meta_src(Head, Called, _) :-
1268
+ xref_meta(Head, Called),
1269
+ !.
1270
+ xref_meta_src(Head, Called, _) :-
1271
+ compound(Head),
1272
+ compound_name_arity(Head, Name, Arity),
1273
+ apply_pred(Name),
1274
+ Arity > 5,
1275
+ !,
1276
+ Extra is Arity - 1,
1277
+ arg(1, Head, G),
1278
+ Called = [G+Extra].
1279
+ xref_meta_src(Head, Called, _) :-
1280
+ with_xref(predicate_property('$xref_tmp':Head, meta_predicate(Meta))),
1281
+ !,
1282
+ Meta =.. [_|Args],
1283
+ meta_args(Args, 1, Head, Called).
1284
+
1285
+ meta_args([], _, _, []).
1286
+ meta_args([H0|T0], I, Head, [H|T]) :-
1287
+ xargs(H0, N),
1288
+ !,
1289
+ arg(I, Head, A),
1290
+ ( N == 0
1291
+ -> H = A
1292
+ ; H = (A+N)
1293
+ ),
1294
+ I2 is I+1,
1295
+ meta_args(T0, I2, Head, T).
1296
+ meta_args([_|T0], I, Head, T) :-
1297
+ I2 is I+1,
1298
+ meta_args(T0, I2, Head, T).
1299
+
1300
+ xargs(N, N) :- integer(N), !.
1301
+ xargs(//, 2).
1302
+ xargs(^, 0).
1303
+
1304
+ apply_pred(call). % built-in
1305
+ apply_pred(maplist). % library(apply_macros)
1306
+
1307
+ xref_meta((A, B), [A, B]).
1308
+ xref_meta((A; B), [A, B]).
1309
+ xref_meta((A| B), [A, B]).
1310
+ xref_meta((A -> B), [A, B]).
1311
+ xref_meta((A *-> B), [A, B]).
1312
+ xref_meta(findall(_V,G,_L), [G]).
1313
+ xref_meta(findall(_V,G,_L,_T), [G]).
1314
+ xref_meta(findnsols(_N,_V,G,_L), [G]).
1315
+ xref_meta(findnsols(_N,_V,G,_L,_T), [G]).
1316
+ xref_meta(setof(_V, EG, _L), [G]) :-
1317
+ setof_goal(EG, G).
1318
+ xref_meta(bagof(_V, EG, _L), [G]) :-
1319
+ setof_goal(EG, G).
1320
+ xref_meta(forall(A, B), [A, B]).
1321
+ xref_meta(maplist(G,_), [G+1]).
1322
+ xref_meta(maplist(G,_,_), [G+2]).
1323
+ xref_meta(maplist(G,_,_,_), [G+3]).
1324
+ xref_meta(maplist(G,_,_,_,_), [G+4]).
1325
+ xref_meta(map_list_to_pairs(G,_,_), [G+2]).
1326
+ xref_meta(map_assoc(G, _), [G+1]).
1327
+ xref_meta(map_assoc(G, _, _), [G+2]).
1328
+ xref_meta(checklist(G, _L), [G+1]).
1329
+ xref_meta(sublist(G, _, _), [G+1]).
1330
+ xref_meta(include(G, _, _), [G+1]).
1331
+ xref_meta(exclude(G, _, _), [G+1]).
1332
+ xref_meta(partition(G, _, _, _, _), [G+2]).
1333
+ xref_meta(partition(G, _, _, _),[G+1]).
1334
+ xref_meta(call(G), [G]).
1335
+ xref_meta(call(G, _), [G+1]).
1336
+ xref_meta(call(G, _, _), [G+2]).
1337
+ xref_meta(call(G, _, _, _), [G+3]).
1338
+ xref_meta(call(G, _, _, _, _), [G+4]).
1339
+ xref_meta(not(G), [G]).
1340
+ xref_meta(notrace(G), [G]).
1341
+ xref_meta('$notrace'(G), [G]).
1342
+ xref_meta(\+(G), [G]).
1343
+ xref_meta(ignore(G), [G]).
1344
+ xref_meta(once(G), [G]).
1345
+ xref_meta(initialization(G), [G]).
1346
+ xref_meta(initialization(G,_), [G]).
1347
+ xref_meta(retract(Rule), [G]) :- head_of(Rule, G).
1348
+ xref_meta(clause(G, _), [G]).
1349
+ xref_meta(clause(G, _, _), [G]).
1350
+ xref_meta(phrase(G, _A), [//(G)]).
1351
+ xref_meta(phrase(G, _A, _R), [//(G)]).
1352
+ xref_meta(call_dcg(G, _A, _R), [//(G)]).
1353
+ xref_meta(phrase_from_file(G,_),[//(G)]).
1354
+ xref_meta(catch(A, _, B), [A, B]).
1355
+ xref_meta(catch_with_backtrace(A, _, B), [A, B]).
1356
+ xref_meta(thread_create(A,_,_), [A]).
1357
+ xref_meta(thread_create(A,_), [A]).
1358
+ xref_meta(thread_signal(_,A), [A]).
1359
+ xref_meta(thread_idle(A,_), [A]).
1360
+ xref_meta(thread_at_exit(A), [A]).
1361
+ xref_meta(thread_initialization(A), [A]).
1362
+ xref_meta(engine_create(_,A,_), [A]).
1363
+ xref_meta(engine_create(_,A,_,_), [A]).
1364
+ xref_meta(transaction(A), [A]).
1365
+ xref_meta(transaction(A,B,_), [A,B]).
1366
+ xref_meta(snapshot(A), [A]).
1367
+ xref_meta(predsort(A,_,_), [A+3]).
1368
+ xref_meta(call_cleanup(A, B), [A, B]).
1369
+ xref_meta(call_cleanup(A, _, B),[A, B]).
1370
+ xref_meta(setup_call_cleanup(A, B, C),[A, B, C]).
1371
+ xref_meta(setup_call_catcher_cleanup(A, B, _, C),[A, B, C]).
1372
+ xref_meta(call_residue_vars(A,_), [A]).
1373
+ xref_meta(with_mutex(_,A), [A]).
1374
+ xref_meta(assume(G), [G]). % library(debug)
1375
+ xref_meta(assertion(G), [G]). % library(debug)
1376
+ xref_meta(freeze(_, G), [G]).
1377
+ xref_meta(when(C, A), [C, A]).
1378
+ xref_meta(time(G), [G]). % development system
1379
+ xref_meta(call_time(G, _), [G]). % development system
1380
+ xref_meta(call_time(G, _, _), [G]). % development system
1381
+ xref_meta(profile(G), [G]).
1382
+ xref_meta(at_halt(G), [G]).
1383
+ xref_meta(call_with_time_limit(_, G), [G]).
1384
+ xref_meta(call_with_depth_limit(G, _, _), [G]).
1385
+ xref_meta(call_with_inference_limit(G, _, _), [G]).
1386
+ xref_meta(alarm(_, G, _), [G]).
1387
+ xref_meta(alarm(_, G, _, _), [G]).
1388
+ xref_meta('$add_directive_wic'(G), [G]).
1389
+ xref_meta(with_output_to(_, G), [G]).
1390
+ xref_meta(if(G), [G]).
1391
+ xref_meta(elif(G), [G]).
1392
+ xref_meta(meta_options(G,_,_), [G+1]).
1393
+ xref_meta(on_signal(_,_,H), [H+1]) :- H \== default.
1394
+ xref_meta(distinct(G), [G]). % library(solution_sequences)
1395
+ xref_meta(distinct(_, G), [G]).
1396
+ xref_meta(order_by(_, G), [G]).
1397
+ xref_meta(limit(_, G), [G]).
1398
+ xref_meta(offset(_, G), [G]).
1399
+ xref_meta(reset(G,_,_), [G]).
1400
+ xref_meta(prolog_listen(Ev,G), [G+N]) :- event_xargs(Ev, N).
1401
+ xref_meta(prolog_listen(Ev,G,_),[G+N]) :- event_xargs(Ev, N).
1402
+ xref_meta(tnot(G), [G]).
1403
+ xref_meta(not_exists(G), [G]).
1404
+ xref_meta(with_tty_raw(G), [G]).
1405
+ xref_meta(residual_goals(G), [G+2]).
1406
+
1407
+ % XPCE meta-predicates
1408
+ xref_meta(pce_global(_, new(_)), _) :- !, fail.
1409
+ xref_meta(pce_global(_, B), [B+1]).
1410
+ xref_meta(ifmaintainer(G), [G]). % used in manual
1411
+ xref_meta(listen(_, G), [G]). % library(broadcast)
1412
+ xref_meta(listen(_, _, G), [G]).
1413
+ xref_meta(in_pce_thread(G), [G]).
1414
+
1415
+ xref_meta(G, Meta) :- % call user extensions
1416
+ prolog:meta_goal(G, Meta).
1417
+ xref_meta(G, Meta) :- % Generated from :- meta_predicate
1418
+ meta_goal(G, Meta, _Src).
1419
+
1420
+ setof_goal(EG, G) :-
1421
+ var(EG), !, G = EG.
1422
+ setof_goal(_^EG, G) :-
1423
+ !,
1424
+ setof_goal(EG, G).
1425
+ setof_goal(G, G).
1426
+
1427
+ event_xargs(abort, 0).
1428
+ event_xargs(erase, 1).
1429
+ event_xargs(break, 3).
1430
+ event_xargs(frame_finished, 1).
1431
+ event_xargs(thread_exit, 1).
1432
+ event_xargs(this_thread_exit, 0).
1433
+ event_xargs(PI, 2) :- pi_to_head(PI, _).
1434
+
1435
+ %! head_of(+Rule, -Head)
1436
+ %
1437
+ % Get the head for a retract call.
1438
+
1439
+ head_of(Var, _) :-
1440
+ var(Var), !, fail.
1441
+ head_of((Head :- _), Head).
1442
+ head_of(Head, Head).
1443
+
1444
+ %! xref_hook(?Callable)
1445
+ %
1446
+ % Definition of known hooks. Hooks that can be called in any
1447
+ % module are unqualified. Other hooks are qualified with the
1448
+ % module where they are called.
1449
+
1450
+ xref_hook(Hook) :-
1451
+ prolog:hook(Hook).
1452
+ xref_hook(Hook) :-
1453
+ hook(Hook).
1454
+
1455
+
1456
+ hook(attr_portray_hook(_,_)).
1457
+ hook(attr_unify_hook(_,_)).
1458
+ hook(attribute_goals(_,_,_)).
1459
+ hook(goal_expansion(_,_)).
1460
+ hook(term_expansion(_,_)).
1461
+ hook(goal_expansion(_,_,_,_)).
1462
+ hook(term_expansion(_,_,_,_)).
1463
+ hook(resource(_,_,_)).
1464
+ hook('$pred_option'(_,_,_,_)).
1465
+ hook('$nowarn_autoload'(_,_)).
1466
+
1467
+ hook(emacs_prolog_colours:goal_classification(_,_)).
1468
+ hook(emacs_prolog_colours:goal_colours(_,_)).
1469
+ hook(emacs_prolog_colours:identify(_,_)).
1470
+ hook(emacs_prolog_colours:style(_,_)).
1471
+ hook(emacs_prolog_colours:term_colours(_,_)).
1472
+ hook(pce_principal:get_implementation(_,_,_,_)).
1473
+ hook(pce_principal:pce_class(_,_,_,_,_,_)).
1474
+ hook(pce_principal:pce_lazy_get_method(_,_,_)).
1475
+ hook(pce_principal:pce_lazy_send_method(_,_,_)).
1476
+ hook(pce_principal:pce_uses_template(_,_)).
1477
+ hook(pce_principal:send_implementation(_,_,_)).
1478
+ hook(predicate_options:option_decl(_,_,_)).
1479
+ hook(prolog:debug_control_hook(_)).
1480
+ hook(prolog:error_message(_,_,_)).
1481
+ hook(prolog:expand_answer(_,_,_)).
1482
+ hook(prolog:general_exception(_,_)).
1483
+ hook(prolog:help_hook(_)).
1484
+ hook(prolog:locate_clauses(_,_)).
1485
+ hook(prolog:message(_,_,_)).
1486
+ hook(prolog:message_context(_,_,_)).
1487
+ hook(prolog:message_line_element(_,_)).
1488
+ hook(prolog:message_location(_,_,_)).
1489
+ hook(prolog:predicate_summary(_,_)).
1490
+ hook(prolog:prolog_exception_hook(_,_,_,_,_)).
1491
+ hook(prolog:residual_goals(_,_)).
1492
+ hook(prolog:show_profile_hook(_,_)).
1493
+ hook(prolog_edit:load).
1494
+ hook(prolog_edit:locate(_,_,_)).
1495
+ hook(sandbox:safe_directive(_)).
1496
+ hook(sandbox:safe_global_variable(_)).
1497
+ hook(sandbox:safe_meta(_,_)).
1498
+ hook(sandbox:safe_meta_predicate(_)).
1499
+ hook(sandbox:safe_primitive(_)).
1500
+ hook(sandbox:safe_prolog_flag(_,_)).
1501
+ hook(shlib:unload_all_foreign_libraries).
1502
+ hook(system:'$foreign_registered'(_, _)).
1503
+ hook(user:exception(_,_,_)).
1504
+ hook(user:expand_answer(_,_)).
1505
+ hook(user:expand_query(_,_,_,_)).
1506
+ hook(user:file_search_path(_,_)).
1507
+ hook(user:library_directory(_)).
1508
+ hook(user:message_hook(_,_,_)).
1509
+ hook(prolog:message_action(_,_)).
1510
+ hook(user:portray(_)).
1511
+ hook(user:prolog_clause_name(_,_)).
1512
+ hook(user:prolog_list_goal(_)).
1513
+ hook(user:prolog_predicate_name(_,_)).
1514
+ hook(user:prolog_trace_interception(_,_,_,_)).
1515
+
1516
+ %! arith_callable(+Spec, -Callable)
1517
+ %
1518
+ % Translate argument of arithmetic_function/1 into a callable term
1519
+
1520
+ arith_callable(Var, _) :-
1521
+ var(Var), !, fail.
1522
+ arith_callable(Module:Spec, Module:Goal) :-
1523
+ !,
1524
+ arith_callable(Spec, Goal).
1525
+ arith_callable(Name/Arity, Goal) :-
1526
+ PredArity is Arity + 1,
1527
+ functor(Goal, Name, PredArity).
1528
+
1529
+ %! process_body(+Body, +Origin, +Src) is det.
1530
+ %
1531
+ % Process a callable body (body of a clause or directive). Origin
1532
+ % describes the origin of the call. Partial evaluation may lead to
1533
+ % non-determinism, which is why we backtrack over process_goal/3.
1534
+ %
1535
+ % We limit the number of explored paths to 100 to avoid getting
1536
+ % trapped in this analysis.
1537
+
1538
+ process_body(Body, Origin, Src) :-
1539
+ forall(limit(100, process_goal(Body, Origin, Src, _Partial)),
1540
+ true).
1541
+
1542
+ %! process_goal(+Goal, +Origin, +Src, ?Partial) is multi.
1543
+ %
1544
+ % Xref Goal. The argument Partial is bound to `true` if there was a
1545
+ % partial evalation inside Goal that has bound variables.
1546
+
1547
+ process_goal(Var, _, _, _) :-
1548
+ var(Var),
1549
+ !.
1550
+ process_goal(_:Goal, _, _, _) :-
1551
+ var(Goal),
1552
+ !.
1553
+ process_goal(Goal, Origin, Src, P) :-
1554
+ Goal = (_,_), % problems
1555
+ !,
1556
+ phrase(conjunction(Goal), Goals),
1557
+ process_conjunction(Goals, Origin, Src, P).
1558
+ process_goal(Goal, Origin, Src, _) :- % Final disjunction, no
1559
+ Goal = (_;_), % problems
1560
+ !,
1561
+ phrase(disjunction(Goal), Goals),
1562
+ forall(member(G, Goals),
1563
+ process_body(G, Origin, Src)).
1564
+ process_goal(Goal, Origin, Src, P) :-
1565
+ ( ( xmodule(M, Src)
1566
+ -> true
1567
+ ; M = user
1568
+ ),
1569
+ pi_head(PI, M:Goal),
1570
+ ( current_predicate(PI),
1571
+ predicate_property(M:Goal, imported_from(IM))
1572
+ -> true
1573
+ ; PI = M:Name/Arity,
1574
+ '$find_library'(M, Name, Arity, IM, _Library)
1575
+ -> true
1576
+ ; IM = M
1577
+ ),
1578
+ prolog:called_by(Goal, IM, M, Called)
1579
+ ; prolog:called_by(Goal, Called)
1580
+ ),
1581
+ !,
1582
+ must_be(list, Called),
1583
+ current_source_line(Here),
1584
+ assert_called(Src, Origin, Goal, Here),
1585
+ process_called_list(Called, Origin, Src, P).
1586
+ process_goal(Goal, Origin, Src, _) :-
1587
+ process_xpce_goal(Goal, Origin, Src),
1588
+ !.
1589
+ process_goal(load_foreign_library(File), _Origin, Src, _) :-
1590
+ process_foreign(File, Src).
1591
+ process_goal(load_foreign_library(File, _Init), _Origin, Src, _) :-
1592
+ process_foreign(File, Src).
1593
+ process_goal(use_foreign_library(File), _Origin, Src, _) :-
1594
+ process_foreign(File, Src).
1595
+ process_goal(use_foreign_library(File, _Init), _Origin, Src, _) :-
1596
+ process_foreign(File, Src).
1597
+ process_goal(Goal, Origin, Src, P) :-
1598
+ xref_meta_src(Goal, Metas, Src),
1599
+ !,
1600
+ current_source_line(Here),
1601
+ assert_called(Src, Origin, Goal, Here),
1602
+ process_called_list(Metas, Origin, Src, P).
1603
+ process_goal(Goal, Origin, Src, _) :-
1604
+ asserting_goal(Goal, Rule),
1605
+ !,
1606
+ current_source_line(Here),
1607
+ assert_called(Src, Origin, Goal, Here),
1608
+ process_assert(Rule, Origin, Src).
1609
+ process_goal(Goal, Origin, Src, P) :-
1610
+ partial_evaluate(Goal, P),
1611
+ current_source_line(Here),
1612
+ assert_called(Src, Origin, Goal, Here).
1613
+
1614
+ disjunction(Var) --> {var(Var), !}, [Var].
1615
+ disjunction((A;B)) --> !, disjunction(A), disjunction(B).
1616
+ disjunction(G) --> [G].
1617
+
1618
+ conjunction(Var) --> {var(Var), !}, [Var].
1619
+ conjunction((A,B)) --> !, conjunction(A), conjunction(B).
1620
+ conjunction(G) --> [G].
1621
+
1622
+ shares_vars(RVars, T) :-
1623
+ term_variables(T, TVars0),
1624
+ sort(TVars0, TVars),
1625
+ ord_intersect(RVars, TVars).
1626
+
1627
+ process_conjunction([], _, _, _).
1628
+ process_conjunction([Disj|Rest], Origin, Src, P) :-
1629
+ nonvar(Disj),
1630
+ Disj = (_;_),
1631
+ Rest \== [],
1632
+ !,
1633
+ phrase(disjunction(Disj), Goals),
1634
+ term_variables(Rest, RVars0),
1635
+ sort(RVars0, RVars),
1636
+ partition(shares_vars(RVars), Goals, Sharing, NonSHaring),
1637
+ forall(member(G, NonSHaring),
1638
+ process_body(G, Origin, Src)),
1639
+ ( Sharing == []
1640
+ -> true
1641
+ ; maplist(term_variables, Sharing, GVars0),
1642
+ append(GVars0, GVars1),
1643
+ sort(GVars1, GVars),
1644
+ ord_intersection(GVars, RVars, SVars),
1645
+ VT =.. [v|SVars],
1646
+ findall(VT,
1647
+ ( member(G, Sharing),
1648
+ process_goal(G, Origin, Src, PS),
1649
+ PS == true
1650
+ ),
1651
+ Alts0),
1652
+ ( Alts0 == []
1653
+ -> true
1654
+ ; ( true
1655
+ ; P = true,
1656
+ sort(Alts0, Alts1),
1657
+ variants(Alts1, 10, Alts),
1658
+ member(VT, Alts)
1659
+ )
1660
+ )
1661
+ ),
1662
+ process_conjunction(Rest, Origin, Src, P).
1663
+ process_conjunction([H|T], Origin, Src, P) :-
1664
+ process_goal(H, Origin, Src, P),
1665
+ process_conjunction(T, Origin, Src, P).
1666
+
1667
+
1668
+ process_called_list([], _, _, _).
1669
+ process_called_list([H|T], Origin, Src, P) :-
1670
+ process_meta(H, Origin, Src, P),
1671
+ process_called_list(T, Origin, Src, P).
1672
+
1673
+ process_meta(A+N, Origin, Src, P) :-
1674
+ !,
1675
+ ( extend(A, N, AX)
1676
+ -> process_goal(AX, Origin, Src, P)
1677
+ ; true
1678
+ ).
1679
+ process_meta(//(A), Origin, Src, P) :-
1680
+ !,
1681
+ process_dcg_goal(A, Origin, Src, P).
1682
+ process_meta(G, Origin, Src, P) :-
1683
+ process_goal(G, Origin, Src, P).
1684
+
1685
+ %! process_dcg_goal(+Grammar, +Origin, +Src, ?Partial) is det.
1686
+ %
1687
+ % Process meta-arguments that are tagged with //, such as
1688
+ % phrase/3.
1689
+
1690
+ process_dcg_goal(Var, _, _, _) :-
1691
+ var(Var),
1692
+ !.
1693
+ process_dcg_goal((A,B), Origin, Src, P) :-
1694
+ !,
1695
+ process_dcg_goal(A, Origin, Src, P),
1696
+ process_dcg_goal(B, Origin, Src, P).
1697
+ process_dcg_goal((A;B), Origin, Src, P) :-
1698
+ !,
1699
+ process_dcg_goal(A, Origin, Src, P),
1700
+ process_dcg_goal(B, Origin, Src, P).
1701
+ process_dcg_goal((A|B), Origin, Src, P) :-
1702
+ !,
1703
+ process_dcg_goal(A, Origin, Src, P),
1704
+ process_dcg_goal(B, Origin, Src, P).
1705
+ process_dcg_goal((A->B), Origin, Src, P) :-
1706
+ !,
1707
+ process_dcg_goal(A, Origin, Src, P),
1708
+ process_dcg_goal(B, Origin, Src, P).
1709
+ process_dcg_goal((A*->B), Origin, Src, P) :-
1710
+ !,
1711
+ process_dcg_goal(A, Origin, Src, P),
1712
+ process_dcg_goal(B, Origin, Src, P).
1713
+ process_dcg_goal({Goal}, Origin, Src, P) :-
1714
+ !,
1715
+ process_goal(Goal, Origin, Src, P).
1716
+ process_dcg_goal(List, _Origin, _Src, _) :-
1717
+ is_list(List),
1718
+ !. % terminal
1719
+ process_dcg_goal(List, _Origin, _Src, _) :-
1720
+ string(List),
1721
+ !. % terminal
1722
+ process_dcg_goal(Callable, Origin, Src, P) :-
1723
+ extend(Callable, 2, Goal),
1724
+ !,
1725
+ process_goal(Goal, Origin, Src, P).
1726
+ process_dcg_goal(_, _, _, _).
1727
+
1728
+
1729
+ extend(Var, _, _) :-
1730
+ var(Var), !, fail.
1731
+ extend(M:G, N, M:GX) :-
1732
+ !,
1733
+ callable(G),
1734
+ extend(G, N, GX).
1735
+ extend(G, N, GX) :-
1736
+ ( compound(G)
1737
+ -> compound_name_arguments(G, Name, Args),
1738
+ length(Rest, N),
1739
+ append(Args, Rest, NArgs),
1740
+ compound_name_arguments(GX, Name, NArgs)
1741
+ ; atom(G)
1742
+ -> length(NArgs, N),
1743
+ compound_name_arguments(GX, G, NArgs)
1744
+ ).
1745
+
1746
+ asserting_goal(assert(Rule), Rule).
1747
+ asserting_goal(asserta(Rule), Rule).
1748
+ asserting_goal(assertz(Rule), Rule).
1749
+ asserting_goal(assert(Rule,_), Rule).
1750
+ asserting_goal(asserta(Rule,_), Rule).
1751
+ asserting_goal(assertz(Rule,_), Rule).
1752
+
1753
+ process_assert(0, _, _) :- !. % catch variables
1754
+ process_assert((_:-Body), Origin, Src) :-
1755
+ !,
1756
+ process_body(Body, Origin, Src).
1757
+ process_assert(_, _, _).
1758
+
1759
+ %! variants(+SortedList, +Max, -Variants) is det.
1760
+
1761
+ variants([], _, []).
1762
+ variants([H|T], Max, List) :-
1763
+ variants(T, H, Max, List).
1764
+
1765
+ variants([], H, _, [H]).
1766
+ variants(_, _, 0, []) :- !.
1767
+ variants([H|T], V, Max, List) :-
1768
+ ( H =@= V
1769
+ -> variants(T, V, Max, List)
1770
+ ; List = [V|List2],
1771
+ Max1 is Max-1,
1772
+ variants(T, H, Max1, List2)
1773
+ ).
1774
+
1775
+ %! partial_evaluate(+Goal, ?Parrial) is det.
1776
+ %
1777
+ % Perform partial evaluation on Goal to trap cases such as below.
1778
+ %
1779
+ % ==
1780
+ % T = hello(X),
1781
+ % findall(T, T, List),
1782
+ % ==
1783
+ %
1784
+ % @tbd Make this user extensible? What about non-deterministic
1785
+ % bindings?
1786
+
1787
+ partial_evaluate(Goal, P) :-
1788
+ eval(Goal),
1789
+ !,
1790
+ P = true.
1791
+ partial_evaluate(_, _).
1792
+
1793
+ eval(X = Y) :-
1794
+ unify_with_occurs_check(X, Y).
1795
+
1796
+ /*******************************
1797
+ * PLUNIT SUPPORT *
1798
+ *******************************/
1799
+
1800
+ enter_test_unit(Unit, _Src) :-
1801
+ current_source_line(Line),
1802
+ asserta(current_test_unit(Unit, Line)).
1803
+
1804
+ leave_test_unit(Unit, _Src) :-
1805
+ retractall(current_test_unit(Unit, _)).
1806
+
1807
+
1808
+ /*******************************
1809
+ * XPCE STUFF *
1810
+ *******************************/
1811
+
1812
+ pce_goal(new(_,_), new(-, new)).
1813
+ pce_goal(send(_,_), send(arg, msg)).
1814
+ pce_goal(send_class(_,_,_), send_class(arg, arg, msg)).
1815
+ pce_goal(get(_,_,_), get(arg, msg, -)).
1816
+ pce_goal(get_class(_,_,_,_), get_class(arg, arg, msg, -)).
1817
+ pce_goal(get_chain(_,_,_), get_chain(arg, msg, -)).
1818
+ pce_goal(get_object(_,_,_), get_object(arg, msg, -)).
1819
+
1820
+ process_xpce_goal(G, Origin, Src) :-
1821
+ pce_goal(G, Process),
1822
+ !,
1823
+ current_source_line(Here),
1824
+ assert_called(Src, Origin, G, Here),
1825
+ ( arg(I, Process, How),
1826
+ arg(I, G, Term),
1827
+ process_xpce_arg(How, Term, Origin, Src),
1828
+ fail
1829
+ ; true
1830
+ ).
1831
+
1832
+ process_xpce_arg(new, Term, Origin, Src) :-
1833
+ callable(Term),
1834
+ process_new(Term, Origin, Src).
1835
+ process_xpce_arg(arg, Term, Origin, Src) :-
1836
+ compound(Term),
1837
+ process_new(Term, Origin, Src).
1838
+ process_xpce_arg(msg, Term, Origin, Src) :-
1839
+ compound(Term),
1840
+ ( arg(_, Term, Arg),
1841
+ process_xpce_arg(arg, Arg, Origin, Src),
1842
+ fail
1843
+ ; true
1844
+ ).
1845
+
1846
+ process_new(_M:_Term, _, _) :- !. % TBD: Calls on other modules!
1847
+ process_new(Term, Origin, Src) :-
1848
+ assert_new(Src, Origin, Term),
1849
+ ( compound(Term),
1850
+ arg(_, Term, Arg),
1851
+ process_xpce_arg(arg, Arg, Origin, Src),
1852
+ fail
1853
+ ; true
1854
+ ).
1855
+
1856
+ assert_new(_, _, Term) :-
1857
+ \+ callable(Term),
1858
+ !.
1859
+ assert_new(Src, Origin, Control) :-
1860
+ functor_name(Control, Class),
1861
+ pce_control_class(Class),
1862
+ !,
1863
+ forall(arg(_, Control, Arg),
1864
+ assert_new(Src, Origin, Arg)).
1865
+ assert_new(Src, Origin, Term) :-
1866
+ compound(Term),
1867
+ arg(1, Term, Prolog),
1868
+ Prolog == @(prolog),
1869
+ ( Term =.. [message, _, Selector | T],
1870
+ atom(Selector)
1871
+ -> Called =.. [Selector|T],
1872
+ process_body(Called, Origin, Src)
1873
+ ; Term =.. [?, _, Selector | T],
1874
+ atom(Selector)
1875
+ -> append(T, [_R], T2),
1876
+ Called =.. [Selector|T2],
1877
+ process_body(Called, Origin, Src)
1878
+ ),
1879
+ fail.
1880
+ assert_new(_, _, @(_)) :- !.
1881
+ assert_new(Src, _, Term) :-
1882
+ functor_name(Term, Name),
1883
+ assert_used_class(Src, Name).
1884
+
1885
+
1886
+ pce_control_class(and).
1887
+ pce_control_class(or).
1888
+ pce_control_class(if).
1889
+ pce_control_class(not).
1890
+
1891
+
1892
+ /********************************
1893
+ * INCLUDED MODULES *
1894
+ ********************************/
1895
+
1896
+ %! process_use_module(+Modules, +Src, +Rexport) is det.
1897
+
1898
+ process_use_module(_Module:_Files, _, _) :- !. % loaded in another module
1899
+ process_use_module([], _, _) :- !.
1900
+ process_use_module([H|T], Src, Reexport) :-
1901
+ !,
1902
+ process_use_module(H, Src, Reexport),
1903
+ process_use_module(T, Src, Reexport).
1904
+ process_use_module(library(pce), Src, Reexport) :- % bit special
1905
+ !,
1906
+ xref_public_list(library(pce), Path, Exports, Src),
1907
+ forall(member(Import, Exports),
1908
+ process_pce_import(Import, Src, Path, Reexport)).
1909
+ process_use_module(File, Src, Reexport) :-
1910
+ load_module_if_needed(File),
1911
+ ( xoption(Src, silent(Silent))
1912
+ -> Extra = [silent(Silent)]
1913
+ ; Extra = [silent(true)]
1914
+ ),
1915
+ ( xref_public_list(File, Src,
1916
+ [ path(Path),
1917
+ module(M),
1918
+ exports(Exports),
1919
+ public(Public),
1920
+ meta(Meta)
1921
+ | Extra
1922
+ ])
1923
+ -> assert(uses_file(File, Src, Path)),
1924
+ assert_import(Src, Exports, _, Path, Reexport),
1925
+ assert_xmodule_callable(Exports, M, Src, Path),
1926
+ assert_xmodule_callable(Public, M, Src, Path),
1927
+ maplist(process_meta_head(Src), Meta),
1928
+ ( File = library(chr) % hacky
1929
+ -> assert(mode(chr, Src))
1930
+ ; true
1931
+ )
1932
+ ; assert(uses_file(File, Src, '<not_found>'))
1933
+ ).
1934
+
1935
+ process_pce_import(Name/Arity, Src, Path, Reexport) :-
1936
+ atom(Name),
1937
+ integer(Arity),
1938
+ !,
1939
+ functor(Term, Name, Arity),
1940
+ ( \+ system_predicate(Term),
1941
+ \+ Term = pce_error(_) % hack!?
1942
+ -> assert_import(Src, [Name/Arity], _, Path, Reexport)
1943
+ ; true
1944
+ ).
1945
+ process_pce_import(op(P,T,N), Src, _, _) :-
1946
+ xref_push_op(Src, P, T, N).
1947
+
1948
+ %! process_use_module2(+File, +Import, +Src, +Reexport) is det.
1949
+ %
1950
+ % Process use_module/2 and reexport/2.
1951
+
1952
+ process_use_module2(File, Import, Src, Reexport) :-
1953
+ load_module_if_needed(File),
1954
+ ( catch(xref_public_list(File, Src,
1955
+ [ path(Path),
1956
+ exports(Export),
1957
+ meta(Meta)
1958
+ ]),
1959
+ error(_,_),
1960
+ fail)
1961
+ -> assertz(uses_file(File, Src, Path)),
1962
+ assert_import(Src, Import, Export, Path, Reexport),
1963
+ forall(( member(Head, Meta),
1964
+ imported(Head, _, Path)
1965
+ ),
1966
+ process_meta_head(Src, Head))
1967
+ ; assertz(uses_file(File, Src, '<not_found>'))
1968
+ ).
1969
+
1970
+
1971
+ %! load_module_if_needed(+File)
1972
+ %
1973
+ % Load a module explicitly if it is not suitable for autoloading.
1974
+ % Typically this is the case if the module provides essential term
1975
+ % and/or goal expansion rulses.
1976
+
1977
+ load_module_if_needed(File) :-
1978
+ prolog:no_autoload_module(File),
1979
+ !,
1980
+ use_module(File, []).
1981
+ load_module_if_needed(_).
1982
+
1983
+ prolog:no_autoload_module(library(apply_macros)).
1984
+ prolog:no_autoload_module(library(arithmetic)).
1985
+ prolog:no_autoload_module(library(record)).
1986
+ prolog:no_autoload_module(library(persistency)).
1987
+ prolog:no_autoload_module(library(pldoc)).
1988
+ prolog:no_autoload_module(library(settings)).
1989
+ prolog:no_autoload_module(library(debug)).
1990
+ prolog:no_autoload_module(library(plunit)).
1991
+ prolog:no_autoload_module(library(macros)).
1992
+ prolog:no_autoload_module(library(yall)).
1993
+
1994
+
1995
+ %! process_requires(+Import, +Src)
1996
+
1997
+ process_requires(Import, Src) :-
1998
+ is_list(Import),
1999
+ !,
2000
+ require_list(Import, Src).
2001
+ process_requires(Var, _Src) :-
2002
+ var(Var),
2003
+ !.
2004
+ process_requires((A,B), Src) :-
2005
+ !,
2006
+ process_requires(A, Src),
2007
+ process_requires(B, Src).
2008
+ process_requires(PI, Src) :-
2009
+ requires(PI, Src).
2010
+
2011
+ require_list([], _).
2012
+ require_list([H|T], Src) :-
2013
+ requires(H, Src),
2014
+ require_list(T, Src).
2015
+
2016
+ requires(PI, _Src) :-
2017
+ '$pi_head'(PI, Head),
2018
+ '$get_predicate_attribute'(system:Head, defined, 1),
2019
+ !.
2020
+ requires(PI, Src) :-
2021
+ '$pi_head'(PI, Head),
2022
+ '$pi_head'(Name/Arity, Head),
2023
+ '$find_library'(_Module, Name, Arity, _LoadModule, Library),
2024
+ ( imported(Head, Src, Library)
2025
+ -> true
2026
+ ; assertz(imported(Head, Src, Library))
2027
+ ).
2028
+
2029
+
2030
+ %! xref_public_list(+Spec, +Source, +Options) is semidet.
2031
+ %
2032
+ % Find meta-information about File. If Spec resolves to a Prolog
2033
+ % source file, this predicate reads all terms upto the first term that
2034
+ % is not a directive. If Spec resolves to a SWI-Prolog `.qlf` file, it
2035
+ % extracts part of the information from the QLF file. It uses the
2036
+ % module and meta_predicate directives to assemble the information in
2037
+ % Options. Options processed:
2038
+ %
2039
+ % - path(-Path)
2040
+ % Path is the full path name of the referenced file. If Spec
2041
+ % resolves to a .qlf file, Path is the name of the embedded
2042
+ % Prolog file.
2043
+ % - module(-Module)
2044
+ % Module is the module defines in Spec.
2045
+ % - exports(-Exports)
2046
+ % Exports is a list of predicate indicators and operators
2047
+ % collected from the module/2 term and reexport declarations.
2048
+ % - public(-Public)
2049
+ % Public declarations of the file. Currently always `[]` for
2050
+ % .qlf files.
2051
+ % - meta(-Meta)
2052
+ % Meta is a list of heads as they appear in meta_predicate/1
2053
+ % declarations. Currently always `[]` for .qlf files.
2054
+ % - silent(+Boolean)
2055
+ % Do not print any messages or raise exceptions on errors.
2056
+ %
2057
+ % The information collected by this predicate is cached. The cached
2058
+ % data is considered valid as long as the modification time of the
2059
+ % file does not change.
2060
+ %
2061
+ % @arg Source is the file from which Spec is referenced.
2062
+
2063
+ xref_public_list(File, Src, Options) :-
2064
+ option(path(Source), Options, _),
2065
+ option(module(Module), Options, _),
2066
+ option(exports(Exports), Options, _),
2067
+ option(public(Public), Options, _),
2068
+ option(meta(Meta), Options, _),
2069
+ xref_source_file(File, Path, Src, Options),
2070
+ public_list(Path, Source, Module, Meta, Exports, Public, Options).
2071
+
2072
+ %! xref_public_list(+File, -Path, -Export, +Src) is semidet.
2073
+ %! xref_public_list(+File, -Path, -Module, -Export, -Meta, +Src) is semidet.
2074
+ %! xref_public_list(+File, -Path, -Module, -Export, -Public, -Meta, +Src) is semidet.
2075
+ %
2076
+ % Find meta-information about File. This predicate reads all terms
2077
+ % upto the first term that is not a directive. It uses the module
2078
+ % and meta_predicate directives to assemble the information
2079
+ % described below.
2080
+ %
2081
+ % These predicates fail if File is not a module-file.
2082
+ %
2083
+ % @arg Path is the canonical path to File
2084
+ % @arg Module is the module defined in Path
2085
+ % @arg Export is a list of predicate indicators.
2086
+ % @arg Meta is a list of heads as they appear in
2087
+ % meta_predicate/1 declarations.
2088
+ % @arg Src is the place from which File is referenced.
2089
+ % @deprecated New code should use xref_public_list/3, which
2090
+ % unifies all variations using an option list.
2091
+
2092
+ xref_public_list(File, Source, Export, Src) :-
2093
+ xref_source_file(File, Path, Src),
2094
+ public_list(Path, Source, _, _, Export, _, []).
2095
+ xref_public_list(File, Source, Module, Export, Meta, Src) :-
2096
+ xref_source_file(File, Path, Src),
2097
+ public_list(Path, Source, Module, Meta, Export, _, []).
2098
+ xref_public_list(File, Source, Module, Export, Public, Meta, Src) :-
2099
+ xref_source_file(File, Path, Src),
2100
+ public_list(Path, Source, Module, Meta, Export, Public, []).
2101
+
2102
+ %! public_list(+Path, -Source, -Module, -Meta, -Export, -Public,
2103
+ %! +Options) is det.
2104
+ %
2105
+ % Read the public information for Path. Options supported are:
2106
+ %
2107
+ % - silent(+Boolean)
2108
+ % If `true`, ignore (syntax) errors. If not specified the default
2109
+ % is inherited from xref_source/2.
2110
+
2111
+ :- dynamic public_list_cache/7.
2112
+ :- volatile public_list_cache/7.
2113
+
2114
+ public_list(Path, Source, Module, Meta, Export, Public, _Options) :-
2115
+ public_list_cache(Path, Source, Modified,
2116
+ Module0, Meta0, Export0, Public0),
2117
+ time_file(Path, ModifiedNow),
2118
+ ( abs(Modified-ModifiedNow) < 0.0001
2119
+ -> !,
2120
+ t(Module,Meta,Export,Public) = t(Module0,Meta0,Export0,Public0)
2121
+ ; retractall(public_list_cache(Path, _, _, _, _, _, _)),
2122
+ fail
2123
+ ).
2124
+ public_list(Path, Source, Module, Meta, Export, Public, Options) :-
2125
+ public_list_nc(Path, Source, Module0, Meta0, Export0, Public0, Options),
2126
+ ( Error = error(_,_),
2127
+ catch(time_file(Path, Modified), Error, fail)
2128
+ -> asserta(public_list_cache(Path, Source, Modified,
2129
+ Module0, Meta0, Export0, Public0))
2130
+ ; true
2131
+ ),
2132
+ t(Module,Meta,Export,Public) = t(Module0,Meta0,Export0,Public0).
2133
+
2134
+ public_list_nc(Path, Source, Module, Meta, Export, Public, _Options) :-
2135
+ public_list_from_index(Path, Module, Meta, Export, Public),
2136
+ !,
2137
+ qlf_pl_file(Path, Source).
2138
+ public_list_nc(Path, Source, Module, [], Export, [], _Options) :-
2139
+ is_qlf_file(Path),
2140
+ !,
2141
+ '$qlf_module'(Path, Info),
2142
+ _{module:Module, exports:Export, file:Source} :< Info.
2143
+ public_list_nc(Path, Path, Module, Meta, Export, Public, Options) :-
2144
+ exists_file(Path),
2145
+ !,
2146
+ prolog_file_directives(Path, Directives, Options),
2147
+ public_list(Directives, Path, Module, Meta, [], Export, [], Public, []).
2148
+ public_list_nc(Path, Path, Module, [], Export, [], _Options) :-
2149
+ qlf_pl_file(QlfFile, Path),
2150
+ '$qlf_module'(QlfFile, Info),
2151
+ _{module:Module, exports:Export} :< Info.
2152
+
2153
+ public_list([(:- module(Module, Export0))|Decls], Path,
2154
+ Module, Meta, MT, Export, Rest, Public, PT) :-
2155
+ !,
2156
+ ( is_list(Export0)
2157
+ -> append(Export0, Reexport, Export)
2158
+ ; Reexport = Export
2159
+ ),
2160
+ public_list_(Decls, Path, Meta, MT, Reexport, Rest, Public, PT).
2161
+ public_list([(:- encoding(_))|Decls], Path,
2162
+ Module, Meta, MT, Export, Rest, Public, PT) :-
2163
+ public_list(Decls, Path, Module, Meta, MT, Export, Rest, Public, PT).
2164
+
2165
+ public_list_([], _, Meta, Meta, Export, Export, Public, Public).
2166
+ public_list_([(:-(Dir))|T], Path, Meta, MT, Export, Rest, Public, PT) :-
2167
+ public_list_1(Dir, Path, Meta, MT0, Export, Rest0, Public, PT0),
2168
+ !,
2169
+ public_list_(T, Path, MT0, MT, Rest0, Rest, PT0, PT).
2170
+ public_list_([_|T], Path, Meta, MT, Export, Rest, Public, PT) :-
2171
+ public_list_(T, Path, Meta, MT, Export, Rest, Public, PT).
2172
+
2173
+ public_list_1(reexport(Spec), Path, Meta, MT, Reexport, Rest, Public, PT) :-
2174
+ reexport_files(Spec, Path, Meta, MT, Reexport, Rest, Public, PT).
2175
+ public_list_1(reexport(Spec, Import), Path, Meta, Meta, Reexport, Rest, Public, Public) :-
2176
+ public_from_import(Import, Spec, Path, Reexport, Rest).
2177
+ public_list_1(meta_predicate(Decl), _Path, Meta, MT, Export, Export, Public, Public) :-
2178
+ phrase(meta_decls(Decl), Meta, MT).
2179
+ public_list_1(public(Decl), _Path, Meta, Meta, Export, Export, Public, PT) :-
2180
+ phrase(public_decls(Decl), Public, PT).
2181
+
2182
+ %! reexport_files(+Files, +Src,
2183
+ %! -Meta, ?MetaTail, -Exports, ?ExportsTail,
2184
+ %! -Public, ?PublicTail)
2185
+
2186
+ reexport_files([], _, Meta, Meta, Export, Export, Public, Public) :- !.
2187
+ reexport_files([H|T], Src, Meta, MT, Export, ET, Public, PT) :-
2188
+ !,
2189
+ xref_source_file(H, Path, Src),
2190
+ public_list(Path, _Source, _Module, Meta0, Export0, Public0, []),
2191
+ append(Meta0, MT1, Meta),
2192
+ append(Export0, ET1, Export),
2193
+ append(Public0, PT1, Public),
2194
+ reexport_files(T, Src, MT1, MT, ET1, ET, PT1, PT).
2195
+ reexport_files(Spec, Src, Meta, MT, Export, ET, Public, PT) :-
2196
+ xref_source_file(Spec, Path, Src),
2197
+ public_list(Path, _Source, _Module, Meta0, Export0, Public0, []),
2198
+ append(Meta0, MT, Meta),
2199
+ append(Export0, ET, Export),
2200
+ append(Public0, PT, Public).
2201
+
2202
+ public_from_import(except(Map), Path, Src, Export, Rest) :-
2203
+ !,
2204
+ xref_public_list(Path, _, AllExports, Src),
2205
+ except(Map, AllExports, NewExports),
2206
+ append(NewExports, Rest, Export).
2207
+ public_from_import(Import, _, _, Export, Rest) :-
2208
+ import_name_map(Import, Export, Rest).
2209
+
2210
+
2211
+ %! except(+Remove, +AllExports, -Exports)
2212
+
2213
+ except([], Exports, Exports).
2214
+ except([PI0 as NewName|Map], Exports0, Exports) :-
2215
+ !,
2216
+ canonical_pi(PI0, PI),
2217
+ map_as(Exports0, PI, NewName, Exports1),
2218
+ except(Map, Exports1, Exports).
2219
+ except([PI0|Map], Exports0, Exports) :-
2220
+ canonical_pi(PI0, PI),
2221
+ select(PI2, Exports0, Exports1),
2222
+ same_pi(PI, PI2),
2223
+ !,
2224
+ except(Map, Exports1, Exports).
2225
+
2226
+
2227
+ map_as([PI|T], Repl, As, [PI2|T]) :-
2228
+ same_pi(Repl, PI),
2229
+ !,
2230
+ pi_as(PI, As, PI2).
2231
+ map_as([H|T0], Repl, As, [H|T]) :-
2232
+ map_as(T0, Repl, As, T).
2233
+
2234
+ pi_as(_/Arity, Name, Name/Arity).
2235
+ pi_as(_//Arity, Name, Name//Arity).
2236
+
2237
+ import_name_map([], L, L).
2238
+ import_name_map([_/Arity as NewName|T0], [NewName/Arity|T], Tail) :-
2239
+ !,
2240
+ import_name_map(T0, T, Tail).
2241
+ import_name_map([_//Arity as NewName|T0], [NewName//Arity|T], Tail) :-
2242
+ !,
2243
+ import_name_map(T0, T, Tail).
2244
+ import_name_map([H|T0], [H|T], Tail) :-
2245
+ import_name_map(T0, T, Tail).
2246
+
2247
+ canonical_pi(Name//Arity0, PI) :-
2248
+ integer(Arity0),
2249
+ !,
2250
+ PI = Name/Arity,
2251
+ Arity is Arity0 + 2.
2252
+ canonical_pi(PI, PI).
2253
+
2254
+ same_pi(Canonical, PI2) :-
2255
+ canonical_pi(PI2, Canonical).
2256
+
2257
+ meta_decls(Var) -->
2258
+ { var(Var) },
2259
+ !.
2260
+ meta_decls((A,B)) -->
2261
+ !,
2262
+ meta_decls(A),
2263
+ meta_decls(B).
2264
+ meta_decls(A) -->
2265
+ [A].
2266
+
2267
+ public_decls(Var) -->
2268
+ { var(Var) },
2269
+ !.
2270
+ public_decls((A,B)) -->
2271
+ !,
2272
+ public_decls(A),
2273
+ public_decls(B).
2274
+ public_decls(A) -->
2275
+ [A].
2276
+
2277
+ %! public_list_from_index(+Path, -Module, -Meta, -Exports, -Public) is semidet.
2278
+ %
2279
+ % Read the exports for Path from the INDEX.pl file in the same
2280
+ % directory.
2281
+
2282
+ public_list_from_index(Path, Module, Meta, Export, Public) :-
2283
+ file_name_extension(BasePath, _Ext, Path),
2284
+ file_directory_name(BasePath, Dir),
2285
+ atom_concat(Dir, '/INDEX.pl', IndexFile),
2286
+ exists_file(IndexFile),
2287
+ file_base_name(BasePath, Base),
2288
+ setup_call_cleanup(
2289
+ '$push_input_context'(autoload_index),
2290
+ setup_call_cleanup(
2291
+ open(IndexFile, read, In),
2292
+ index_public_list(In, Base, Module, Meta, Export, Public),
2293
+ close(In)),
2294
+ '$pop_input_context').
2295
+
2296
+ index_public_list(In, Base, Module, Meta, Export, Public) :-
2297
+ read_term(In, Term, []),
2298
+ index_public_list(Term, In, Base, Module, Meta, Export, Public).
2299
+
2300
+ index_public_list(end_of_file, _In, _Base, _Module, [], [], []).
2301
+ index_public_list(index(op:Op, Module, Base), In, Base, Module, Meta, [Op|Export], Public) :-
2302
+ !,
2303
+ read_term(In, Term, []),
2304
+ index_public_list(Term, In, Base, Module, Meta, Export, Public).
2305
+ index_public_list(index((public):Head, Module, Base), In, Base, Module, Meta, Export, [PI|Public]) :-
2306
+ !,
2307
+ pi_head(PI, Head),
2308
+ read_term(In, Term, []),
2309
+ index_public_list(Term, In, Base, Module, Meta, Export, Public).
2310
+ index_public_list(index(Head, Module, Base), In, Base, Module, Meta, [PI|Export], Public) :-
2311
+ !,
2312
+ pi_head(PI, Head),
2313
+ ( meta_mode(Head)
2314
+ -> Meta = [Head|MetaT]
2315
+ ; Meta = MetaT
2316
+ ),
2317
+ read_term(In, Term, []),
2318
+ index_public_list(Term, In, Base, Module, MetaT, Export, Public).
2319
+ index_public_list(index(Name, Arity, Module, Base), In, Base, Module, Meta, [Name/Arity|Export], Public) :-
2320
+ !,
2321
+ read_term(In, Term, []),
2322
+ index_public_list(Term, In, Base, Module, Meta, Export, Public).
2323
+ index_public_list(_, In, Base, Module, Meta, Export, Public) :-
2324
+ read_term(In, Term, []),
2325
+ index_public_list(Term, In, Base, Module, Meta, Export, Public).
2326
+
2327
+ meta_mode(H) :-
2328
+ compound(H),
2329
+ arg(_, H, A),
2330
+ meta_arg(A),
2331
+ !.
2332
+
2333
+ meta_arg(I) :-
2334
+ integer(I),
2335
+ !.
2336
+ meta_arg(:).
2337
+ meta_arg(^).
2338
+ meta_arg(//).
2339
+
2340
+ /*******************************
2341
+ * INCLUDE *
2342
+ *******************************/
2343
+
2344
+ process_include([], _) :- !.
2345
+ process_include([H|T], Src) :-
2346
+ !,
2347
+ process_include(H, Src),
2348
+ process_include(T, Src).
2349
+ process_include(File, Src) :-
2350
+ callable(File),
2351
+ !,
2352
+ ( once(xref_input(ParentSrc, _)),
2353
+ xref_source_file(File, Path, ParentSrc)
2354
+ -> ( ( uses_file(_, Src, Path)
2355
+ ; Path == Src
2356
+ )
2357
+ -> true
2358
+ ; assert(uses_file(File, Src, Path)),
2359
+ ( xoption(Src, process_include(true))
2360
+ -> findall(O, xoption(Src, O), Options),
2361
+ setup_call_cleanup(
2362
+ open_include_file(Path, In, Refs),
2363
+ collect(Src, Path, In, Options),
2364
+ close_include(In, Refs))
2365
+ ; true
2366
+ )
2367
+ )
2368
+ ; assert(uses_file(File, Src, '<not_found>'))
2369
+ ).
2370
+ process_include(_, _).
2371
+
2372
+ %! open_include_file(+Path, -In, -Refs)
2373
+ %
2374
+ % Opens an :- include(File) referenced file. Note that we cannot
2375
+ % use prolog_open_source/2 because we should _not_ safe/restore
2376
+ % the lexical context.
2377
+
2378
+ open_include_file(Path, In, [Ref]) :-
2379
+ once(xref_input(_, Parent)),
2380
+ stream_property(Parent, encoding(Enc)),
2381
+ '$push_input_context'(xref_include),
2382
+ catch(( prolog:xref_open_source(Path, In)
2383
+ -> catch(set_stream(In, encoding(Enc)),
2384
+ error(_,_), true) % deal with non-file input
2385
+ ; include_encoding(Enc, Options),
2386
+ open(Path, read, In, Options)
2387
+ ), E,
2388
+ ( '$pop_input_context', throw(E))),
2389
+ catch(( peek_char(In, #) % Deal with #! script
2390
+ -> skip(In, 10)
2391
+ ; true
2392
+ ), E,
2393
+ ( close_include(In, []), throw(E))),
2394
+ asserta(xref_input(Path, In), Ref).
2395
+
2396
+ include_encoding(wchar_t, []) :- !.
2397
+ include_encoding(Enc, [encoding(Enc)]).
2398
+
2399
+
2400
+ close_include(In, Refs) :-
2401
+ maplist(erase, Refs),
2402
+ close(In, [force(true)]),
2403
+ '$pop_input_context'.
2404
+
2405
+ %! process_foreign(+Spec, +Src)
2406
+ %
2407
+ % Process a load_foreign_library/1 call.
2408
+
2409
+ process_foreign(Spec, Src) :-
2410
+ ground(Spec),
2411
+ current_foreign_library(Spec, Defined),
2412
+ !,
2413
+ ( xmodule(Module, Src)
2414
+ -> true
2415
+ ; Module = user
2416
+ ),
2417
+ process_foreign_defined(Defined, Module, Src).
2418
+ process_foreign(_, _).
2419
+
2420
+ process_foreign_defined([], _, _).
2421
+ process_foreign_defined([H|T], M, Src) :-
2422
+ ( H = M:Head
2423
+ -> assert_foreign(Src, Head)
2424
+ ; assert_foreign(Src, H)
2425
+ ),
2426
+ process_foreign_defined(T, M, Src).
2427
+
2428
+
2429
+ /*******************************
2430
+ * CHR SUPPORT *
2431
+ *******************************/
2432
+
2433
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2434
+ This part of the file supports CHR. Our choice is between making special
2435
+ hooks to make CHR expansion work and then handle the (complex) expanded
2436
+ code or process the CHR source directly. The latter looks simpler,
2437
+ though I don't like the idea of adding support for libraries to this
2438
+ module. A file is supposed to be a CHR file if it uses a
2439
+ use_module(library(chr) or contains a :- constraint/1 directive. As an
2440
+ extra bonus we get the source-locations right :-)
2441
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2442
+
2443
+ process_chr(@(_Name, Rule), Src) :-
2444
+ mode(chr, Src),
2445
+ process_chr(Rule, Src).
2446
+ process_chr(pragma(Rule, _Pragma), Src) :-
2447
+ mode(chr, Src),
2448
+ process_chr(Rule, Src).
2449
+ process_chr(<=>(Head, Body), Src) :-
2450
+ mode(chr, Src),
2451
+ chr_head(Head, Src, H),
2452
+ chr_body(Body, H, Src).
2453
+ process_chr(==>(Head, Body), Src) :-
2454
+ mode(chr, Src),
2455
+ chr_head(Head, H, Src),
2456
+ chr_body(Body, H, Src).
2457
+ process_chr((:- chr_constraint(Decls)), Src) :-
2458
+ ( mode(chr, Src)
2459
+ -> true
2460
+ ; assert(mode(chr, Src))
2461
+ ),
2462
+ chr_decls(Decls, Src).
2463
+
2464
+ chr_decls((A,B), Src) =>
2465
+ chr_decls(A, Src),
2466
+ chr_decls(B, Src).
2467
+ chr_decls(Head, Src) =>
2468
+ generalise_term(Head, Gen),
2469
+ ( declared(Gen, chr_constraint, Src, _)
2470
+ -> true
2471
+ ; current_source_line(Line),
2472
+ assertz(declared(Gen, chr_constraint, Src, Line))
2473
+ ).
2474
+
2475
+ chr_head(X, _, _) :-
2476
+ var(X),
2477
+ !. % Illegal. Warn?
2478
+ chr_head(\(A,B), Src, H) :-
2479
+ chr_head(A, Src, H),
2480
+ process_body(B, H, Src).
2481
+ chr_head((H0,B), Src, H) :-
2482
+ chr_defined(H0, Src, H),
2483
+ process_body(B, H, Src).
2484
+ chr_head(H0, Src, H) :-
2485
+ chr_defined(H0, Src, H).
2486
+
2487
+ chr_defined(X, _, _) :-
2488
+ var(X),
2489
+ !.
2490
+ chr_defined(#(C,_Id), Src, C) :-
2491
+ !,
2492
+ assert_constraint(Src, C).
2493
+ chr_defined(A, Src, A) :-
2494
+ assert_constraint(Src, A).
2495
+
2496
+ chr_body(X, From, Src) :-
2497
+ var(X),
2498
+ !,
2499
+ process_body(X, From, Src).
2500
+ chr_body('|'(Guard, Goals), H, Src) :-
2501
+ !,
2502
+ chr_body(Guard, H, Src),
2503
+ chr_body(Goals, H, Src).
2504
+ chr_body(G, From, Src) :-
2505
+ process_body(G, From, Src).
2506
+
2507
+ assert_constraint(_, Head) :-
2508
+ var(Head),
2509
+ !.
2510
+ assert_constraint(Src, Head) :-
2511
+ constraint(Head, Src, _),
2512
+ !.
2513
+ assert_constraint(Src, Head) :-
2514
+ generalise_term(Head, Term),
2515
+ current_source_line(Line),
2516
+ assert(constraint(Term, Src, Line)).
2517
+
2518
+
2519
+ /********************************
2520
+ * PHASE 1 ASSERTIONS *
2521
+ ********************************/
2522
+
2523
+ %! assert_called(+Src, +From, +Head, +Line) is det.
2524
+ %
2525
+ % Assert the fact that Head is called by From in Src. We do not
2526
+ % assert called system predicates.
2527
+
2528
+ assert_called(_, _, Var, _) :-
2529
+ var(Var),
2530
+ !.
2531
+ assert_called(Src, From, Goal, Line) :-
2532
+ var(From),
2533
+ !,
2534
+ assert_called(Src, '<unknown>', Goal, Line).
2535
+ assert_called(_, _, Goal, _) :-
2536
+ expand_hide_called(Goal),
2537
+ !.
2538
+ assert_called(Src, Origin, M:G, Line) :-
2539
+ !,
2540
+ ( atom(M),
2541
+ callable(G)
2542
+ -> current_condition(Cond),
2543
+ ( xmodule(M, Src) % explicit call to own module
2544
+ -> assert_called(Src, Origin, G, Line)
2545
+ ; called(M:G, Src, Origin, Cond, Line) % already registered
2546
+ -> true
2547
+ ; hide_called(M:G, Src) % not interesting (now)
2548
+ -> true
2549
+ ; generalise(Origin, OTerm),
2550
+ generalise(G, GTerm)
2551
+ -> assert(called(M:GTerm, Src, OTerm, Cond, Line))
2552
+ ; true
2553
+ )
2554
+ ; true % call to variable module
2555
+ ).
2556
+ assert_called(Src, _, Goal, _) :-
2557
+ ( xmodule(M, Src)
2558
+ -> M \== system
2559
+ ; M = user
2560
+ ),
2561
+ hide_called(M:Goal, Src),
2562
+ !.
2563
+ assert_called(Src, Origin, Goal, Line) :-
2564
+ current_condition(Cond),
2565
+ ( called(Goal, Src, Origin, Cond, Line)
2566
+ -> true
2567
+ ; generalise(Origin, OTerm),
2568
+ generalise(Goal, Term)
2569
+ -> assert(called(Term, Src, OTerm, Cond, Line))
2570
+ ; true
2571
+ ).
2572
+
2573
+
2574
+ %! expand_hide_called(:Callable) is semidet.
2575
+ %
2576
+ % Goals that should not turn up as being called. Hack. Eventually
2577
+ % we should deal with that using an XPCE plugin.
2578
+
2579
+ expand_hide_called(pce_principal:send_implementation(_, _, _)).
2580
+ expand_hide_called(pce_principal:get_implementation(_, _, _, _)).
2581
+ expand_hide_called(pce_principal:pce_lazy_get_method(_,_,_)).
2582
+ expand_hide_called(pce_principal:pce_lazy_send_method(_,_,_)).
2583
+
2584
+ assert_defined(Src, Goal) :-
2585
+ Goal = test(_Test),
2586
+ current_test_unit(Unit, Line),
2587
+ assert_called(Src, '<test_unit>'(Unit), Goal, Line),
2588
+ fail.
2589
+ assert_defined(Src, Goal) :-
2590
+ Goal = test(_Test, _Options),
2591
+ current_test_unit(Unit, Line),
2592
+ assert_called(Src, '<test_unit>'(Unit), Goal, Line),
2593
+ fail.
2594
+ assert_defined(Src, Goal) :-
2595
+ defined(Goal, Src, _),
2596
+ !.
2597
+ assert_defined(Src, Goal) :-
2598
+ generalise(Goal, Term),
2599
+ current_source_line(Line),
2600
+ assert(defined(Term, Src, Line)).
2601
+
2602
+ assert_foreign(Src, Goal) :-
2603
+ foreign(Goal, Src, _),
2604
+ !.
2605
+ assert_foreign(Src, Goal) :-
2606
+ generalise(Goal, Term),
2607
+ current_source_line(Line),
2608
+ assert(foreign(Term, Src, Line)).
2609
+
2610
+ assert_grammar_rule(Src, Goal) :-
2611
+ grammar_rule(Goal, Src),
2612
+ !.
2613
+ assert_grammar_rule(Src, Goal) :-
2614
+ generalise(Goal, Term),
2615
+ assert(grammar_rule(Term, Src)).
2616
+
2617
+
2618
+ %! assert_import(+Src, +Import, +ExportList, +From, +Reexport) is det.
2619
+ %
2620
+ % Asserts imports into Src. Import is the import specification,
2621
+ % ExportList is the list of known exported predicates or unbound
2622
+ % if this need not be checked and From is the file from which the
2623
+ % public predicates come. If Reexport is =true=, re-export the
2624
+ % imported predicates.
2625
+ %
2626
+ % @tbd Tighter type-checking on Import.
2627
+
2628
+ assert_import(_, [], _, _, _) :- !.
2629
+ assert_import(Src, [H|T], Export, From, Reexport) :-
2630
+ !,
2631
+ assert_import(Src, H, Export, From, Reexport),
2632
+ assert_import(Src, T, Export, From, Reexport).
2633
+ assert_import(Src, except(Except), Export, From, Reexport) :-
2634
+ !,
2635
+ is_list(Export),
2636
+ !,
2637
+ except(Except, Export, Import),
2638
+ assert_import(Src, Import, _All, From, Reexport).
2639
+ assert_import(Src, Import as Name, Export, From, Reexport) :-
2640
+ !,
2641
+ pi_to_head(Import, Term0),
2642
+ rename_goal(Term0, Name, Term),
2643
+ ( in_export_list(Term0, Export)
2644
+ -> assert(imported(Term, Src, From)),
2645
+ assert_reexport(Reexport, Src, Term)
2646
+ ; current_source_line(Line),
2647
+ assert_called(Src, '<directive>'(Line), Term0, Line)
2648
+ ).
2649
+ assert_import(Src, Import, Export, From, Reexport) :-
2650
+ pi_to_head(Import, Term),
2651
+ !,
2652
+ ( in_export_list(Term, Export)
2653
+ -> assert(imported(Term, Src, From)),
2654
+ assert_reexport(Reexport, Src, Term)
2655
+ ; current_source_line(Line),
2656
+ assert_called(Src, '<directive>'(Line), Term, Line)
2657
+ ).
2658
+ assert_import(Src, op(P,T,N), _, _, _) :-
2659
+ xref_push_op(Src, P,T,N).
2660
+
2661
+ in_export_list(_Head, Export) :-
2662
+ var(Export),
2663
+ !.
2664
+ in_export_list(Head, Export) :-
2665
+ member(PI, Export),
2666
+ pi_to_head(PI, Head).
2667
+
2668
+ assert_reexport(false, _, _) :- !.
2669
+ assert_reexport(true, Src, Term) :-
2670
+ assert(exported(Term, Src)).
2671
+
2672
+ %! process_import(:Import, +Src)
2673
+ %
2674
+ % Process an import/1 directive
2675
+
2676
+ process_import(M:PI, Src) :-
2677
+ pi_to_head(PI, Head),
2678
+ !,
2679
+ ( atom(M),
2680
+ current_module(M),
2681
+ module_property(M, file(From))
2682
+ -> true
2683
+ ; From = '<unknown>'
2684
+ ),
2685
+ assert(imported(Head, Src, From)).
2686
+ process_import(_, _).
2687
+
2688
+ %! assert_xmodule_callable(PIs, Module, Src, From)
2689
+ %
2690
+ % We can call all exports and public predicates of an imported
2691
+ % module using Module:Goal.
2692
+ %
2693
+ % @tbd Should we distinguish this from normal imported?
2694
+
2695
+ assert_xmodule_callable([], _, _, _).
2696
+ assert_xmodule_callable([PI|T], M, Src, From) :-
2697
+ ( pi_to_head(M:PI, Head)
2698
+ -> assert(imported(Head, Src, From))
2699
+ ; true
2700
+ ),
2701
+ assert_xmodule_callable(T, M, Src, From).
2702
+
2703
+
2704
+ %! assert_op(+Src, +Op) is det.
2705
+ %
2706
+ % @param Op Ground term op(Priority, Type, Name).
2707
+
2708
+ assert_op(Src, op(P,T,M:N)) :-
2709
+ ( '$current_source_module'(M)
2710
+ -> Name = N
2711
+ ; Name = M:N
2712
+ ),
2713
+ ( xop(Src, op(P,T,Name))
2714
+ -> true
2715
+ ; assert(xop(Src, op(P,T,Name)))
2716
+ ).
2717
+
2718
+ %! assert_module(+Src, +Module)
2719
+ %
2720
+ % Assert we are loading code into Module. This is also used to
2721
+ % exploit local term-expansion and other rules.
2722
+
2723
+ assert_module(Src, Module) :-
2724
+ xmodule(Module, Src),
2725
+ !.
2726
+ assert_module(Src, Module) :-
2727
+ '$set_source_module'(Module),
2728
+ assert(xmodule(Module, Src)),
2729
+ ( module_property(Module, class(system))
2730
+ -> retractall(xoption(Src, register_called(_))),
2731
+ assert(xoption(Src, register_called(all)))
2732
+ ; true
2733
+ ).
2734
+
2735
+ assert_module_export(_, []) :- !.
2736
+ assert_module_export(Src, [H|T]) :-
2737
+ !,
2738
+ assert_module_export(Src, H),
2739
+ assert_module_export(Src, T).
2740
+ assert_module_export(Src, PI) :-
2741
+ pi_to_head(PI, Term),
2742
+ !,
2743
+ assert(exported(Term, Src)).
2744
+ assert_module_export(Src, op(P, A, N)) :-
2745
+ xref_push_op(Src, P, A, N).
2746
+
2747
+ %! assert_module3(+Import, +Src)
2748
+ %
2749
+ % Handle 3th argument of module/3 declaration.
2750
+
2751
+ assert_module3([], _) :- !.
2752
+ assert_module3([H|T], Src) :-
2753
+ !,
2754
+ assert_module3(H, Src),
2755
+ assert_module3(T, Src).
2756
+ assert_module3(Option, Src) :-
2757
+ process_use_module(library(dialect/Option), Src, false).
2758
+
2759
+
2760
+ %! process_predicates(:Closure, +Predicates, +Src)
2761
+ %
2762
+ % Process areguments of dynamic, etc., using call(Closure, PI,
2763
+ % Src). Handles both lists of specifications and (PI,...)
2764
+ % specifications.
2765
+
2766
+ process_predicates(Closure, Preds, Src) :-
2767
+ is_list(Preds),
2768
+ !,
2769
+ process_predicate_list(Preds, Closure, Src).
2770
+ process_predicates(Closure, as(Preds, _Options), Src) :-
2771
+ !,
2772
+ process_predicates(Closure, Preds, Src).
2773
+ process_predicates(Closure, Preds, Src) :-
2774
+ process_predicate_comma(Preds, Closure, Src).
2775
+
2776
+ process_predicate_list([], _, _).
2777
+ process_predicate_list([H|T], Closure, Src) :-
2778
+ ( nonvar(H)
2779
+ -> call(Closure, H, Src)
2780
+ ; true
2781
+ ),
2782
+ process_predicate_list(T, Closure, Src).
2783
+
2784
+ process_predicate_comma(Var, _, _) :-
2785
+ var(Var),
2786
+ !.
2787
+ process_predicate_comma(M:(A,B), Closure, Src) :-
2788
+ !,
2789
+ process_predicate_comma(M:A, Closure, Src),
2790
+ process_predicate_comma(M:B, Closure, Src).
2791
+ process_predicate_comma((A,B), Closure, Src) :-
2792
+ !,
2793
+ process_predicate_comma(A, Closure, Src),
2794
+ process_predicate_comma(B, Closure, Src).
2795
+ process_predicate_comma(as(Spec, _Options), Closure, Src) :-
2796
+ !,
2797
+ process_predicate_comma(Spec, Closure, Src).
2798
+ process_predicate_comma(A, Closure, Src) :-
2799
+ call(Closure, A, Src).
2800
+
2801
+
2802
+ assert_dynamic(PI, Src) :-
2803
+ pi_to_head(PI, Term),
2804
+ ( thread_local(Term, Src, _) % dynamic after thread_local has
2805
+ -> true % no effect
2806
+ ; current_source_line(Line),
2807
+ assert(dynamic(Term, Src, Line))
2808
+ ).
2809
+
2810
+ assert_thread_local(PI, Src) :-
2811
+ pi_to_head(PI, Term),
2812
+ current_source_line(Line),
2813
+ assert(thread_local(Term, Src, Line)).
2814
+
2815
+ assert_multifile(PI, Src) :- % :- multifile(Spec)
2816
+ pi_to_head(PI, Term),
2817
+ current_source_line(Line),
2818
+ assert(multifile(Term, Src, Line)).
2819
+
2820
+ assert_public(PI, Src) :- % :- public(Spec)
2821
+ pi_to_head(PI, Term),
2822
+ current_source_line(Line),
2823
+ assert_called(Src, '<public>'(Line), Term, Line),
2824
+ assert(public(Term, Src, Line)).
2825
+
2826
+ assert_export(PI, Src) :- % :- export(Spec)
2827
+ pi_to_head(PI, Term),
2828
+ !,
2829
+ assert(exported(Term, Src)).
2830
+
2831
+ %! pi_to_head(+PI, -Head) is semidet.
2832
+ %
2833
+ % Translate Name/Arity or Name//Arity to a callable term. Fails if
2834
+ % PI is not a predicate indicator.
2835
+
2836
+ pi_to_head(Var, _) :-
2837
+ var(Var), !, fail.
2838
+ pi_to_head(M:PI, M:Term) :-
2839
+ !,
2840
+ pi_to_head(PI, Term).
2841
+ pi_to_head(Name/Arity, Term) :-
2842
+ functor(Term, Name, Arity).
2843
+ pi_to_head(Name//DCGArity, Term) :-
2844
+ Arity is DCGArity+2,
2845
+ functor(Term, Name, Arity).
2846
+
2847
+
2848
+ assert_used_class(Src, Name) :-
2849
+ used_class(Name, Src),
2850
+ !.
2851
+ assert_used_class(Src, Name) :-
2852
+ assert(used_class(Name, Src)).
2853
+
2854
+ assert_defined_class(Src, Name, _Meta, _Super, _) :-
2855
+ defined_class(Name, _, _, Src, _),
2856
+ !.
2857
+ assert_defined_class(_, _, _, -, _) :- !. % :- pce_extend_class
2858
+ assert_defined_class(Src, Name, Meta, Super, Summary) :-
2859
+ current_source_line(Line),
2860
+ ( Summary == @(default)
2861
+ -> Atom = ''
2862
+ ; is_list(Summary)
2863
+ -> atom_codes(Atom, Summary)
2864
+ ; string(Summary)
2865
+ -> atom_concat(Summary, '', Atom)
2866
+ ),
2867
+ assert(defined_class(Name, Super, Atom, Src, Line)),
2868
+ ( Meta = @(_)
2869
+ -> true
2870
+ ; assert_used_class(Src, Meta)
2871
+ ),
2872
+ assert_used_class(Src, Super).
2873
+
2874
+ assert_defined_class(Src, Name, imported_from(_File)) :-
2875
+ defined_class(Name, _, _, Src, _),
2876
+ !.
2877
+ assert_defined_class(Src, Name, imported_from(File)) :-
2878
+ assert(defined_class(Name, _, '', Src, file(File))).
2879
+
2880
+
2881
+ /********************************
2882
+ * UTILITIES *
2883
+ ********************************/
2884
+
2885
+ %! generalise(+Callable, -General)
2886
+ %
2887
+ % Generalise a callable term.
2888
+
2889
+ generalise(Var, Var) :-
2890
+ var(Var),
2891
+ !. % error?
2892
+ generalise(pce_principal:send_implementation(Id, _, _),
2893
+ pce_principal:send_implementation(Id, _, _)) :-
2894
+ atom(Id),
2895
+ !.
2896
+ generalise(pce_principal:get_implementation(Id, _, _, _),
2897
+ pce_principal:get_implementation(Id, _, _, _)) :-
2898
+ atom(Id),
2899
+ !.
2900
+ generalise('<directive>'(Line), '<directive>'(Line)) :- !.
2901
+ generalise(test(Test), test(Test)) :-
2902
+ current_test_unit(_,_),
2903
+ ground(Test),
2904
+ !.
2905
+ generalise(test(Test, _), test(Test, _)) :-
2906
+ current_test_unit(_,_),
2907
+ ground(Test),
2908
+ !.
2909
+ generalise('<test_unit>'(Line), '<test_unit>'(Line)) :- !.
2910
+ generalise(Module:Goal0, Module:Goal) :-
2911
+ atom(Module),
2912
+ !,
2913
+ generalise(Goal0, Goal).
2914
+ generalise(Term0, Term) :-
2915
+ callable(Term0),
2916
+ generalise_term(Term0, Term).
2917
+
2918
+
2919
+ /*******************************
2920
+ * SOURCE MANAGEMENT *
2921
+ *******************************/
2922
+
2923
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2924
+ This section of the file contains hookable predicates to reason about
2925
+ sources. The built-in code here can only deal with files. The XPCE
2926
+ library(pce_prolog_xref) provides hooks to deal with XPCE objects, so we
2927
+ can do cross-referencing on PceEmacs edit buffers. Other examples for
2928
+ hooking can be databases, (HTTP) URIs, etc.
2929
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2930
+
2931
+ :- multifile
2932
+ prolog:xref_source_directory/2, % +Source, -Dir
2933
+ prolog:xref_source_file/3. % +Spec, -Path, +Options
2934
+
2935
+
2936
+ %! xref_source_file(+Spec, -File, +Src) is semidet.
2937
+ %! xref_source_file(+Spec, -File, +Src, +Options) is semidet.
2938
+ %
2939
+ % Find named source file from Spec, relative to Src.
2940
+
2941
+ xref_source_file(Plain, File, Source) :-
2942
+ xref_source_file(Plain, File, Source, []).
2943
+
2944
+ xref_source_file(QSpec, File, Source, Options) :-
2945
+ nonvar(QSpec), QSpec = _:Spec,
2946
+ !,
2947
+ must_be(acyclic, Spec),
2948
+ xref_source_file(Spec, File, Source, Options).
2949
+ xref_source_file(Spec, File, Source, Options) :-
2950
+ nonvar(Spec),
2951
+ prolog:xref_source_file(Spec, File,
2952
+ [ relative_to(Source)
2953
+ | Options
2954
+ ]),
2955
+ !.
2956
+ xref_source_file(Plain, File, Source, Options) :-
2957
+ atom(Plain),
2958
+ \+ is_absolute_file_name(Plain),
2959
+ ( prolog:xref_source_directory(Source, Dir)
2960
+ -> true
2961
+ ; atom(Source),
2962
+ file_directory_name(Source, Dir)
2963
+ ),
2964
+ atomic_list_concat([Dir, /, Plain], Spec0),
2965
+ absolute_file_name(Spec0, Spec),
2966
+ do_xref_source_file(Spec, File, Options),
2967
+ !.
2968
+ xref_source_file(Spec, File, Source, Options) :-
2969
+ do_xref_source_file(Spec, File,
2970
+ [ relative_to(Source)
2971
+ | Options
2972
+ ]),
2973
+ !.
2974
+ xref_source_file(_, _, _, Options) :-
2975
+ option(silent(true), Options),
2976
+ !,
2977
+ fail.
2978
+ xref_source_file(Spec, _, Src, _Options) :-
2979
+ verbose(Src),
2980
+ print_message(warning, error(existence_error(file, Spec), _)),
2981
+ fail.
2982
+
2983
+ do_xref_source_file(Spec, File, Options) :-
2984
+ nonvar(Spec),
2985
+ option(file_type(Type), Options, prolog),
2986
+ absolute_file_name(Spec, File0,
2987
+ [ file_type(Type),
2988
+ access(read),
2989
+ file_errors(fail)
2990
+ ]),
2991
+ !,
2992
+ qlf_pl_file(File0, File).
2993
+ do_xref_source_file(Spec, File, Options) :-
2994
+ atom(Spec), % handle absolute /file/to/source.pl without sources
2995
+ file_name_extension(Base, Ext, Spec),
2996
+ user:prolog_file_type(Ext, source),
2997
+ option(file_type(prolog), Options, prolog),
2998
+ absolute_file_name(Base, File0,
2999
+ [ file_type(prolog),
3000
+ access(read),
3001
+ file_errors(fail)
3002
+ ]),
3003
+ qlf_pl_file(File0, File).
3004
+
3005
+ %! qlf_pl_file(?QlfFile, ?PlFile) is semidet.
3006
+
3007
+ qlf_pl_file(QlfFile, PlFile) :-
3008
+ nonvar(QlfFile),
3009
+ is_qlf_file(QlfFile),
3010
+ !,
3011
+ '$qlf_module'(QlfFile, Info),
3012
+ #{file:PlFile} :< Info.
3013
+ qlf_pl_file(QlfFile, PlFile) :-
3014
+ nonvar(PlFile),
3015
+ !,
3016
+ ( file_name_extension(Base, Ext, PlFile),
3017
+ user:prolog_file_type(Ext, source)
3018
+ -> true
3019
+ ),
3020
+ ( user:prolog_file_type(QlfExt, qlf),
3021
+ file_name_extension(Base, QlfExt, QlfFile),
3022
+ exists_file(QlfFile)
3023
+ -> true
3024
+ ),
3025
+ '$qlf_module'(QlfFile, Info),
3026
+ #{file:PlFile} :< Info,
3027
+ !.
3028
+ qlf_pl_file(PlFile, PlFile).
3029
+
3030
+ is_qlf_file(QlfFile) :-
3031
+ file_name_extension(_, Ext, QlfFile),
3032
+ user:prolog_file_type(Ext, qlf),
3033
+ !.
3034
+
3035
+ %! canonical_source(?Source, ?Src) is det.
3036
+ %
3037
+ % Src is the canonical version of Source if Source is given.
3038
+
3039
+ canonical_source(Source, Src) :-
3040
+ ( ground(Source)
3041
+ -> prolog_canonical_source(Source, Src)
3042
+ ; Source = Src
3043
+ ).
3044
+
3045
+ %! goal_name_arity(+Goal, -Name, -Arity)
3046
+ %
3047
+ % Generalized version of functor/3 that can deal with name()
3048
+ % goals.
3049
+
3050
+ goal_name_arity(Goal, Name, Arity) :-
3051
+ ( compound(Goal)
3052
+ -> compound_name_arity(Goal, Name, Arity)
3053
+ ; atom(Goal)
3054
+ -> Name = Goal, Arity = 0
3055
+ ).
3056
+
3057
+ generalise_term(Specific, General) :-
3058
+ ( compound(Specific)
3059
+ -> compound_name_arity(Specific, Name, Arity),
3060
+ compound_name_arity(General, Name, Arity)
3061
+ ; General = Specific
3062
+ ).
3063
+
3064
+ functor_name(Term, Name) :-
3065
+ ( compound(Term)
3066
+ -> compound_name_arity(Term, Name, _)
3067
+ ; atom(Term)
3068
+ -> Name = Term
3069
+ ).
3070
+
3071
+ rename_goal(Goal0, Name, Goal) :-
3072
+ ( compound(Goal0)
3073
+ -> compound_name_arity(Goal0, _, Arity),
3074
+ compound_name_arity(Goal, Name, Arity)
3075
+ ; Goal = Name
3076
+ ).
3077
+
3078
+
3079
+ /*******************************
3080
+ * MESSAGES *
3081
+ *******************************/<
3082
+
3083
+ :- multifile prolog:message//1.
3084
+
3085
+ prolog:message(meta_predicate_after_call(Decl, By)) -->
3086
+ { pi_head(ByPI, By) },
3087
+ [ ansi(code, ':- meta_predicate(~p)', [Decl]),
3088
+ ' declaration appears after call from '-[],
3089
+ ansi(code, '~p', [ByPI])
3090
+ ].