Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nala/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pycparser import c_ast
from pycparser.c_generator import CGenerator

from .inspect import PRIMITIVE_TYPES
from .inspect import VaList
from .inspect import PrimitiveType
from .inspect import is_struct_or_union
Expand Down
66 changes: 21 additions & 45 deletions nala/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,40 +137,6 @@ def rename_parameters(function_declaration, param_names):
return function_declaration


PRIMITIVE_TYPES = [
'char',
'signed char',
'unsigned char',
'short',
'short int',
'signed short',
'signed short int',
'unsigned short',
'unsigned short int',
'int',
'signed',
'signed int',
'unsigned',
'unsigned int',
'long',
'long int',
'signed long',
'signed long int',
'unsigned long',
'unsigned long int',
'long unsigned int',
'long long',
'long long int',
'signed long long',
'signed long long int',
'unsigned long long',
'unsigned long long int',
'long long unsigned int',
'float',
'double',
'long double'
]

LINEMARKER = re.compile(r'^# \d+ "((?:\\.|[^\\"])*)"((?: [1234])*)$')

TOKENS = {
Expand Down Expand Up @@ -281,25 +247,35 @@ def is_fixed_array(type_):
return False


def is_primitive_type_pointer_type(type_, types):
def is_primitive_type(type_):
PRIMITIVE_TYPES = set([
'char', 'signed', 'unsigned',
'short', 'int', 'long',
'float', 'double',
])

if isinstance(type_, c_ast.IdentifierType):
return set(type_.names) <= PRIMITIVE_TYPES

return False


def is_primitive_type_pointer_type(type_):
if isinstance(type_, c_ast.IdentifierType):
return ' '.join(type_.names) in types
return is_primitive_type(type_)

if isinstance(type_, c_ast.TypeDecl):
return is_primitive_type_pointer_type(type_.type, types)
return is_primitive_type_pointer_type(type_.type)

return False


def is_primitive_type_pointer(type_, types=None):
if types is None:
types = PRIMITIVE_TYPES

def is_primitive_type_pointer(type_):
if isinstance(type_, c_ast.TypeDecl):
return is_primitive_type_pointer(type_.type, types)
return is_primitive_type_pointer(type_.type)

if isinstance(type_, c_ast.PtrDecl):
return is_primitive_type_pointer_type(type_.type, types)
return is_primitive_type_pointer_type(type_.type)

return False

Expand Down Expand Up @@ -410,7 +386,7 @@ def resolve_type(self, type_):
if isinstance(type_, c_ast.IdentifierType):
name = ' '.join(type_.names)

if name in PRIMITIVE_TYPES or name == '_Bool':
if is_primitive_type(type_) or name == '_Bool':
return PrimitiveType(name)
elif name == '__builtin_va_list':
return VaList()
Expand Down Expand Up @@ -439,7 +415,7 @@ def expand_type(self, type_):
if isinstance(type_, c_ast.IdentifierType):
name = ' '.join(type_.names)

if name in PRIMITIVE_TYPES:
if is_primitive_type(type_):
pass
elif name in ['__builtin_va_list', 'void', '_Bool']:
pass
Expand Down
Loading