Last active
April 5, 2019 21:42
-
-
Save kastiglione/e3749a05041b7765c7a0016ae461f91a to your computer and use it in GitHub Desktop.
Prolog predicates to detangle Swift symbols and USRs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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