Comments (5)
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.
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.
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.
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.
Closing for now. If you want to submit a pull request with proposed patches, go ahead.
from pycparser.
Related Issues (20)
- AssertionError
- Two-dimensional array binding type problem HOT 1
- Is there a release plan for the next version of pycparser?
- parser error with typedef HOT 10
- assertion error on gcc-9 stddef.h
- Is there a way to find the function declaration matching a function call? HOT 1
- CParser doesn't work with comments HOT 1
- Add end of token coord
- Unable to parse labels at end of block HOT 1
- BUG: pycparser treats empty declarations as a binary operation HOT 1
- TypeError:'Nonetype' object is not callable HOT 5
- "sorry, but this version only supports 100 named groups" HOT 1
- Parsing `va_arg(foo, type)` HOT 3
- Unable to parse through comments and can't support directives HOT 2
- Parser can't handle unknown data types for variables HOT 1
- Parser unbale to handle custom data types for custom functions HOT 1
- Parehthesized compount statements HOT 3
- Can't parse function declaration with unnamed static array HOT 1
- Implement the collections.abc.Sequence interface for e. g. class Node HOT 1
- c_ast.cpython-*.pyc is rewritten after it is installed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycparser.