Comments (10)
I expanded the output for the debugging results. It look like for some reason it is marking the _lv_res_t
enum as a typedef when it isn't.
State : 100
Stack : translation_unit storage_class_specifier declaration_specifiers_no_type_opt . LexToken(ID,'_lv_res_t',52,6995)
Action : Reduce rule [declaration_specifiers_no_type -> storage_class_specifier declaration_specifiers_no_type_opt] with ['typedef',None] and goto state 25
Result : <dict @ 0x7f37f6256600> ({'qual': [], 'storage': ['typedef'], 'type': [], 'function': [], 'alignment': []})
from pycparser.
Please add a minimal, reproducible example
A small .c
file without any preprocessor directives that you observe the issue on.
from pycparser.
It's right there. I just gave you an example.
enum _lv_res_t {
LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action
function or an operation was failed*/
LV_RES_OK, /*The object is valid (no deleted) after the action*/
};
typedef _lv_res_t lv_res_t;
from pycparser.
This example still has comments that need to be removed manually. I asked for code that can be fed to pycparser directly without the preprocessor (which often obscures issue reports).
In any case, the code is invalid standard C, I believe, because the compiler does not know what _lv_res_t
is.
Trying your fragment with gcc -std=c99
, I get:
error: unknown type name ‘_lv_res_t’
7 | typedef _lv_res_t lv_res_t;
| ^~~~~~~~~
The right way to write this typedef would be:
typedef enum _lv_res_t lv_res_t;
from pycparser.
OK so I have done what you stated and this is what happens.
enum _lv_meter_indicator_type_t {
LV_METER_INDICATOR_TYPE_NEEDLE_IMG,
LV_METER_INDICATOR_TYPE_NEEDLE_LINE,
LV_METER_INDICATOR_TYPE_SCALE_LINES,
LV_METER_INDICATOR_TYPE_ARC,
};
typedef enum _lv_meter_indicator_type_t lv_meter_indicator_type_t;
Decl(name=None,
quals=[
],
align=[
],
storage=[
],
funcspec=[
],
type=Enum(name='_lv_meter_indicator_type_t',
values=EnumeratorList(enumerators=[Enumerator(name='LV_METER_INDICATOR_TYPE_NEEDLE_IMG',
value=None
),
Enumerator(name='LV_METER_INDICATOR_TYPE_NEEDLE_LINE',
value=None
),
Enumerator(name='LV_METER_INDICATOR_TYPE_SCALE_LINES',
value=None
),
Enumerator(name='LV_METER_INDICATOR_TYPE_ARC',
value=None
)
]
)
),
init=None,
bitsize=None
)
TypeDecl(declname='lv_meter_indicator_type_t',
quals=[
],
align=None,
type=Enum(name='_lv_meter_indicator_type_t',
values=None
)
)
see the issue there.
lv_meter_indicator_type_t
has the type of _lv_meter_indicator_type_t
but it has no values.
Those values should be apart of the lv_meter_indicator_type_t
type because lv_meter_indicator_type_t
is an alias for _lv_meter_indicator_type_t
from pycparser.
the type for lv_meter_indicator_type_t
should be the same instance as the type used in the Decl at the top.
from pycparser.
Oh and I am not sure why I am able to run the code through the preprocessor and it doesn't error at all. It also works with DOXYGEN without any issues. The original example I am referring to.
from pycparser.
Yes, that's how it works. pycparser just produces an AST for you, it doesn't do any semantic or type analysis. Note also that just:
typedef enum _lv_meter_indicator_type_t lv_meter_indicator_type_t;
... is perfectly valid C. The enum
type doesn't have to be declared.
The AST you have from pycparser has all the information you need -- you can see the type the typedef
is referring to, find that type in the AST and extract whatever you need from it.
from pycparser.
There is no link between the 2 enumerations made?.. what you are telling me is I have to iterate over the entire ast again in order to locate the type used in the typedef? That's crazy to have to do that. There should be some kind of a link between a typedef and it's parent type if there is one available.
from pycparser.
so if I use this code
typedef enum _example {
some_enumeration=0,
} example;
is some_enumeration
a descendant of example
?
I believe it is.
enum _example {
some_enumeration=0,
};
typedef enum _example example;
but it's not if I do this?...
They are both the same thing. They do the same thing...
from pycparser.
Related Issues (20)
- 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
- type cast parsing error in (__typeof(h))spa_meta_first(m) line, __typeof(h) type is not allowed by parser rules HOT 1
- pycparser.plyparser.ParseError when running the example code on .h
- Constant string concatenation HOT 4
- A variable which declared as static within a function causes parser to fail with an error ":4700:18: before: locale" HOT 3
- using_gcc_E_libc example is ran during tests in an LLVM only setup HOT 6
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.