本文整理汇总了Python中pycparserext.ext_c_parser.GnuCParser类的典型用法代码示例。如果您正苦于以下问题:Python GnuCParser类的具体用法?Python GnuCParser怎么用?Python GnuCParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GnuCParser类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_array_ptr_decl_attribute
def test_array_ptr_decl_attribute():
src = """
int* __attribute__((weak)) array[256];
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
示例2: test_gnu_statement_expression
def test_gnu_statement_expression():
src = """
int func(int a) {
return (int)({; ; *(int*)&a;});
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
示例3: test_funky_header_code_5
def test_funky_header_code_5():
src=""" void do_foo(void) __asm(__STRING(do_foo));"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例4: test_func_ret_ptr_decl_attribute
def test_func_ret_ptr_decl_attribute():
src = """
extern void* memcpy(const void* src, const void *dst, int len) __attribute__((unused));
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例5: test_asm_volatile_2
def test_asm_volatile_2():
src = """
void read_tsc(void) {
long val;
asm volatile("rdtsc" : "=A" (val));
} """
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print GnuCGenerator().visit(ast)
示例6: test_empty_struct_declaration
def test_empty_struct_declaration():
src = """
typedef struct Foo {
} Foo_t;
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例7: test_array_attributes
def test_array_attributes():
src = """
int x[10] __attribute__((unused));
int y[20] __attribute((aligned(10)));
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例8: test_asm_volatile_3
def test_asm_volatile_3():
src = """
void read_tsc(void) {
long fpenv;
asm("mtfsf 255,%0" :: "f" (fpenv));
} """
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print GnuCGenerator().visit(ast)
示例9: test_lvalue_gnu_statement_expression
def test_lvalue_gnu_statement_expression():
src = """
int func(int a) {
int ret=(int)({; ; *(int*)&a;});
return ret;
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例10: test_func_decl_attribute
def test_func_decl_attribute():
src = """
extern void int happy(void) __attribute__((unused));
int main()
{
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例11: test_funky_header_code
def test_funky_header_code():
src = """
extern __inline int __attribute__ ((__nothrow__)) __signbitf (float __x)
{
int __m;
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
return __m & 0x8;
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
from pycparserext.ext_c_generator import GnuCGenerator
print GnuCGenerator().visit(ast)
示例12: test_empty_gnu_statement_expression
def test_empty_gnu_statement_expression():
# Incase, ASSERTS turn out to be empty statements
src = """
int func(int a) {
({
; ;
});
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
示例13: GnuCParser
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
src="""
typedef int wchar_t;
extern wchar_t *wcscpy (wchar_t *restrict __dest,
const wchar_t *__restrict __src) __attribute ((nothrow , leaf));
"""
p.parse(src).show()
示例14: visit_AttributeSpecifier
def visit_AttributeSpecifier(self, n):
return ' __attribute__((' + self.visit(n.exprlist) + '))'
####################################################################################################
class MyCGenerator(AsmAndAttributesMixin, CGenerator):
pass
####################################################################################################
file_path = 'fitz-from-cpp.h'
with open(file_path, 'r') as f:
source = f.read()
parser = GnuCParser()
ast = parser.parse(source)
# ast.show()
# generator = FunctionDeclarationGenerator()
generator = MyCGenerator()
source = generator.visit(ast)
# print(source)
print('\nStructs:')
for name in generator.structs:
if name and name.startswith('fz_'):
print(name)
print('\nFunctions:')