Fix bug with TRUNC function and with type conversion functions called with constant as parameter
--- a/generate_IEC_std.py Mon Jun 06 16:29:08 2011 +0200
+++ b/generate_IEC_std.py Wed Jun 08 18:35:28 2011 +0200
@@ -267,6 +267,15 @@
return res.replace('\n','\n'+indent)
+def get_default_input_type(fdecls):
+ if type(fdecls) != type(tuple()) and len(fdecls) == 1:
+ ParamTypes = fdecls.values()[0]
+ if len(ParamTypes) == 1:
+ ParamType_name, ParamType_value = ParamTypes.items()[0]
+ if not ParamType_name.startswith("ANY") and type(ParamType_value) == type(tuple()):
+ return "&search_constant_type_c::%s_type_name" % ParamType_name.lower()
+ return "NULL"
+
###################################################################
### ###
### MAIN ###
@@ -346,8 +355,8 @@
*/
case function_%s :
{
- symbol_c *last_type_symbol = NULL;
-""" %(fname, fname.lower())
+ symbol_c *last_type_symbol = %s;
+""" %(fname, fname.lower(), get_default_input_type(fdecls))
indent = " "
st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n ')
@@ -378,8 +387,8 @@
*/
case function_%s :
{
- symbol_c *last_type_symbol = NULL;
-""" %(fname, fname.lower())
+ symbol_c *last_type_symbol = %s;
+""" %(fname, fname.lower(), get_default_input_type(fdecls))
indent = " "
il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n ')
@@ -427,8 +436,8 @@
*/
case function_%s :
{
- symbol_c *last_type_symbol = NULL;
-""" %(fname, fname.lower())
+ symbol_c *last_type_symbol = %s;
+""" %(fname, fname.lower(), get_default_input_type(fdecls))
indent = " "
search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n ')
@@ -460,8 +469,8 @@
*/
case function_%s :
{
- symbol_c *last_type_symbol = NULL;
-""" %(fname, fname.lower())
+ symbol_c *last_type_symbol = %s;
+""" %(fname, fname.lower(), get_default_input_type(fdecls))
indent = " "
search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n ')
--- a/plcopen/iec_std.csv Mon Jun 06 16:29:08 2011 +0200
+++ b/plcopen/iec_std.csv Wed Jun 08 18:35:28 2011 +0200
@@ -14,7 +14,7 @@
;;;;;;;;
Standard_functions_type;name;baseinputnumber;inputs;outputs;comment;extensible;python_eval_c_code_format;return_type_rule
_("Type conversion");*_TO_**;1;(ANY);ANY;_("Data type conversion");no;ANY_TO_ANY_FORMAT_GEN(ANY_TO_ANY_LIST,fdecl);defined
-;TRUNC;1;(ANY_REAL);ANY_INT;_("Rounding up/down");no;("int", None, None);&search_constant_type_c::integer
+;TRUNC;1;(ANY_REAL);ANY_INT;_("Rounding up/down");no;("int", "__move_", None);&search_constant_type_c::integer
;BCD_TO_**;1;(ANY_BIT);ANY_INT;_("Conversion from BCD");no;ANY_TO_ANY_FORMAT_GEN(BCD_TO_ANY_LIST,fdecl);defined
;*_TO_BCD;1;(ANY_INT);ANY_BIT;_("Conversion to BCD");no;ANY_TO_ANY_FORMAT_GEN(ANY_TO_BCD_LIST,fdecl);&search_constant_type_c::integer
;DATE_AND_TIME_TO_TIME_OF_DAY;1;(DT);TOD;_("Conversion to time-of-day");no;(None, "__date_and_time_to_time_of_day", None);defined