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, but it gives error for function declaration of test for parameter with uint8_t as identifier

Traceback (most recent call last):
  File "examples/func_calls.py", line 48, in <module>
    show_func_calls(filename, func)
  File "examples/func_calls.py", line 34, in show_func_calls
    ast = parse_file(filename, use_cpp=True,cpp_args= r'-I../utils/fake_libc_include')
  File "./pycparser/__init__.py", line 90, in parse_file
    return parser.parse(text, filename)
  File "./pycparser/c_parser.py", line 152, in parse
    debug=debuglevel)
  File "./pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "./pycparser/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "./pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "./pycparser/c_parser.py", line 1865, in p_error
    column=self.clex.find_tok_column(p)))
  File "./pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: /usr/include/stdint.h:48:23: before: uint8_t

How to include these types in pycparser?

来源:https://stackoverflow.com/questions/65390685/unknown-uint8-t-type-in-pycparser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!