Bug on standard functions called with literals fixed
authorlaurent
Mon, 14 Dec 2009 11:00:39 +0100
changeset 486 0daecbcbfbf4
parent 485 d5ebb8eac934
child 487 580b04db8c65
Bug on standard functions called with literals fixed
generate_IEC_std.py
--- a/generate_IEC_std.py	Sat Dec 12 20:38:41 2009 +0100
+++ b/generate_IEC_std.py	Mon Dec 14 11:00:39 2009 +0100
@@ -233,14 +233,7 @@
         
         result_type_rule = fdecl["return_type_rule"]
         res += {
-            "copy_input" : """symbol_c * return_type_symbol;
-if (search_expression_type->is_literal_integer_type(last_type_symbol))
-    return_type_symbol = &search_constant_type_c::%s_type_name;
-else
-    return_type_symbol = last_type_symbol;
-"""%({True: "lword", False: """lint_type_name;
-else if (search_expression_type->is_literal_real_type(last_type_symbol))
-    return_type_symbol = &search_constant_type_c::lreal"""}[reduce(lambda x, y: x or y, [paramtype == "ANY_BIT" for paramname,paramtype,unused in fdecl["inputs"]], False)]),
+            "copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n",
             "defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(),
             }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule)
         
@@ -249,6 +242,26 @@
                 res += "function_type_prefix = %s;\n"%{"return_type" : "return_type_symbol"}.get(code_gen[0], "(symbol_c*)(new pragma_c(\"%s\"))"%code_gen[0])
             if code_gen[2] is not None:
                 res += "function_type_suffix = %s_symbol;\n"%{"common_type" : "last_type"}.get(code_gen[2], code_gen[2])
+            
+            any_common = reduce(lambda x, y: {"ANY": lambda x: x,
+                                          "ANY_BIT": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x),
+                                          "ANY_NUM": lambda x: {"ANY": y}.get(y, x),
+                                          "ANY_REAL": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x)}.get(x, y), 
+                                [paramtype for paramname,paramtype,unused in fdecl["inputs"]], "BOOL")
+            
+            first = True
+            for list, test_type, default_type in [(["ANY", "ANY_NUM"], "integer", "lint"),
+                                                  (["ANY_BIT"], "integer", "lword"),
+                                                  (["ANY", "ANY_REAL"], "real", "lreal")]:
+            
+                if any_common in list:
+                    if not first:
+                        res += "else "
+                    first = False
+                    res += """if (search_expression_type->is_literal_%s_type(function_type_suffix))
+    function_type_suffix = &search_constant_type_c::%s_type_name;
+"""%(test_type, default_type)
+        
             res += "break;\n"
         else:
             res += "return return_type_symbol;\n"