首页 > 解决方案 > pycparser 中的未知 uint8_t 类型

问题描述

我正在尝试解析 C 函数声明。正如它所具有uint8_tuint16_t那样,pycparser 无法识别这种类型。

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);

这是我想要解析和创建的代码,但它给出了以 uint8_t 作为标识符的参数测试的函数声明错误

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

如何在 pycparser 中包含这些类型?

标签: pythoncpycparser

解决方案


推荐阅读