You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
3.7 KiB

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>ClangFrontend (infer.ClangFrontend)</title><link rel="stylesheet" href="../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="index.html">Up</a> <a href="index.html">infer</a> &#x00BB; ClangFrontend</nav><h1 id="clang-frontend"><a href="#clang-frontend" class="anchor"></a>Clang Frontend</h1><p>Translates code that <a href="https://clang.llvm.org/"><code>Clang</code></a> understands into Infer's intermediate representation language <a href="IR/Sil/index.html"><code>IR.Sil</code></a>.</p><p>All modules: <a href="ClangFrontend/index.html"><code>ClangFrontend</code></a></p><nav class="toc"><ul><li><a href="#capturing-source-files">Capturing source files</a></li><li><a href="#quick-guide-to-changing-the-ast-format">Quick guide to changing the AST format</a></li><li><a href="#tips-&amp;-tricks">Tips &amp; Tricks</a></li></ul></nav></header><h2 id="capturing-source-files"><a href="#capturing-source-files" class="anchor"></a>Capturing source files</h2><p>Start at <a href="ClangFrontend/Capture/index.html"><code>ClangFrontend.Capture</code></a> for how Infer uses Clang to parse source files, using our Clang plugin. For more information on our clang plugin itself, refer to the relevant documentation in <code>facebook-clang-plugins</code>:</p><ul><li><a href="https://github.com/facebook/facebook-clang-plugins/blob/master/libtooling/ATD_GUIDELINES.md"><code>facebook-clang-plugins/libtooling/ATD_GUIDELINES.md</code></a></li><li><a href="https://github.com/facebook/facebook-clang-plugins/blob/master/clang-ocaml/README.md"><code>facebook-clang-plugins/clang-ocaml/README.md</code></a></li></ul><h2 id="quick-guide-to-changing-the-ast-format"><a href="#quick-guide-to-changing-the-ast-format" class="anchor"></a>Quick guide to changing the AST format</h2><ol><li>Create a simple example (<code>example.cpp</code>) source file with construct that needs to be exported. The smaller the better.</li><li>Export the extra information by changing the code in <a href="https://github.com/facebook/facebook-clang-plugins/blob/master/libtooling/ASTExporter.h"><code>libtooling/ASTExporter.h</code></a>. For more information, refer to the <a href="https://github.com/facebook/facebook-clang-plugins/blob/master/libtooling/ATD_GUIDELINES.md"><code>ATD_GUIDELINES</code></a>.</li><li>Compile Infer with the new version of <code>facebook-clang-plugins</code>. Running <code>make</code> from top level of Infer repository will do that. Sometimes there may be compilation errors due to <code>.atd</code> file changes --they need to be fixed.</li><li>Use newly-exported information in the frontend as you please.</li></ol><h2 id="tips-&amp;-tricks"><a href="#tips-&amp;-tricks" class="anchor"></a>Tips &amp; Tricks</h2><ul><li>To view the AST in a human readable version, Infer can generate <code>.bdump</code> files: <code>infer -g -- clang -c example.cpp &amp;&amp; sh example.cpp.ast.sh</code>. Then open <code>example.cpp.ast.bdump</code>.</li><li>To inspect the AST visually: <code>clang -c example.cpp -Xclang -ast-dump</code>. It doesn't include all the information that Infer sees, but it's often a good place to start.</li><li>If running <code>bdump</code> is failing (it happens on huge sources sometimes), there is a way to view it in &quot;Yojson&quot; format. To do that, replace all occurrences of <code>BiniouASTExporter</code> with <code>YojsonASTExporter</code> in the <code>.ast.sh</code> debug script.</li></ul></div></body></html>