Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
nstr = n.declname if n.declname else ''
# Resolve modifiers.
# Wrap in parens to distinguish pointer to array and pointer to
# function syntax.
#
for i, modifier in enumerate(modifiers):
if isinstance(modifier, c_ast.ArrayDecl):
if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)):
nstr = '(' + nstr + ')'
nstr += '[' + self.visit(modifier.dim) + ']'
elif isinstance(modifier, c_ast.FuncDecl):
if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)):
nstr = '(' + nstr + ')'
nstr += '(' + self.visit(modifier.args) + ')'
elif isinstance(modifier, FuncDeclExt):
if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)):
nstr = '(' + nstr + ')'
nstr += '(' + self.visit(modifier.args) + ')'
if modifier.asm is not None:
nstr += " " + self.visit(modifier.asm)
if modifier.attributes.exprs:
nstr += (
' __attribute__(('
+ self.visit(modifier.attributes)
+ '))')
elif isinstance(modifier, c_ast.PtrDecl):
# BUG FIX: pycparser ignores quals
quals = ' '.join(modifier.quals)
quals = quals + ' '
nstr = '*' + quals + nstr
if hasattr(n, "attributes") and n.attributes.exprs:
nstr += ' __attribute__((' + self.visit(n.attributes) + '))'
if nstr:
s += ' ' + nstr
return s
elif typ == c_ast.Decl:
return self._generate_decl(n.type)
elif typ == c_ast.Typename:
return self._generate_type(n.type)
elif typ == c_ast.IdentifierType:
return ' '.join(n.names) + ' '
elif typ in (c_ast.ArrayDecl, c_ast.PtrDecl, c_ast.FuncDecl, FuncDeclExt):
return self._generate_type(n.type, modifiers + [n])
else:
return self.visit(n)
elif isinstance(typedecl, c_ast.PtrDecl):
res.extend(typedecl.quals)
res.extend(render_type(typedecl.type))
res.append('*')
elif isinstance(typedecl, c_ast.IdentifierType):
res.extend(typedecl.names)
elif isinstance(typedecl, c_ast.Struct):
res.extend(['struct', typedecl.name])
elif isinstance(typedecl, c_ast.Union):
res.extend(['union', typedecl.name])
elif isinstance(typedecl, (c_ast.FuncDecl, ext_c_parser.FuncDeclExt)):
ret = render_type(typedecl.type)
args = []
for param in typedecl.args.params:
args.append(' '.join(render_type(param)))
ret.append('({})'.format(', '.join(args)))
res.extend(ret)
elif isinstance(typedecl, c_ast.ArrayDecl):
res.extend(render_type(typedecl.type))
if typedecl.dim is None:
res.append('[]')
elif isinstance(typedecl.dim, c_ast.Constant):
res.append('[{}]'.format(typedecl.dim.value))
else:
die('non-constant dimension in array declaration')
def p_direct_abstract_declarator_6(self, p):
""" direct_abstract_declarator : direct_abstract_declarator \
LPAREN parameter_type_list_opt RPAREN asm_opt attributes_opt
"""
func = FuncDeclExt(
args=p[3],
type=None,
attributes=p[6],
asm=p[5],
coord=p[1].coord)
p[0] = self._type_modify_decl(decl=p[1], modifier=func)
def p_direct_xxx_declarator_6(self, p):
""" direct_xxx_declarator : direct_xxx_declarator LPAREN parameter_type_list \
RPAREN asm_opt attributes_opt
| direct_xxx_declarator \
LPAREN identifier_list_opt RPAREN \
asm_opt attributes_opt
"""
func = FuncDeclExt(
args=p[3],
type=None,
attributes=p[6],
asm=p[5],
coord=p[1].coord)
p[0] = self._type_modify_decl(decl=p[1], modifier=func)