- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是解析方面的新手,我正在尝试使用 Pycparser 来解析我的 c 文件,我按照说明预处理文件 gcc -E 然后我使用示例文件夹中的 using_gcc_E_libc.py 并传递我的文件,我得到了一些输出,但不确定 AST 是否是这样的?如果那是正确的 AST,我如何找到每个节点及其依赖项以及该节点的指针(位置)?
FileAST:
Typedef: size_t, [], ['typedef']
TypeDecl: size_t, []
IdentifierType: ['int']
Typedef: __builtin_va_list, [], ['typedef']
TypeDecl: __builtin_va_list, []
IdentifierType: ['int']
Typedef: __gnuc_va_list, [], ['typedef']
TypeDecl: __gnuc_va_list, []
IdentifierType: ['int']
Typedef: va_list, [], ['typedef']
TypeDecl: va_list, []
IdentifierType: ['int']
Typedef: __int8_t, [], ['typedef']
TypeDecl: __int8_t, []
IdentifierType: ['int']
Typedef: __uint8_t, [], ['typedef']
TypeDecl: __uint8_t, []
IdentifierType: ['int']
Typedef: __int16_t, [], ['typedef']
TypeDecl: __int16_t, []
IdentifierType: ['int']
Typedef: __uint16_t, [], ['typedef']
TypeDecl: __uint16_t, []
IdentifierType: ['int']
Typedef: __int_least16_t, [], ['typedef']
TypeDecl: __int_least16_t, []
IdentifierType: ['int']
Typedef: __uint_least16_t, [], ['typedef']
TypeDecl: __uint_least16_t, []
IdentifierType: ['int']
Typedef: __int32_t, [], ['typedef']
TypeDecl: __int32_t, []
IdentifierType: ['int']
Typedef: __uint32_t, [], ['typedef']
TypeDecl: __uint32_t, []
IdentifierType: ['int']
Typedef: __int64_t, [], ['typedef']
TypeDecl: __int64_t, []
IdentifierType: ['int']
Typedef: __uint64_t, [], ['typedef']
TypeDecl: __uint64_t, []
IdentifierType: ['int']
Typedef: __int_least32_t, [], ['typedef']
TypeDecl: __int_least32_t, []
IdentifierType: ['int']
Typedef: __uint_least32_t, [], ['typedef']
TypeDecl: __uint_least32_t, []
IdentifierType: ['int']
Typedef: __s8, [], ['typedef']
TypeDecl: __s8, []
IdentifierType: ['int']
Typedef: __u8, [], ['typedef']
TypeDecl: __u8, []
IdentifierType: ['int']
Typedef: __s16, [], ['typedef']
TypeDecl: __s16, []
IdentifierType: ['int']
Typedef: __u16, [], ['typedef']
TypeDecl: __u16, []
IdentifierType: ['int']
Typedef: __s32, [], ['typedef']
TypeDecl: __s32, []
IdentifierType: ['int']
Typedef: __u32, [], ['typedef']
TypeDecl: __u32, []
IdentifierType: ['int']
Typedef: __s64, [], ['typedef']
TypeDecl: __s64, []
IdentifierType: ['int']
Typedef: __u64, [], ['typedef']
TypeDecl: __u64, []
IdentifierType: ['int']
Typedef: _LOCK_T, [], ['typedef']
TypeDecl: _LOCK_T, []
IdentifierType: ['int']
Typedef: _LOCK_RECURSIVE_T, [], ['typedef']
TypeDecl: _LOCK_RECURSIVE_T, []
IdentifierType: ['int']
Typedef: _off_t, [], ['typedef']
TypeDecl: _off_t, []
IdentifierType: ['int']
Typedef: __dev_t, [], ['typedef']
TypeDecl: __dev_t, []
IdentifierType: ['int']
Typedef: __uid_t, [], ['typedef']
TypeDecl: __uid_t, []
IdentifierType: ['int']
Typedef: __gid_t, [], ['typedef']
TypeDecl: __gid_t, []
IdentifierType: ['int']
Typedef: _off64_t, [], ['typedef']
TypeDecl: _off64_t, []
IdentifierType: ['int']
Typedef: _fpos_t, [], ['typedef']
TypeDecl: _fpos_t, []
IdentifierType: ['int']
Typedef: _ssize_t, [], ['typedef']
TypeDecl: _ssize_t, []
IdentifierType: ['int']
Typedef: wint_t, [], ['typedef']
TypeDecl: wint_t, []
IdentifierType: ['int']
Typedef: _mbstate_t, [], ['typedef']
TypeDecl: _mbstate_t, []
IdentifierType: ['int']
Typedef: _flock_t, [], ['typedef']
TypeDecl: _flock_t, []
IdentifierType: ['int']
Typedef: _iconv_t, [], ['typedef']
TypeDecl: _iconv_t, []
IdentifierType: ['int']
Typedef: __ULong, [], ['typedef']
TypeDecl: __ULong, []
IdentifierType: ['int']
Typedef: __FILE, [], ['typedef']
TypeDecl: __FILE, []
IdentifierType: ['int']
Typedef: ptrdiff_t, [], ['typedef']
TypeDecl: ptrdiff_t, []
IdentifierType: ['int']
Typedef: wchar_t, [], ['typedef']
TypeDecl: wchar_t, []
IdentifierType: ['int']
Typedef: __off_t, [], ['typedef']
TypeDecl: __off_t, []
IdentifierType: ['int']
Typedef: __pid_t, [], ['typedef']
TypeDecl: __pid_t, []
IdentifierType: ['int']
Typedef: __loff_t, [], ['typedef']
TypeDecl: __loff_t, []
IdentifierType: ['int']
Typedef: u_char, [], ['typedef']
TypeDecl: u_char, []
IdentifierType: ['int']
Typedef: u_short, [], ['typedef']
TypeDecl: u_short, []
IdentifierType: ['int']
Typedef: u_int, [], ['typedef']
TypeDecl: u_int, []
IdentifierType: ['int']
Typedef: u_long, [], ['typedef']
TypeDecl: u_long, []
IdentifierType: ['int']
Typedef: ushort, [], ['typedef']
TypeDecl: ushort, []
IdentifierType: ['int']
Typedef: uint, [], ['typedef']
TypeDecl: uint, []
IdentifierType: ['int']
Typedef: clock_t, [], ['typedef']
TypeDecl: clock_t, []
IdentifierType: ['int']
Typedef: time_t, [], ['typedef']
TypeDecl: time_t, []
IdentifierType: ['int']
Typedef: daddr_t, [], ['typedef']
TypeDecl: daddr_t, []
IdentifierType: ['int']
Typedef: caddr_t, [], ['typedef']
TypeDecl: caddr_t, []
IdentifierType: ['int']
Typedef: ino_t, [], ['typedef']
TypeDecl: ino_t, []
IdentifierType: ['int']
Typedef: off_t, [], ['typedef']
TypeDecl: off_t, []
IdentifierType: ['int']
Typedef: dev_t, [], ['typedef']
TypeDecl: dev_t, []
IdentifierType: ['int']
Typedef: uid_t, [], ['typedef']
TypeDecl: uid_t, []
IdentifierType: ['int']
Typedef: gid_t, [], ['typedef']
TypeDecl: gid_t, []
IdentifierType: ['int']
Typedef: pid_t, [], ['typedef']
TypeDecl: pid_t, []
IdentifierType: ['int']
Typedef: key_t, [], ['typedef']
TypeDecl: key_t, []
IdentifierType: ['int']
Typedef: ssize_t, [], ['typedef']
TypeDecl: ssize_t, []
IdentifierType: ['int']
Typedef: mode_t, [], ['typedef']
TypeDecl: mode_t, []
IdentifierType: ['int']
Typedef: nlink_t, [], ['typedef']
TypeDecl: nlink_t, []
IdentifierType: ['int']
Typedef: fd_mask, [], ['typedef']
TypeDecl: fd_mask, []
IdentifierType: ['int']
Typedef: _types_fd_set, [], ['typedef']
TypeDecl: _types_fd_set, []
IdentifierType: ['int']
Typedef: clockid_t, [], ['typedef']
TypeDecl: clockid_t, []
IdentifierType: ['int']
Typedef: timer_t, [], ['typedef']
TypeDecl: timer_t, []
IdentifierType: ['int']
Typedef: useconds_t, [], ['typedef']
TypeDecl: useconds_t, []
IdentifierType: ['int']
Typedef: suseconds_t, [], ['typedef']
TypeDecl: suseconds_t, []
IdentifierType: ['int']
Typedef: FILE, [], ['typedef']
TypeDecl: FILE, []
IdentifierType: ['int']
Typedef: fpos_t, [], ['typedef']
TypeDecl: fpos_t, []
IdentifierType: ['int']
Typedef: cookie_read_function_t, [], ['typedef']
TypeDecl: cookie_read_function_t, []
IdentifierType: ['int']
Typedef: cookie_write_function_t, [], ['typedef']
TypeDecl: cookie_write_function_t, []
IdentifierType: ['int']
Typedef: cookie_seek_function_t, [], ['typedef']
TypeDecl: cookie_seek_function_t, []
IdentifierType: ['int']
Typedef: cookie_close_function_t, [], ['typedef']
TypeDecl: cookie_close_function_t, []
IdentifierType: ['int']
Typedef: cookie_io_functions_t, [], ['typedef']
TypeDecl: cookie_io_functions_t, []
IdentifierType: ['int']
Typedef: div_t, [], ['typedef']
TypeDecl: div_t, []
IdentifierType: ['int']
Typedef: ldiv_t, [], ['typedef']
TypeDecl: ldiv_t, []
IdentifierType: ['int']
Typedef: lldiv_t, [], ['typedef']
TypeDecl: lldiv_t, []
IdentifierType: ['int']
Typedef: sigset_t, [], ['typedef']
TypeDecl: sigset_t, []
IdentifierType: ['int']
Typedef: __sigset_t, [], ['typedef']
TypeDecl: __sigset_t, []
IdentifierType: ['int']
Typedef: _sig_func_ptr, [], ['typedef']
TypeDecl: _sig_func_ptr, []
IdentifierType: ['int']
Typedef: sig_atomic_t, [], ['typedef']
TypeDecl: sig_atomic_t, []
IdentifierType: ['int']
Typedef: __tzrule_type, [], ['typedef']
TypeDecl: __tzrule_type, []
IdentifierType: ['int']
Typedef: __tzinfo_type, [], ['typedef']
TypeDecl: __tzinfo_type, []
IdentifierType: ['int']
Typedef: mbstate_t, [], ['typedef']
TypeDecl: mbstate_t, []
IdentifierType: ['int']
Typedef: sem_t, [], ['typedef']
TypeDecl: sem_t, []
IdentifierType: ['int']
Typedef: pthread_t, [], ['typedef']
TypeDecl: pthread_t, []
IdentifierType: ['int']
Typedef: pthread_attr_t, [], ['typedef']
TypeDecl: pthread_attr_t, []
IdentifierType: ['int']
Typedef: pthread_mutex_t, [], ['typedef']
TypeDecl: pthread_mutex_t, []
IdentifierType: ['int']
Typedef: pthread_mutexattr_t, [], ['typedef']
TypeDecl: pthread_mutexattr_t, []
IdentifierType: ['int']
Typedef: pthread_cond_t, [], ['typedef']
TypeDecl: pthread_cond_t, []
IdentifierType: ['int']
Typedef: pthread_condattr_t, [], ['typedef']
TypeDecl: pthread_condattr_t, []
IdentifierType: ['int']
Typedef: pthread_key_t, [], ['typedef']
TypeDecl: pthread_key_t, []
IdentifierType: ['int']
Typedef: pthread_once_t, [], ['typedef']
TypeDecl: pthread_once_t, []
IdentifierType: ['int']
Typedef: pthread_rwlock_t, [], ['typedef']
TypeDecl: pthread_rwlock_t, []
IdentifierType: ['int']
Typedef: pthread_rwlockattr_t, [], ['typedef']
TypeDecl: pthread_rwlockattr_t, []
IdentifierType: ['int']
Typedef: pthread_spinlock_t, [], ['typedef']
TypeDecl: pthread_spinlock_t, []
IdentifierType: ['int']
Typedef: pthread_barrier_t, [], ['typedef']
TypeDecl: pthread_barrier_t, []
IdentifierType: ['int']
Typedef: pthread_barrierattr_t, [], ['typedef']
TypeDecl: pthread_barrierattr_t, []
IdentifierType: ['int']
Typedef: jmp_buf, [], ['typedef']
TypeDecl: jmp_buf, []
IdentifierType: ['int']
Typedef: rlim_t, [], ['typedef']
TypeDecl: rlim_t, []
IdentifierType: ['int']
Typedef: sa_family_t, [], ['typedef']
TypeDecl: sa_family_t, []
IdentifierType: ['int']
Typedef: sigjmp_buf, [], ['typedef']
TypeDecl: sigjmp_buf, []
IdentifierType: ['int']
Typedef: stack_t, [], ['typedef']
TypeDecl: stack_t, []
IdentifierType: ['int']
Typedef: siginfo_t, [], ['typedef']
TypeDecl: siginfo_t, []
IdentifierType: ['int']
Typedef: z_stream, [], ['typedef']
TypeDecl: z_stream, []
IdentifierType: ['int']
Typedef: int8_t, [], ['typedef']
TypeDecl: int8_t, []
IdentifierType: ['int']
Typedef: uint8_t, [], ['typedef']
TypeDecl: uint8_t, []
IdentifierType: ['int']
Typedef: int16_t, [], ['typedef']
TypeDecl: int16_t, []
IdentifierType: ['int']
Typedef: uint16_t, [], ['typedef']
TypeDecl: uint16_t, []
IdentifierType: ['int']
Typedef: int32_t, [], ['typedef']
TypeDecl: int32_t, []
IdentifierType: ['int']
Typedef: uint32_t, [], ['typedef']
TypeDecl: uint32_t, []
IdentifierType: ['int']
Typedef: int64_t, [], ['typedef']
TypeDecl: int64_t, []
IdentifierType: ['int']
Typedef: uint64_t, [], ['typedef']
TypeDecl: uint64_t, []
IdentifierType: ['int']
Typedef: int_least8_t, [], ['typedef']
TypeDecl: int_least8_t, []
IdentifierType: ['int']
Typedef: uint_least8_t, [], ['typedef']
TypeDecl: uint_least8_t, []
IdentifierType: ['int']
Typedef: int_least16_t, [], ['typedef']
TypeDecl: int_least16_t, []
IdentifierType: ['int']
Typedef: uint_least16_t, [], ['typedef']
TypeDecl: uint_least16_t, []
IdentifierType: ['int']
Typedef: int_least32_t, [], ['typedef']
TypeDecl: int_least32_t, []
IdentifierType: ['int']
Typedef: uint_least32_t, [], ['typedef']
TypeDecl: uint_least32_t, []
IdentifierType: ['int']
Typedef: int_least64_t, [], ['typedef']
TypeDecl: int_least64_t, []
IdentifierType: ['int']
Typedef: uint_least64_t, [], ['typedef']
TypeDecl: uint_least64_t, []
IdentifierType: ['int']
Typedef: int_fast8_t, [], ['typedef']
TypeDecl: int_fast8_t, []
IdentifierType: ['int']
Typedef: uint_fast8_t, [], ['typedef']
TypeDecl: uint_fast8_t, []
IdentifierType: ['int']
Typedef: int_fast16_t, [], ['typedef']
TypeDecl: int_fast16_t, []
IdentifierType: ['int']
Typedef: uint_fast16_t, [], ['typedef']
TypeDecl: uint_fast16_t, []
IdentifierType: ['int']
Typedef: int_fast32_t, [], ['typedef']
TypeDecl: int_fast32_t, []
IdentifierType: ['int']
Typedef: uint_fast32_t, [], ['typedef']
TypeDecl: uint_fast32_t, []
IdentifierType: ['int']
Typedef: int_fast64_t, [], ['typedef']
TypeDecl: int_fast64_t, []
IdentifierType: ['int']
Typedef: uint_fast64_t, [], ['typedef']
TypeDecl: uint_fast64_t, []
IdentifierType: ['int']
Typedef: intptr_t, [], ['typedef']
TypeDecl: intptr_t, []
IdentifierType: ['int']
Typedef: uintptr_t, [], ['typedef']
TypeDecl: uintptr_t, []
IdentifierType: ['int']
Typedef: intmax_t, [], ['typedef']
TypeDecl: intmax_t, []
IdentifierType: ['int']
Typedef: uintmax_t, [], ['typedef']
TypeDecl: uintmax_t, []
IdentifierType: ['int']
Typedef: bool, [], ['typedef']
TypeDecl: bool, []
IdentifierType: ['_Bool']
Typedef: MirEGLNativeWindowType, [], ['typedef']
PtrDecl: []
TypeDecl: MirEGLNativeWindowType, []
IdentifierType: ['void']
Typedef: MirEGLNativeDisplayType, [], ['typedef']
PtrDecl: []
TypeDecl: MirEGLNativeDisplayType, []
IdentifierType: ['void']
Typedef: MirConnection, [], ['typedef']
TypeDecl: MirConnection, []
Struct: MirConnection
Typedef: MirSurface, [], ['typedef']
TypeDecl: MirSurface, []
Struct: MirSurface
Typedef: MirSurfaceSpec, [], ['typedef']
TypeDecl: MirSurfaceSpec, []
Struct: MirSurfaceSpec
Typedef: MirScreencast, [], ['typedef']
TypeDecl: MirScreencast, []
Struct: MirScreencast
Typedef: MirPromptSession, [], ['typedef']
TypeDecl: MirPromptSession, []
Struct: MirPromptSession
Typedef: MirBufferStream, [], ['typedef']
TypeDecl: MirBufferStream, []
Struct: MirBufferStream
Typedef: MirPersistentId, [], ['typedef']
TypeDecl: MirPersistentId, []
Struct: MirPersistentId
Typedef: MirBlob, [], ['typedef']
TypeDecl: MirBlob, []
Struct: MirBlob
Typedef: MirDisplayConfig, [], ['typedef']
TypeDecl: MirDisplayConfig, []
Struct: MirDisplayConfig
Typedef: xcb_connection_t, [], ['typedef']
TypeDecl: xcb_connection_t, []
Struct: xcb_connection_t
Typedef: xcb_window_t, [], ['typedef']
TypeDecl: xcb_window_t, []
IdentifierType: ['uint32_t']
Typedef: xcb_visualid_t, [], ['typedef']
TypeDecl: xcb_visualid_t, []
IdentifierType: ['uint32_t']
FuncDef:
Decl: main, [], [], []
FuncDecl:
TypeDecl: main, []
IdentifierType: ['int']
Compound:
Decl: number1, [], [], []
TypeDecl: number1, []
IdentifierType: ['int']
Decl: number2, [], [], []
TypeDecl: number2, []
IdentifierType: ['int']
FuncCall:
ID: printf
ExprList:
Constant: string, "Enter two integers: "
FuncCall:
ID: scanf
ExprList:
Constant: string, "%d %d"
UnaryOp: &
ID: number1
UnaryOp: &
ID: number2
If:
BinaryOp: >=
ID: number1
ID: number2
Compound:
If:
BinaryOp: ==
ID: number1
ID: number2
Compound:
FuncCall:
ID: printf
ExprList:
Constant: string, "Result: %d = %d"
ID: number1
ID: number2
Compound:
FuncCall:
ID: printf
ExprList:
Constant: string, "Result: %d > %d"
ID: number1
ID: number2
Compound:
FuncCall:
ID: printf
ExprList:
Constant: string, "Result: %d < %d"
ID: number1
ID: number2
Return:
Constant: int, 0
最佳答案
这看起来像一个正确的 AST。顶部的所有 Typedef
节点都来自 pycparser 的“假” header ,以帮助它正确解析文件,您几乎可以忽略它们。
AST 只是一个递归的节点树;每个节点都是一个 Node目的。您可以迭代它的子节点(其他节点),使用 .coord
属性查看其原始源位置,等等。有几个查看 AST 节点的示例,例如 explore_ast .
要查找特定节点,您可能需要编写访问者。有几个这样做的例子,比如 func_calls .
关于c - pycparser AST 节点指针/位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54717008/
我刚接触 C 语言几周,所以对它还很陌生。 我见过这样的事情 * (variable-name) = -* (variable-name) 在讲义中,但它到底会做什么?它会否定所指向的值吗? 最佳答案
我有一个指向内存地址的void 指针。然后,我做 int 指针 = void 指针 float 指针 = void 指针 然后,取消引用它们以获取值。 { int x = 25; vo
我正在与计算机控制的泵进行一些串行端口通信,我用来通信的 createfile 函数需要将 com 端口名称解析为 wchar_t 指针。 我也在使用 QT 创建一个表单并获取 com 端口名称作为
#include "stdio.h" #include "malloc.h" int main() { char*x=(char*)malloc(1024); *(x+2)=3; --
#include #include main() { int an_int; void *void_pointer = &an_int; double *double_ptr = void
对于每个时间步长,我都有一个二维矩阵 a[ix][iz],ix 从 0 到 nx-1 和 iz 从 0 到 nz-1。 为了组装所有时间步长的矩阵,我定义了一个长度为 nx*nz*nt 的 3D 指针
我有一个函数,它接受一个指向 char ** 的指针并用字符串填充它(我猜是一个字符串数组)。 *list_of_strings* 在函数内部分配内存。 char * *list_of_strings
我试图了解当涉及到字符和字符串时,内存分配是如何工作的。 我知道声明的数组的名称就像指向数组第一个元素的指针,但该数组将驻留在内存的堆栈中。 另一方面,当我们想要使用内存堆时,我们使用 malloc,
我有一个 C 语言的 .DLL 文件。该 DLL 中所有函数所需的主要结构具有以下形式。 typedef struct { char *snsAccessID; char *
我得到了以下数组: let arr = [ { children: [ { children: [], current: tru
#include int main(void) { int i; int *ptr = (int *) malloc(5 * sizeof(int)); for (i=0;
我正在编写一个程序,它接受一个三位数整数并将其分成两个整数。 224 将变为 220 和 4。 114 将变为 110 和 4。 基本上,您可以使用模数来完成。我写了我认为应该工作的东西,编译器一直说
好吧,我对 C++ 很陌生,我确定这个问题已经在某个地方得到了回答,而且也很简单,但我似乎找不到答案.... 我有一个自定义数组类,我将其用作练习来尝试了解其工作原理,其定义如下: 标题: class
1) this 指针与其他指针有何不同?据我了解,指针指向堆中的内存。如果有指向它们的指针,这是否意味着对象总是在堆中构造? 2)我们可以在 move 构造函数或 move 赋值中窃取this指针吗?
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: C : pointer to struct in the struct definition 在我的初学者类
我有两个指向指针的结构指针 typedef struct Square { ... ... }Square; Square **s1; //Representing 2D array of say,
变量在内存中是如何定位的?我有这个代码 int w=1; int x=1; int y=1; int z=1; int main(int argc, char** argv) { printf
#include #include main() { char *q[]={"black","white","red"}; printf("%s",*q+3); getch()
我在“C”类中有以下函数 class C { template void Func1(int x); template void Func2(int x); }; template void
我在64位linux下使用c++,编译器(g++)也是64位的。当我打印某个变量的地址时,例如一个整数,它应该打印一个 64 位整数,但实际上它打印了一个 48 位整数。 int i; cout <<
我是一名优秀的程序员,十分优秀!