You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might be ambitious, but I'm trying to parse /usr/include/math.h (on OS X)
Here's what I have so far:
f='/usr/include/math.h'prep=C::Preprocessor.new# XXX: bug #4prep.pwd=File.expand_path('.')source=prep.preprocess_file(f)# XXX: there seem to still be some '#' lines, which cause Cast to chokesource.gsub!(/(^\#.+)/,'')beginast=C.parse(source)rescueC::ParseError=>epe# XXX: feature request #3line_num=e.message.match(/\d*/)[0].to_iputssource.lines.to_a[line_num-1]end
The output of which is:
#<C::ParseError: 32:0: parse error on LPAREN (LPAREN)>
inline __attribute__ ((__always_inline__)) int __inline_isfinitel(long double);
So my guess is Cast doesn't support __attribute__, which I understand is not part of the C spec, but unfortunately is somewhat common in actual code. Description here: http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html with all its infelicities.
The text was updated successfully, but these errors were encountered:
Can you just add __attribute__ as a macro that expands to nothing?
I think adding explicit support for this will be something of a slippery slope. Each compiler seems to do its own weird thing.
If there was a good way to package up compiler-specific tweaks for stuff like this, I'd go for it, but I don't have the time to implement it myself. Happy to discuss if it's something you're keen to send a PR for. :)
I have an implementation of __attribute__ ready. Just waiting to see if my first PR will be accepted before opening that one.
In response to @oggy's concern, one option would be to add separate classes C::Parser::ANSI and C::Parser::GNU, one which just accepts "vanilla" C, and one which accepts all the GCC extensions.
It might be ambitious, but I'm trying to parse
/usr/include/math.h
(on OS X)Here's what I have so far:
The output of which is:
So my guess is Cast doesn't support
__attribute__
, which I understand is not part of the C spec, but unfortunately is somewhat common in actual code. Description here: http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html with all its infelicities.The text was updated successfully, but these errors were encountered: