GithubHelp home page GithubHelp logo

Implement implicit typedefs about pycparser HOT 5 CLOSED

eliben avatar eliben commented on June 6, 2024
Implement implicit typedefs

from pycparser.

Comments (5)

eliben avatar eliben commented on June 6, 2024

Can you elaborate on how I can distinguish a storage type from just an undefined variable? E.g.

foo * bar;

Is this a pointer to foo named bar or just a multiplication of two variables? Note that pycparser does not run semantic analysis so it doesn't know which variables were previously defined.

from pycparser.

allfro avatar allfro commented on June 6, 2024

Hi @eliben,

The use case I'm looking at for this has specifically to do with typedef statements, i.e.:

typedef __builtin_va_list __darwin_va_list;

At this point parse_file returns an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.8-intel/egg/pycparser/__init__.py", line 93, in parse_file

  File "build/bdist.macosx-10.8-intel/egg/pycparser/c_parser.py", line 138, in parse
  File "build/bdist.macosx-10.8-intel/egg/pycparser/ply/yacc.py", line 265, in parse
  File "build/bdist.macosx-10.8-intel/egg/pycparser/ply/yacc.py", line 1047, in parseopt_notrack
  File "build/bdist.macosx-10.8-intel/egg/pycparser/c_parser.py", line 1613, in p_error
  File "build/bdist.macosx-10.8-intel/egg/pycparser/plyparser.py", line 54, in _parse_error
pycparser.plyparser.ParseError: test.h:20:27: before: __darwin_va_list

Perhaps this could be skipped if some sort of dont_fail_on_unknown flag is set in the call to the parser. Kinda like:

>>> parser = parse_file('foo.c', warn_only=True)
Warning: pycparser.plyparser.ParseError: test.h:20:27: before: __darwin_va_list... skipping

This way it is really up to the user who's using the lib to decide whether or not they want strict parsing or not. The reason why I ask this is because I'd like to write a lib that reads an include file and generates a ctypes binding for python. That way I can save myself from hand writing all the ctypes definitions of the functions, their arguments, and their return types as well as any data structures that may exist. I should also add that I would like other users to use this generator for their own projects. As not everyone who is a python developer understands or codes in C, it would be nice to make it as user friendly as possible to avoid them having to fine tune the output of gcc -E -P.

from pycparser.

allfro avatar allfro commented on June 6, 2024

Instead of completely skipping an element perhaps an UnknownDecl with the line statement that failed could be emitted if this option is enabled?

from pycparser.

eliben avatar eliben commented on June 6, 2024

Feel free to propose a patch, but I think it will be more difficult than it's worth, really. I assume pycparser runs on code that has been compiled, so these type definitions do exist somewhere. The fake libc headers already cover most use cases and it's trivial to add new types to them. On the other hand, tweaking such special-case rules in pycparser is not trivial. But feel free to prove me wrong :)

from pycparser.

eliben avatar eliben commented on June 6, 2024

Closing for now. If you want to submit a pull request with proposed patches, go ahead.

from pycparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.