<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span class="">Hi All!</span><span class=""><br class=""></span><span class=""><br class=""></span><span class="">I’m writing to propose clang-extract-api, a tool to collect and serialize API information from header files, for example function signatures, Objective-C interfaces and protocols, and inline documentation comments. We hope it could help future tools to understand clang-based language APIs without needing to dig into the AST themselves.</span><span class=""><br class=""></span><span class=""><br class=""></span><div class=""><span class=""><font size="4" class=""><b class="">Background<br class=""></b></font><br class=""></span><span class=""><span style="font-size: 14px;" class=""><b class="">Motivation</b></span><br class=""><br class=""></span><span class="">Library and SDK providers may find it useful to be able to create and inspect a “snapshot” of APIs they expose, for example, to check for API/ABI-breaking changes between two versions, or to automate generating documentation for the APIs. Here is a list of examples of information we want to extract from APIs:</span><span class=""><br class=""></span><span class=""><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• the name (spelling/mangled) of the symbol;<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>• the unique identifier of the symbol, for example the Unified Symbol Resolution (USR);<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>• the source location of the API declaration (file, line, column);<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• access control of the API (public/private/protected);<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>• availability (available/unavailable/deprecated);<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• function signatures (return/parameters);<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• documentation comments attached to a symbol;<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>• relations with other symbols (class methods, typedef relations, struct data fields, enum constants, etc.)<br class=""></div></span><span class="">Since these API information is available in the header files, which declare and distribute the APIs, we can implement a tool to extract them without invoking a compilation of the whole project to enable easy access to the information for tooling.</span></div><div class=""><span class=""><br class=""></span><span class=""><span style="font-size: 14px;" class=""><b class="">Existing solutions</b></span><br class=""><br class=""></span><span class="">While there are some existing solutions in clang to dump symbols or AST information, they either expose unnecessary low-level details or fail to provide enough information of APIs. For example, clang -ast-dump dumps low-level details for all declarations for debug purposes and the output is not machine-parsable. Doxygen also extracts documentation comments and other information from API declarations, but its output is rendered documentation in web formats which is not flexible for other uses and tools.</span></div><div class=""><span class=""><br class=""></span><span class=""><b class=""><font size="4" class="">Proposal</font></b><br class=""><br class=""></span><span class="">We propose to implement this tool as a new frontend action invoked by `clang -extract-api` as show in the example below.</span></div><div class=""><span class=""><br class=""></span><span class=""><font face="Menlo" class="">clang -extract-api \<br class="">  header.h [more_header.h ...] or a filelist\<br class="">  -isysroot <SDK> \<br class="">  -target <TARGET> \<br class="">  -I <INCLUDE PATH> \<br class="">  -isystem <SYS INCLUDE PATH> \<br class="">  ...<br class="">  -o output.json</font></span></div><div class=""><span class=""><font face="Menlo" class=""><br class=""></font></span><span class="">It takes in the header file(s) or a filelist file containing paths to the header file(s) as the input. The header files will be parsed by clang and the extract-api action will visit the AST to extract needed information and serialize to a JSON output. Please find an example input and output attached.</span><span class=""><br class=""></span><span class=""><br class=""></span><span class="">The example output is based on the symbol graph format that's already used by Swift for serializing symbol information and their relations. This format can represent the required API information and is flexible and extendable as demonstrated in the example so we think it's a good starting point.</span><span class=""><br class=""></span><span class=""><br class=""></span><span class="">We are excited about this idea and its potential uses, and we’d love to hear feedback and suggestions!</span><br class=""></div><div class=""><span class=""><br class=""></span></div><div class=""></div></body></html>