Skip to content

Instantly share code, notes, and snippets.

@kastiglione
Last active April 5, 2019 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastiglione/e3749a05041b7765c7a0016ae461f91a to your computer and use it in GitHub Desktop.
Save kastiglione/e3749a05041b7765c7a0016ae461f91a to your computer and use it in GitHub Desktop.
Prolog predicates to detangle Swift symbols and USRs
swift_demangle(Symbol, Name) :-
Command = ['swift-demangle', '-compact', Symbol],
setup_call_cleanup(
process_create(path(xcrun), Command, [stdout(pipe(Out))]),
read_string(Out, "\n", "", _, Name),
close(Out)
).
usr_symbol(USR, Symbol) :-
(
sub_string(USR, 0, Offset, _, "s:e:s:"), !;
sub_string(USR, 0, Offset, _, "s:e:c:"), !;
sub_string(USR, 0, Offset, _, "s:")
),
sub_string(USR, Offset, _, 0, Suffix),
string_concat("$S", Suffix, Symbol).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment