pycparser

Unknown uint8_t type in pycparser

China☆狼群 提交于 2021-02-11 14:59:54
问题 I am trying to parse a C function declaration. As it has uint8_t , uint16_t in it, pycparser is unable to recognize this type. typedef enum tagReturnCode {SUCCESS, FAIL} ReturnCode; typedef struct tagEntry { char* key; char* value; } Entry; typedef struct tagNode { Entry* entry; struct tagNode* next; } Node; typedef struct tagHash { unsigned int table_size; Node** heads; } Hash; void test(uint8_t res[], int* op1[], int op2[], char n); This is code that I want to parse and create ast of that,

Find all macro definition in c header file

孤街醉人 提交于 2021-01-29 08:30:12
问题 I am trying to get list of all macro definitions in a c header file by using pycparser. Can you please help me on this issue with an example if possible? Thanks. 回答1: Try using pyparsing instead... from pyparsing import * # define the structure of a macro definition (the empty term is used # to advance to the next non-whitespace character) macroDef = "#define" + Word(alphas+"_",alphanums+"_").setResultsName("macro") + \ empty + restOfLine.setResultsName("value") with open('myheader.h', 'r')

Extracting input parameters and its Identifier type While parsing a c file using PycParser

末鹿安然 提交于 2019-12-11 12:05:33
问题 Note: Ones who are familiar with pycparser would understand the problem much better. I am using pycparser v2.10 and I am trying to extract all the functions that have been defined in the C file as well extract its input parameter name and identifier type While parsing that C file (Using pycparser). Code sample import sys sys.path.extend(['.', '..']) CPPPATH = '../utils/cpp.exe' if sys.platform == 'win32' else 'cpp' from pycparser import c_parser, c_ast, parse_file class FunctionParameter(c

python pycparser setup error

微笑、不失礼 提交于 2019-12-09 10:28:53
问题 I am seeing the following error while setting up pyparser on CentOS 7 via pip /usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-PMzCYU/pycparser/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-0bpBrX-record/install-record.txt --single-version-externally-managed --compile Traceback (most recent call last): File "", line 1, in init.py", line 12, in import setuptools.version

Pycparser not working on preprocessed code

时光毁灭记忆、已成空白 提交于 2019-12-06 13:02:36
问题 I need to use pycparser on preprocessed C code (the results produced by 'gcc -E'). However I am currently running into issue that I can't understand or solve. I am using the provided samples year2.c and func_defs.py, which i modified to use a variety of preprocessors and fake libraries to no avail. Maybe some of you can look into this and see if you can reproduce/solve the issue. I will append all necessary code. The errors were generated using year2.c (regular sample file) and year2.i ('gcc

Pycparser not working on preprocessed code

喜欢而已 提交于 2019-12-04 19:52:33
I need to use pycparser on preprocessed C code (the results produced by 'gcc -E'). However I am currently running into issue that I can't understand or solve. I am using the provided samples year2.c and func_defs.py, which i modified to use a variety of preprocessors and fake libraries to no avail. Maybe some of you can look into this and see if you can reproduce/solve the issue. I will append all necessary code. The errors were generated using year2.c (regular sample file) and year2.i ('gcc -E' output). There was no useable result for the latter while the former worked with both preprocessor