@@ -356,9 +356,10 @@ def find_else_lineno(self, search_index):
356
356
357
357
Returns
358
358
-------
359
- tuple : (int, int)
360
- Tuple containing the line number of the else statement and the
361
- index of the last character of the else in the original python code
359
+ search_index : int
360
+ Line number of the else statement
361
+ end_col_offset : int
362
+ Index of the last character of the else in the original python code
362
363
363
364
Raises
364
365
------
@@ -378,7 +379,8 @@ def find_else_lineno(self, search_index):
378
379
end_col_offset += 4
379
380
380
381
# Line number is 1+index in list
381
- return search_index + 1 , end_col_offset
382
+ search_index += 1
383
+ return search_index , end_col_offset
382
384
383
385
def parse_While (self , node , file_index , function_key , indent ):
384
386
"""
@@ -700,9 +702,10 @@ def parse_Call(self, node, file_index, function_key):
700
702
701
703
Returns
702
704
-------
703
- tuple : (str, [str])
704
- Tuple with the string representation of the call and the return
705
- type in a list of a string
705
+ return_str : str
706
+ The call represented as a string
707
+ return_type : list of str
708
+ The return type of the call
706
709
707
710
Raises
708
711
------
@@ -791,9 +794,10 @@ def parse_ported_function(self, file_index, function_key, function, args,
791
794
792
795
Returns
793
796
-------
794
- tuple : (str, [str])
795
- Tuple with the string representation of the ported function and the
796
- return type in a list of a string
797
+ return_str : str
798
+ The ported function represented as a string
799
+ return_type : list of str
800
+ The return type of the ported function
797
801
798
802
Raises
799
803
------
@@ -829,21 +833,27 @@ def parse_Constant(self, node, file_index, function_key):
829
833
830
834
Returns
831
835
-------
832
- tuple : (str, [str])
833
- Tuple with the string representation of the constant and the return
834
- type in a list of a string
836
+ return_str : str
837
+ The constant value represented as a string
838
+ return_type : list of str
839
+ The type of the constant
835
840
"""
836
841
# Strings need to be wrapped in quotes
837
842
if type (node .value ) is str :
838
- return ("\" " + node .value + "\" " ), ["str" ]
843
+ return_str = ("\" " + node .value + "\" " )
844
+ return_type = ["str" ]
839
845
840
846
# Python booleans are capital while C++ is lowercase, so we need to
841
847
# translate it
842
848
elif type (node .value ) is bool :
843
- return cvar .CPPVariable .bool_map [str (node .value )], ["bool" ]
849
+ return_str = cvar .CPPVariable .bool_map [str (node .value )]
850
+ return_type = ["bool" ]
844
851
845
852
else :
846
- return str (node .value ), [type (node .value ).__name__ ]
853
+ return_str = str (node .value )
854
+ return_type = [type (node .value ).__name__ ]
855
+
856
+ return return_str , return_type
847
857
848
858
# Operators
849
859
def parse_BoolOp (self , node , file_index , function_key ):
@@ -861,9 +871,10 @@ def parse_BoolOp(self, node, file_index, function_key):
861
871
862
872
Returns
863
873
-------
864
- tuple : (str, [str])
865
- Tuple with the string representation of the BoolOp and the return
866
- type in a list of a string
874
+ return_str : str
875
+ The BoolOp represented as a string
876
+ return_type : list of str
877
+ The return type of the BoolOp
867
878
868
879
Raises
869
880
------
@@ -906,7 +917,8 @@ def parse_BoolOp(self, node, file_index, function_key):
906
917
else :
907
918
return_type = compare_nodes [0 ][1 ]
908
919
909
- return "(" + return_str + ")" , return_type
920
+ return_str = "(" + return_str + ")"
921
+ return return_str , return_type
910
922
911
923
def parse_BinOp (self , node , file_index , function_key ):
912
924
"""
@@ -923,9 +935,10 @@ def parse_BinOp(self, node, file_index, function_key):
923
935
924
936
Returns
925
937
-------
926
- tuple : (str, [str])
927
- Tuple with the string representation of the BinOp and the return
928
- type in a list of a string
938
+ return_str : str
939
+ The BinOp represented as a string
940
+ return_type : list of str
941
+ The return type of the BinOp
929
942
930
943
Raises
931
944
------
@@ -945,32 +958,33 @@ def parse_BinOp(self, node, file_index, function_key):
945
958
if operator in PyAnalyzer .operator_map :
946
959
if operator == "Pow" :
947
960
self .output_files [file_index ].add_include_file ("math.h" )
948
- return_expr = "pow(" + left_str + ", " + right_str + ")"
961
+ return_str = "pow(" + left_str + ", " + right_str + ")"
949
962
return_type = ["float" ]
950
963
951
964
elif operator == "FloorDiv" :
952
- return_expr = left_str + " / " + right_str
965
+ return_str = left_str + " / " + right_str
953
966
# If they aren't both ints, we need to cast to int to truncate
954
967
if left_type [0 ] != "int" or right_type [0 ] != "int" :
955
- return_expr = "(int)(" + return_expr + ")"
968
+ return_str = "(int)(" + return_str + ")"
956
969
return_type = ["int" ]
957
970
958
971
elif operator == "Div" :
959
- return_expr = left_str + " / " + right_str
972
+ return_str = left_str + " / " + right_str
960
973
# We need to cast one to a double or it will perform integer
961
974
# math
962
975
if left_type [0 ] != "float" or right_type [0 ] != "float" :
963
- return_expr = "(double)" + return_expr
976
+ return_str = "(double)" + return_str
964
977
return_type = ["float" ]
965
978
966
979
else :
967
- return_expr = left_str \
980
+ return_str = left_str \
968
981
+ PyAnalyzer .operator_map [operator ] \
969
982
+ right_str
970
983
971
984
return_type = self .type_precedence (left_type , right_type )
972
985
973
- return "(" + return_expr + ")" , return_type
986
+ return_str = "(" + return_str + ")"
987
+ return return_str , return_type
974
988
975
989
def type_precedence (self , type_a , type_b ):
976
990
"""
@@ -987,7 +1001,7 @@ def type_precedence(self, type_a, type_b):
987
1001
988
1002
Returns
989
1003
-------
990
- list of str
1004
+ return_type : list of str
991
1005
The list that holds the type that should take precedence
992
1006
"""
993
1007
if type_a [0 ] in PyAnalyzer .type_precedence_dict and type_b [0 ] in PyAnalyzer .type_precedence_dict :
@@ -1020,9 +1034,10 @@ def parse_UnaryOp(self, node, file_index, function_key):
1020
1034
1021
1035
Returns
1022
1036
-------
1023
- tuple : (str, [str])
1024
- Tuple with the string representation of the UnaryOp and the return
1025
- type in a list of a string
1037
+ return_str : str
1038
+ The UnaryOp represented as a string
1039
+ return_type : list of str
1040
+ The return type of the UnaryOp
1026
1041
1027
1042
Raises
1028
1043
------
@@ -1039,11 +1054,12 @@ def parse_UnaryOp(self, node, file_index, function_key):
1039
1054
1040
1055
# Not operation becomes a bool no matter what type it operated on
1041
1056
if operator is ast .Not :
1042
- return_type = "bool"
1057
+ return_type = [ "bool" ]
1043
1058
else :
1044
- return_type = "int"
1059
+ return_type = [ "int" ]
1045
1060
1046
- return "(" + PyAnalyzer .operator_map [operator .__name__ ] + return_str + ")" , [return_type ]
1061
+ return_str = "(" + PyAnalyzer .operator_map [operator .__name__ ] + return_str + ")"
1062
+ return return_str , return_type
1047
1063
1048
1064
def parse_Compare (self , node , file_index , function_key ):
1049
1065
"""
@@ -1060,9 +1076,10 @@ def parse_Compare(self, node, file_index, function_key):
1060
1076
1061
1077
Returns
1062
1078
-------
1063
- tuple : (str, [str])
1064
- Tuple with the string representation of the comparison and the
1065
- return type in a list of a string
1079
+ return_str : str
1080
+ The Compare operation represented as a string
1081
+ return_type : list of str
1082
+ The return type of the Compare operation
1066
1083
1067
1084
Raises
1068
1085
------
@@ -1101,7 +1118,9 @@ def parse_Compare(self, node, file_index, function_key):
1101
1118
PyAnalyzer .comparison_map [node .ops [- 1 ].__class__ .__name__ ] \
1102
1119
+ comparator + ")"
1103
1120
1104
- return return_str , ["bool" ]
1121
+ # All comparisons come back as a bool
1122
+ return_type = ["bool" ]
1123
+ return return_str , return_type
1105
1124
1106
1125
def recurse_operator (self , node , file_index , function_key ):
1107
1126
"""
0 commit comments