title: Using ClangTool to parse a string
body: <p>The following code successfully sets up a ClangTool for parsing:</p>
  
  <pre><code>std::vector&lt;std::string&gt; source_files;
  cl::OptionCategory option_category("options");
  CommonOptionsParser options_parser(argc, argv, option_category);
  ClangTool tool(options_parser.getCompilations(), source_files);
  </code></pre>
  
  <p>However, I created argc and argv on my own -- they didn't come from main().  Instead of an input file, is it possible to get the ClangTool to parse the contents of a string?  E.g.,</p>
  
  <pre><code>const char *str = "extern int foo;\n";
  </code></pre>
  
  <p>mapVirtualFile() looked like what I wanted, but when I tried, foo didn't come out of it.</p>
  
  <pre><code>tool.mapVirtualFile(StringRef("faux_file.c"), StringRef(str));
  // Then proceed to tool.run(...), etc.
  </code></pre>
  
  <p>I could create a temporary file in /tmp, but I'd like to simply read from the string.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Creating a temporary file works.  It's kind of hack-ish, but it's stable and consistent.  It would be nice to have a way of inputting from a string, but it doesn't seem possible with the existing implementation.</p>