Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visit_FuncDeclExt(self, node):
visits['FuncDeclExt'][0] += 1
NodeVisitor.generic_visit(self, node)
src_gnu = """
int func1(int a, int b) {
__typeof__(a) _a = __builtin_types_compatible_p(long char, short int);
__typeof__ (__typeof__ (char *)[4]) y;
asm("rdtsc" : "=A" (val));
__attribute__((unused)) static int c;
}
"""
import pycparserext.ext_c_parser as ext_c_parser
parser = ext_c_parser.GnuCParser()
ast = parser.parse(src_gnu)
ast.show()
TestVisitor().visit(ast)
for visit_type, visit_num in visits.items():
assert_msg = '{}: Should have visited {}, got {}'.format(
visit_type, visit_num[1], visit_num[0])
assert visit_num[0] == visit_num[1], assert_msg
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))
def test_funky_header_code_2():
src = """
extern __inline int __attribute__ ((__nothrow__)) __signbitf (float __x)
{
int __m;
if (__x == 0)
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
else
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
return __m & 0x8;
}
"""
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))
def test_nesty_c_declarator():
src = """
struct a {
int *b[1][1];
};
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
def enumerate_pins(c_source_file, include_dirs, definitions):
"""
Enumerate pins specified in PinNames.h, by looking for a PinName enum
typedef somewhere in the file.
"""
definitions += ['__attribute(x)__=', '__extension__(x)=', 'register=', '__IO=', 'uint32_t=unsigned int']
gcc_args = ['-E', '-fmerge-all-constants']
gcc_args += ['-I' + directory for directory in include_dirs]
gcc_args += ['-D' + definition for definition in definitions]
parsed_ast = parse_file(c_source_file,
use_cpp=True,
cpp_path='arm-none-eabi-gcc',
cpp_args=gcc_args,
parser=GnuCParser())
# now, walk the AST
visitor = TypeDeclVisitor(['PinName'])
return visitor.visit(parsed_ast)