Skip to content
Open
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
20 changes: 19 additions & 1 deletion load.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,25 @@ def set_SourceContent(self, source_content):
def visit_Decl(self, n, *args, **kwargs):
result = super().visit_Decl(n, *args, **kwargs)

if isinstance(n.type, pycparser.c_ast.FuncDecl):
if isinstance(n.type, pycparser.c_ast.ArrayDecl):
array_size = result[result.find("[")+1:result.find("]")]

# cffi doesn't work with array sizes that are not a number. like "int test[ 1 + 2]"
# So eval the number
if( not array_size.isnumeric() ):

# remove possible casts like "int test[ (uint8_t)1 + 2]"
no_cast_array_size = re.sub("\\(\\s*[u]int[0-9]*_t\\s*\\)", " ", array_size)
try:
number = round(eval(no_cast_array_size))

# remove the size
result = result.replace(array_size, str(number))
except:
print("can't parse: " + result)
pass

elif isinstance(n.type, pycparser.c_ast.FuncDecl):
# Is a function declaration
if n.name in self.functions:
# Is already in functions
Expand Down