<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 1, 2021, at 11:46 PM, Petr Hosek <<a href="mailto:phosek@chromium.org" class="">phosek@chromium.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="">In Fuchsia, we have been using clang-doc (<a href="https://clang.llvm.org/extra/clang-doc.html" class="">https://clang.llvm.org/extra/clang-doc.html</a>) for this purpose (using the YAML output format). Would it be possible to use clang-doc for your purposes?</div></div></div></blockquote><div><br class=""></div><div>We’ve looked into clang-doc when planning and designing clang-extract-api. Our conclusion is that though clang-doc looks great and works by extracting information from the clang AST, it still does not fit the purpose of clang-extract-api 100%, as it’s focus is on documentation generation. And we think it’s okay to have two separate tools in this case. In the future more fields might become of-interest for one tool but not the other and it’s good to have the input/output conventions separated.</div><div>Another reason is that we would like to implement the core functionalities of clang-extract-api in libclang so that it could enable more use cases. Clang-doc lives in clang-tools-extra and is more like an endpoint tool. One possibility is that we could refactor clang-doc to re-use the AST visitor implemented by clang-extract-api (in libclang) and have the two tools process and serialize the extracted information in their own ways.</div><div><br class=""></div><div>Zixu</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="">You might need to extend the output format to include additional information but that should be quite straightforward.</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 1, 2021 at 11:19 AM Zixu Wang via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="overflow-wrap: break-word;" 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 style="white-space: pre-wrap;" class=""> </span>• the name (spelling/mangled) of the symbol;<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• the unique identifier of the symbol, for example the Unified Symbol Resolution (USR);<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• the source location of the API declaration (file, line, column);<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• access control of the API (public/private/protected);<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• availability (available/unavailable/deprecated);<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• function signatures (return/parameters);<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </span>• documentation comments attached to a symbol;<br class=""></div><div class=""><span style="white-space: pre-wrap;" class=""> </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=""> <span class="Apple-converted-space"> </span>header.h [more_header.h ...] or a filelist\<br class=""> <span class="Apple-converted-space"> </span>-isysroot <SDK> \<br class=""> <span class="Apple-converted-space"> </span>-target <TARGET> \<br class=""> <span class="Apple-converted-space"> </span>-I <INCLUDE PATH> \<br class=""> <span class="Apple-converted-space"> </span>-isystem <SYS INCLUDE PATH> \<br class=""> <span class="Apple-converted-space"> </span>...<br class=""> <span class="Apple-converted-space"> </span>-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></div><div style="overflow-wrap: break-word;" class=""><div class=""></div></div><div style="overflow-wrap: break-word;" class=""><div class=""></div><div class=""><span class=""><br class=""></span></div></div>_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></blockquote></div></div></div></blockquote></div><br class=""></body></html>