Skip to content

__attribute__ #7

@ghazel

Description

@ghazel

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 #4
prep.pwd = File.expand_path('.')
source = prep.preprocess_file(f)
# XXX: there seem to still be some '#' lines, which cause Cast to choke
source.gsub!(/(^\#.+)/, '')
begin
  ast = C.parse(source)
rescue C::ParseError => e
  p e
  # XXX: feature request #3
  line_num = e.message.match(/\d*/)[0].to_i
  puts source.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions