generate_IEC_std.py
changeset 486 0daecbcbfbf4
parent 458 6e4ad5af894d
child 488 93bf600bae11
equal deleted inserted replaced
485:d5ebb8eac934 486:0daecbcbfbf4
   231 }while(param_value != NULL);
   231 }while(param_value != NULL);
   232 """%(fdecl["baseinputnumber"] + 2)
   232 """%(fdecl["baseinputnumber"] + 2)
   233         
   233         
   234         result_type_rule = fdecl["return_type_rule"]
   234         result_type_rule = fdecl["return_type_rule"]
   235         res += {
   235         res += {
   236             "copy_input" : """symbol_c * return_type_symbol;
   236             "copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n",
   237 if (search_expression_type->is_literal_integer_type(last_type_symbol))
       
   238     return_type_symbol = &search_constant_type_c::%s_type_name;
       
   239 else
       
   240     return_type_symbol = last_type_symbol;
       
   241 """%({True: "lword", False: """lint_type_name;
       
   242 else if (search_expression_type->is_literal_real_type(last_type_symbol))
       
   243     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)]),
       
   244             "defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(),
   237             "defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(),
   245             }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule)
   238             }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule)
   246         
   239         
   247         if not do_type_search_only:
   240         if not do_type_search_only:
   248             if code_gen[0] is not None:
   241             if code_gen[0] is not None:
   249                 res += "function_type_prefix = %s;\n"%{"return_type" : "return_type_symbol"}.get(code_gen[0], "(symbol_c*)(new pragma_c(\"%s\"))"%code_gen[0])
   242                 res += "function_type_prefix = %s;\n"%{"return_type" : "return_type_symbol"}.get(code_gen[0], "(symbol_c*)(new pragma_c(\"%s\"))"%code_gen[0])
   250             if code_gen[2] is not None:
   243             if code_gen[2] is not None:
   251                 res += "function_type_suffix = %s_symbol;\n"%{"common_type" : "last_type"}.get(code_gen[2], code_gen[2])
   244                 res += "function_type_suffix = %s_symbol;\n"%{"common_type" : "last_type"}.get(code_gen[2], code_gen[2])
       
   245             
       
   246             any_common = reduce(lambda x, y: {"ANY": lambda x: x,
       
   247                                           "ANY_BIT": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x),
       
   248                                           "ANY_NUM": lambda x: {"ANY": y}.get(y, x),
       
   249                                           "ANY_REAL": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x)}.get(x, y), 
       
   250                                 [paramtype for paramname,paramtype,unused in fdecl["inputs"]], "BOOL")
       
   251             
       
   252             first = True
       
   253             for list, test_type, default_type in [(["ANY", "ANY_NUM"], "integer", "lint"),
       
   254                                                   (["ANY_BIT"], "integer", "lword"),
       
   255                                                   (["ANY", "ANY_REAL"], "real", "lreal")]:
       
   256             
       
   257                 if any_common in list:
       
   258                     if not first:
       
   259                         res += "else "
       
   260                     first = False
       
   261                     res += """if (search_expression_type->is_literal_%s_type(function_type_suffix))
       
   262     function_type_suffix = &search_constant_type_c::%s_type_name;
       
   263 """%(test_type, default_type)
       
   264         
   252             res += "break;\n"
   265             res += "break;\n"
   253         else:
   266         else:
   254             res += "return return_type_symbol;\n"
   267             res += "return return_type_symbol;\n"
   255         
   268         
   256         return res.replace('\n','\n'+indent)
   269         return res.replace('\n','\n'+indent)