Note that there are some explanatory texts on larger screens.

plurals
  1. POClang for fuzzy parsing C++
    primarykey
    data
    text
    <p>Is it at all possible to parse C++ with incomplete declarations with clang with its existing libclang API ? I.e. parse .cpp file without including all the headers, deducing declarations on the fly. so, e.g. The following text:</p> <pre><code>A B::Foo(){return stuff();} </code></pre> <p>Will detect unknown symbol A, call my callback that deducts A is a class using my magic heuristic, then call this callback the same way with B and Foo and stuff. In the end I want to be able to infer that I saw a member Foo of class B returning A, and stuff is a function.. Or something to that effect. context: I wanna see if I can do sensible syntax highlighting and on the fly code analysis without parsing all the headers very quickly.</p> <p>[EDIT] To clarify, I'm looking for very heavily restricted C++ parsing, possibly with some heuristic to lift some of the restrictions.</p> <p>C++ grammar is full of context dependencies. Is Foo() a function call or a construction of a temporary of class Foo? Is Foo&lt;Bar&gt; stuff; a template Foo&lt;Bar&gt; instantiation and declaration of variable stuff, or is it weird-looking 2 calls to overloaded operator &lt; and operator > ? It's only possible to tell in context, and context often comes from parsing the headers.</p> <p>What I'm looking for is a way to plug my custom convention rules. E.g. I know that I don't overload Win32 symbols, so I can safely assume that CreateFile is <em>always</em> a function, and I even know its signature. I also know that all my classes start with a capital letter and are nouns, and functions are usually verbs, so I can reasonably guess that Foo and Bar are class names. In a more complex scenario, I know I don't write side-effect-free expressions like a &lt; b > c; so I can assume that a is always a template instantiation. And so on.</p> <p>So, the question is whether it's possible to use Clang API to call back every time it encounters an unknown symbol, and give it an answer using my own non-C++ heuristic. If my heuristic fails, then the parse fails, obviously. And I'm not talking about parsing Boost library :) I'm talking about very simple C++, probably without templates, restricted to some minimum that clang can handle in this case. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload