|
9 | 9 |
|
10 | 10 | from pyccel.ast.basic import ScopedAstNode
|
11 | 11 |
|
| 12 | +from pyccel.ast.bind_c import BindCPointer |
| 13 | + |
12 | 14 | from pyccel.ast.builtins import PythonRange, PythonComplex
|
13 | 15 | from pyccel.ast.builtins import PythonPrint, PythonType
|
14 | 16 | from pyccel.ast.builtins import PythonList, PythonTuple, PythonSet, PythonDict
|
|
57 | 59 | from pyccel.ast.variable import InhomogeneousTupleVariable
|
58 | 60 |
|
59 | 61 | from pyccel.ast.c_concepts import ObjectAddress, CMacro, CStringExpression, PointerCast, CNativeInt
|
| 62 | +from pyccel.ast.c_concepts import CStackArray |
60 | 63 |
|
61 | 64 | from pyccel.codegen.printing.codeprinter import CodePrinter
|
62 | 65 |
|
@@ -1342,6 +1345,8 @@ def get_declare_type(self, expr):
|
1342 | 1345 | if isinstance(expr.class_type, (HomogeneousSetType, HomogeneousListType, DictType)):
|
1343 | 1346 | dtype = self.get_c_type(expr.class_type)
|
1344 | 1347 | return dtype
|
| 1348 | + if isinstance(expr.class_type, CStackArray): |
| 1349 | + return self.get_c_type(expr.class_type.element_type) |
1345 | 1350 | if isinstance(expr.class_type,(HomogeneousTupleType, NumpyNDArrayType)):
|
1346 | 1351 | if expr.rank > 15:
|
1347 | 1352 | errors.report(UNSUPPORTED_ARRAY_RANK, symbol=expr, severity='fatal')
|
@@ -1379,20 +1384,31 @@ def _print_FuncAddressDeclare(self, expr):
|
1379 | 1384 | return f'{ret_type} (*{name})({arg_code});\n'
|
1380 | 1385 |
|
1381 | 1386 | def _print_Declare(self, expr):
|
1382 |
| - if isinstance(expr.variable, InhomogeneousTupleVariable): |
1383 |
| - return ''.join(self._print_Declare(Declare(v,intent=expr.intent, static=expr.static)) for v in expr.variable) |
| 1387 | + var = expr.variable |
| 1388 | + if isinstance(var, InhomogeneousTupleVariable): |
| 1389 | + return ''.join(self._print_Declare(Declare(v,intent=expr.intent, static=expr.static)) for v in var) |
| 1390 | + |
| 1391 | + declaration_type = self.get_declare_type(var) |
| 1392 | + variable = self._print(var.name) |
1384 | 1393 |
|
1385 |
| - declaration_type = self.get_declare_type(expr.variable) |
1386 |
| - variable = self._print(expr.variable.name) |
| 1394 | + init = f' = {self._print(expr.value)}' if expr.value is not None else '' |
1387 | 1395 |
|
1388 |
| - if expr.variable.is_stack_array: |
1389 |
| - preface, init = self._init_stack_array(expr.variable,) |
| 1396 | + if isinstance(var.class_type, CStackArray): |
| 1397 | + assert init == '' |
| 1398 | + preface = '' |
| 1399 | + if isinstance(var.alloc_shape[0], (int, LiteralInteger)): |
| 1400 | + init = f'[{var.alloc_shape[0]}]' |
| 1401 | + else: |
| 1402 | + declaration_type += '*' |
| 1403 | + init = '' |
| 1404 | + elif var.is_stack_array: |
| 1405 | + preface, init = self._init_stack_array(var,) |
1390 | 1406 | elif declaration_type == 't_ndarray' and not self._in_header:
|
| 1407 | + assert init == '' |
1391 | 1408 | preface = ''
|
1392 | 1409 | init = ' = {.shape = NULL}'
|
1393 | 1410 | else:
|
1394 | 1411 | preface = ''
|
1395 |
| - init = '' |
1396 | 1412 |
|
1397 | 1413 | external = 'extern ' if expr.external else ''
|
1398 | 1414 | static = 'static ' if expr.static else ''
|
@@ -2023,7 +2039,8 @@ def _print_FunctionDef(self, expr):
|
2023 | 2039 | self._additional_args.append(results)
|
2024 | 2040 |
|
2025 | 2041 | body = self._print(expr.body)
|
2026 |
| - decs = [Declare(i) if isinstance(i, Variable) else FuncAddressDeclare(i) for i in expr.local_vars] |
| 2042 | + decs = [Declare(i, value=(Nil() if i.is_alias and isinstance(i.class_type, (VoidType, BindCPointer)) else None)) |
| 2043 | + if isinstance(i, Variable) else FuncAddressDeclare(i) for i in expr.local_vars] |
2027 | 2044 |
|
2028 | 2045 | if len(results) == 1 :
|
2029 | 2046 | res = results[0]
|
|
0 commit comments