@@ -775,9 +775,11 @@ def is_int(a):
775
775
else :
776
776
return self ._visit (var [indices [0 ]][indices [1 :]])
777
777
else :
778
+ pyccel_stage .set_stage ('syntactic' )
778
779
tmp_var = PyccelSymbol (self .scope .get_new_name ())
779
780
assign = Assign (tmp_var , var )
780
781
assign .set_current_ast (expr .python_ast )
782
+ pyccel_stage .set_stage ('semantic' )
781
783
self ._additional_exprs [- 1 ].append (self ._visit (assign ))
782
784
var = self ._visit (tmp_var )
783
785
@@ -1074,9 +1076,11 @@ def _handle_function(self, expr, func, args, is_method = False):
1074
1076
1075
1077
func_results = func .results if isinstance (func , FunctionDef ) else func .functions [0 ].results
1076
1078
if not parent_assign and len (func_results ) == 1 and func_results [0 ].var .rank > 0 :
1079
+ pyccel_stage .set_stage ('syntactic' )
1077
1080
tmp_var = PyccelSymbol (self .scope .get_new_name ())
1078
1081
assign = Assign (tmp_var , expr )
1079
1082
assign .set_current_ast (expr .python_ast )
1083
+ pyccel_stage .set_stage ('semantic' )
1080
1084
self ._additional_exprs [- 1 ].append (self ._visit (assign ))
1081
1085
return self ._visit (tmp_var )
1082
1086
@@ -1714,7 +1718,10 @@ def _assign_GeneratorComprehension(self, lhs_name, expr):
1714
1718
# Use _visit_Assign to create the requested iterator with the correct type
1715
1719
# The result of this operation is not stored, it is just used to declare
1716
1720
# iterator with the correct dtype to allow correct dtype deductions later
1717
- self ._visit (Assign (iterator , iterator_rhs , python_ast = expr .python_ast ))
1721
+ pyccel_stage .set_stage ('syntactic' )
1722
+ syntactic_assign = Assign (iterator , iterator_rhs , python_ast = expr .python_ast )
1723
+ pyccel_stage .set_stage ('semantic' )
1724
+ self ._visit (syntactic_assign )
1718
1725
1719
1726
loop_elem = loop .body .body [0 ]
1720
1727
@@ -1724,9 +1731,13 @@ def _assign_GeneratorComprehension(self, lhs_name, expr):
1724
1731
gens = set (loop_elem .get_attribute_nodes (GeneratorComprehension ))
1725
1732
if len (gens )== 1 :
1726
1733
gen = gens .pop ()
1734
+ pyccel_stage .set_stage ('syntactic' )
1727
1735
assert isinstance (gen .lhs , PyccelSymbol ) and gen .lhs .is_temp
1728
1736
gen_lhs = self .scope .get_new_name () if gen .lhs .is_temp else gen .lhs
1729
- assign = self ._visit (Assign (gen_lhs , gen , python_ast = gen .python_ast ))
1737
+ syntactic_assign = Assign (gen_lhs , gen , python_ast = gen .python_ast )
1738
+ pyccel_stage .set_stage ('semantic' )
1739
+ assign = self ._visit (syntactic_assign )
1740
+
1730
1741
new_expr .append (assign )
1731
1742
loop .substitute (gen , assign .lhs )
1732
1743
loop_elem = loop .body .body [0 ]
@@ -1857,7 +1868,9 @@ def _get_indexed_type(self, base, args, expr):
1857
1868
if isinstance (base , PyccelFunctionDef ) and base .cls_name is TypingFinal :
1858
1869
syntactic_annotation = args [0 ]
1859
1870
if not isinstance (syntactic_annotation , SyntacticTypeAnnotation ):
1871
+ pyccel_stage .set_stage ('syntactic' )
1860
1872
syntactic_annotation = SyntacticTypeAnnotation (dtype = syntactic_annotation )
1873
+ pyccel_stage .set_stage ('semantic' )
1861
1874
annotation = self ._visit (syntactic_annotation )
1862
1875
for t in annotation .type_list :
1863
1876
t .is_const = True
@@ -1887,7 +1900,9 @@ def _get_indexed_type(self, base, args, expr):
1887
1900
if len (args ) == 2 and args [1 ] is LiteralEllipsis ():
1888
1901
syntactic_annotation = args [0 ]
1889
1902
if not isinstance (syntactic_annotation , SyntacticTypeAnnotation ):
1903
+ pyccel_stage .set_stage ('syntactic' )
1890
1904
syntactic_annotation = SyntacticTypeAnnotation (dtype = syntactic_annotation )
1905
+ pyccel_stage .set_stage ('semantic' )
1891
1906
internal_datatypes = self ._visit (syntactic_annotation )
1892
1907
type_annotations = []
1893
1908
if dtype_cls is PythonTupleFunction :
@@ -1925,14 +1940,16 @@ def _visit(self, expr):
1925
1940
1926
1941
Parameters
1927
1942
----------
1928
- expr : pyccel.ast.basic.PyccelAstNode
1943
+ expr : pyccel.ast.basic.PyccelAstNode | PyccelSymbol
1929
1944
Object to visit of type X.
1930
1945
1931
1946
Returns
1932
1947
-------
1933
1948
pyccel.ast.basic.PyccelAstNode
1934
1949
AST object which is the semantic equivalent of expr.
1935
1950
"""
1951
+ if getattr (expr , 'pyccel_staging' , 'syntactic' ) == 'semantic' :
1952
+ return expr
1936
1953
1937
1954
# TODO - add settings to Errors
1938
1955
# - line and column
@@ -2203,8 +2220,12 @@ def _visit_FunctionCallArgument(self, expr):
2203
2220
value = self ._visit (expr .value )
2204
2221
a = FunctionCallArgument (value , expr .keyword )
2205
2222
def generate_and_assign_temp_var ():
2223
+ pyccel_stage .set_stage ('syntactic' )
2206
2224
tmp_var = self .scope .get_new_name ()
2207
- assign = self ._visit (Assign (tmp_var , expr .value , python_ast = expr .value .python_ast ))
2225
+ syntactic_assign = Assign (tmp_var , expr .value , python_ast = expr .value .python_ast )
2226
+ pyccel_stage .set_stage ('semantic' )
2227
+
2228
+ assign = self ._visit (syntactic_assign )
2208
2229
self ._additional_exprs [- 1 ].append (assign )
2209
2230
return FunctionCallArgument (self ._visit (tmp_var ))
2210
2231
if isinstance (value , (PyccelArithmeticOperator , PyccelInternalFunction )) and value .rank :
@@ -3663,12 +3684,15 @@ def _visit_FunctionalFor(self, expr):
3663
3684
def _visit_GeneratorComprehension (self , expr ):
3664
3685
lhs = self .check_for_variable (expr .lhs )
3665
3686
if lhs is None :
3687
+ pyccel_stage .set_stage ('syntactic' )
3666
3688
if expr .lhs .is_temp :
3667
3689
lhs = PyccelSymbol (self .scope .get_new_name (), is_temp = True )
3668
3690
else :
3669
3691
lhs = expr .lhs
3692
+ syntactic_assign = Assign (lhs , expr , python_ast = expr .python_ast )
3693
+ pyccel_stage .set_stage ('semantic' )
3670
3694
3671
- creation = self ._visit (Assign ( lhs , expr , python_ast = expr . python_ast ) )
3695
+ creation = self ._visit (syntactic_assign )
3672
3696
self ._additional_exprs [- 1 ].append (creation )
3673
3697
return self .get_variable (lhs )
3674
3698
else :
@@ -3774,9 +3798,13 @@ def _visit_Return(self, expr):
3774
3798
v = o .var
3775
3799
if not (isinstance (r , PyccelSymbol ) and r == (v .name if isinstance (v , Variable ) else v )):
3776
3800
# Create a syntactic object to visit
3801
+ pyccel_stage .set_stage ('syntactic' )
3777
3802
if isinstance (v , Variable ):
3778
3803
v = PyccelSymbol (v .name )
3779
- a = self ._visit (Assign (v , r , python_ast = expr .python_ast ))
3804
+ syntactic_assign = Assign (v , r , python_ast = expr .python_ast )
3805
+ pyccel_stage .set_stage ('semantic' )
3806
+
3807
+ a = self ._visit (syntactic_assign )
3780
3808
assigns .append (a )
3781
3809
if isinstance (a , ConstructorCall ):
3782
3810
a .cls_variable .is_temp = False
@@ -3871,6 +3899,7 @@ def unpack(ann):
3871
3899
templates = {t : v for t ,v in templates .items () if t in used_type_names }
3872
3900
3873
3901
# Create new temparary templates for the arguments with a Union data type.
3902
+ pyccel_stage .set_stage ('syntactic' )
3874
3903
tmp_templates = {}
3875
3904
new_expr_args = []
3876
3905
for a in expr .arguments :
@@ -3889,6 +3918,7 @@ def unpack(ann):
3889
3918
value = a .value , kwonly = a .is_kwonly , annotation = dtype_symb ))
3890
3919
else :
3891
3920
new_expr_args .append (a )
3921
+ pyccel_stage .set_stage ('semantic' )
3892
3922
3893
3923
templates .update (tmp_templates )
3894
3924
template_combinations = list (product (* [v .type_list for v in templates .values ()]))
@@ -4513,10 +4543,15 @@ def _visit_MacroFunction(self, expr):
4513
4543
for hd in header :
4514
4544
for i ,_ in enumerate (hd .dtypes ):
4515
4545
self .scope .insert_symbol (f'arg_{ i } ' )
4516
- arguments = [FunctionDefArgument (self ._visit (AnnotatedPyccelSymbol (f'arg_{ i } ' , annotation = arg ))[0 ]) \
4546
+ pyccel_stage .set_stage ('syntactic' )
4547
+ syntactic_args = [AnnotatedPyccelSymbol (f'arg_{ i } ' , annotation = arg ) \
4517
4548
for i , arg in enumerate (hd .dtypes )]
4518
- results = [FunctionDefResult ( self . _visit ( AnnotatedPyccelSymbol (f'out_{ i } ' , annotation = arg ))[ 0 ] ) \
4549
+ syntactic_results = [AnnotatedPyccelSymbol (f'out_{ i } ' , annotation = arg ) \
4519
4550
for i , arg in enumerate (hd .results )]
4551
+ pyccel_stage .set_stage ('semantic' )
4552
+
4553
+ arguments = [FunctionDefArgument (self ._visit (a )[0 ]) for a in syntactic_args ]
4554
+ results = [FunctionDefResult (self ._visit (r )[0 ]) for r in syntactic_results ]
4520
4555
interfaces .append (FunctionDef (f_name , arguments , results , []))
4521
4556
4522
4557
# TODO -> Said: must handle interface
@@ -4600,8 +4635,12 @@ def _visit_NumpyNonZero(self, func_call):
4600
4635
# expr is a FunctionCall
4601
4636
arg = func_call_args [0 ].value
4602
4637
if not isinstance (arg , Variable ):
4638
+ pyccel_stage .set_stage ('syntactic' )
4603
4639
new_symbol = PyccelSymbol (self .scope .get_new_name ())
4604
- creation = self ._visit (Assign (new_symbol , arg , python_ast = func_call .python_ast ))
4640
+ syntactic_assign = Assign (new_symbol , arg , python_ast = func_call .python_ast )
4641
+ pyccel_stage .set_stage ('semantic' )
4642
+
4643
+ creation = self ._visit (syntactic_assign )
4605
4644
self ._additional_exprs [- 1 ].append (creation )
4606
4645
arg = self ._visit (new_symbol )
4607
4646
return NumpyWhere (arg )
0 commit comments