Skip to content

Commit

Permalink
Adapt to newer pycparser.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jan 23, 2022
1 parent 62c54fc commit 3af8946
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
23 changes: 14 additions & 9 deletions nala/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def is_ellipsis(param):


def decl(name, type):
return c_ast.Decl(name, [], [], [], type, None, None)
return c_ast.Decl(name, [], None, [], [], type, None, None)


def function_ptr_decl(name, return_type, parameters):
Expand All @@ -45,13 +45,14 @@ def function_ptr_decl(name, return_type, parameters):


def bool_param(name):
return decl(name, c_ast.TypeDecl(name, [], c_ast.IdentifierType(['bool'])))
return decl(name, c_ast.TypeDecl(name, [], None, c_ast.IdentifierType(['bool'])))


def set_member(name):
return decl(name,
c_ast.TypeDecl(name,
[],
None,
c_ast.IdentifierType(['struct nala_set_param'])))


Expand All @@ -65,7 +66,7 @@ def in_assert_member(name, param_actual, param_expected):
param_actual,
param_expected,
decl('size',
c_ast.TypeDecl('size', [], c_ast.IdentifierType(['size_t'])))
c_ast.TypeDecl('size', [], None, c_ast.IdentifierType(['size_t'])))
])


Expand All @@ -79,21 +80,21 @@ def out_copy_member(name, param_dst, param_src):
param_dst,
param_src,
decl('size',
c_ast.TypeDecl('size', [], c_ast.IdentifierType(['size_t'])))
c_ast.TypeDecl('size', [], None, c_ast.IdentifierType(['size_t'])))
])


def va_list_param(name):
return decl(None,
c_ast.TypeDecl(name, [], c_ast.IdentifierType(['va_list'])))
c_ast.TypeDecl(name, [], None, c_ast.IdentifierType(['va_list'])))


def void_type(name):
return c_ast.TypeDecl(name, [], c_ast.IdentifierType(['void']))
return c_ast.TypeDecl(name, [], None, c_ast.IdentifierType(['void']))


def int_type(name):
return c_ast.TypeDecl(name, [], c_ast.IdentifierType(['int']))
return c_ast.TypeDecl(name, [], None, c_ast.IdentifierType(['int']))


def rename_return_type(return_type, name):
Expand Down Expand Up @@ -259,14 +260,15 @@ def __init__(self,
c_ast.PtrDecl([],
c_ast.TypeDecl('vafmt_p',
['const'],
None,
c_ast.IdentifierType(['char'])))))
self.forward_args += ', nala_vl'

# -Wpedantic warns on empty structs.
if not self.params_struct:
self.params_struct = [
decl('dummy',
c_ast.TypeDecl('dummy', [], c_ast.IdentifierType(['int'])))
c_ast.TypeDecl('dummy', [], None, c_ast.IdentifierType(['int'])))
]

return_type = self.func_decl.type
Expand Down Expand Up @@ -299,7 +301,7 @@ def __init__(self,
f'{self.func_name}_mock_set_errno',
[decl(
'errno_value',
c_ast.TypeDecl('errno_value', [], c_ast.IdentifierType(['int'])),
c_ast.TypeDecl('errno_value', [], None, c_ast.IdentifierType(['int'])),
)])
self.callback_decl = function_ptr_decl(
'callback',
Expand All @@ -310,12 +312,14 @@ def __init__(self,
c_ast.TypeDecl(
f'{self.func_name}_mock_va_arg_real',
[],
None,
return_type))
self.default_variadic_func_real_wrapper_decl = c_ast.FuncDecl(
c_ast.ParamList(create_implementation_params(self.func_params)),
c_ast.TypeDecl(
f'nala_v{self.func_name}',
[],
None,
return_type))
self.real_decl = self.rename_function(self.real_func)
self.wrapped_decl = self.rename_function(self.wrapped_func)
Expand Down Expand Up @@ -557,6 +561,7 @@ def create_mock_params(self):
c_ast.PtrDecl([],
c_ast.TypeDecl('vafmt_p',
['const'],
None,
c_ast.IdentifierType(['char'])))))
mock_params.append(decl(None, c_ast.EllipsisParam()))

Expand Down
9 changes: 8 additions & 1 deletion nala/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ def rename_parameters(function_declaration, param_names):

for param in function_declaration.type.args.params:
if isinstance(param, c_ast.Typename):
param = c_ast.Decl(param.name, [], [], [], param.type, None, None)
param = c_ast.Decl(param.name,
[],
None,
[],
[],
param.type,
None,
None)

params.append(param)

Expand Down
2 changes: 1 addition & 1 deletion nala/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.177.1'
__version__ = '0.178.0'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pycparser
pycparser>=2.21
jinja2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def find_version():
packages=find_packages(exclude=['tests']),
test_suite="tests",
install_requires=[
'pycparser',
'pycparser>=2.21',
'jinja2'
],
include_package_data=True,
Expand Down

0 comments on commit 3af8946

Please sign in to comment.