diff -r c4199b88cf60 -r 6cf858411d3a generate_IEC_std.py --- a/generate_IEC_std.py Fri Oct 17 16:22:15 2008 +0200 +++ b/generate_IEC_std.py Fri Oct 24 16:39:32 2008 +0200 @@ -41,6 +41,10 @@ # Get definitions from plcopen.structures import * +if len(sys.argv) != 2 : + print "Usage: " + sys.argv[0] + " path_name\n -> create files in path_name" + sys.exit(0) + #import pprint #pp = pprint.PrettyPrinter(indent=4) @@ -154,7 +158,7 @@ symbol_c *%(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value); last_type_symbol = last_type_symbol && search_expression_type->is_same_type(%(input_name)s_type_symbol, last_type_symbol) ? search_expression_type->common_type(%(input_name)s_type_symbol, last_type_symbol) : %(input_name)s_type_symbol ; """%{"input_name":Paramname} - + for ParamType,NextParamDecl in ParamTypes.iteritems(): res += """ @@ -167,6 +171,7 @@ "if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n ')} res += """ + ERROR; } """ @@ -176,6 +181,46 @@ res = "\n" fdecl=fdecls[0] + if not do_type_search_only: + code_gen = eval(fdecl["python_eval_c_code_format"]) + + if code_gen[1] is not None: + res += "function_name = (symbol_c*)(new pragma_c(\"%s\"));\n"%code_gen[1] + if fdecl["extensible"]: + res += """ +char nb_param_str[10]; +sprintf(nb_param_str, "%d", nb_param); +ADD_PARAM_LIST((symbol_c*)(new integer_c(nb_param_str)), (symbol_c*)(new int_type_name_c()), function_param_iterator_c::direction_in) +""" + for paramname,paramtype,unused in fdecl["inputs"]: + res += "ADD_PARAM_LIST(%(input_name)s_param_value, %(input_name)s_type_symbol, function_param_iterator_c::direction_in)\n"%{"input_name" : paramname} + + if fdecl["extensible"]: + res += """ +int base_num = %d; +symbol_c *param_value = NULL; +do{ + char my_name[10]; + sprintf(my_name, "IN%%d", base_num++); + identifier_c param_name(my_name); + + /* Get the value from a foo( = ) style call */ + param_value = function_call_param_iterator.search(¶m_name); + + /* Get the value from a foo() style call */ + if (param_value == NULL) + param_value = function_call_param_iterator.next(); + if (param_value != NULL){ + symbol_c *current_type_symbol = search_expression_type->get_type(param_value); + last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; + + /*Function specific CODE */ + ADD_PARAM_LIST(param_value, current_type_symbol, function_param_iterator_c::direction_in) + } + +}while(param_value != NULL); +"""%(fdecl["baseinputnumber"] + 2) + result_type_rule = fdecl["return_type_rule"] res += { "copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n", @@ -183,64 +228,14 @@ }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule) if not do_type_search_only: - code_gen = eval(fdecl["python_eval_c_code_format"]) - - code_gen_dic_decl = {} - for paramname,paramtype,unused in fdecl["inputs"]: - code_gen_dic_decl[paramname+"_value"] = '");\n%s_param_value->accept(*this);\ns4o.print("'%(paramname) - code_gen_dic_decl[paramname+"_type"] = '");\n%s_type_symbol->accept(*this);\ns4o.print("'%(paramname) - code_gen_dic_decl["return_type"] = '");\nreturn_type_symbol->accept(*this);\ns4o.print("' - code_gen_dic_decl["param_count"] = '");\ns4o.print_integer(nb_param);\ns4o.print("' - code_gen_dic_decl["common_type"] = '");\nlast_type_symbol->accept(*this);\ns4o.print("' - code_gen_dic_decl["start_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol))\n s4o.print("(' - code_gen_dic_decl["end_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol)) {\n s4o.print("&1");\n s4o.print(")");\n}\ns4o.print("' - - if type(code_gen) == type(tuple()): - res += 's4o.indent_right();\n' - res += 's4o.print("%s\\n" + s4o.indent_spaces);\n'%(code_gen[0]%code_gen_dic_decl) - static_param_accept_list = [] - for paramname,paramtype,unused in fdecl["inputs"]: - static_param_accept_list.append("%s_param_value->accept(*this);\n"%(paramname)) - res += ('s4o.print("%s\\n" + s4o.indent_spaces);\n'%(code_gen[1])).join(static_param_accept_list) - code = 's4o.print("%s\\n" + s4o.indent_spaces);\nparam_value->accept(*this);\n'%(code_gen[1]) - end_code = 's4o.print("%s");\ns4o.indent_left();\nreturn NULL;\n'%(code_gen[2]%code_gen_dic_decl) - else: - code = '' - end_code = ('s4o.print("' + code_gen%code_gen_dic_decl + '");\nreturn NULL;\n').replace('s4o.print("");\n','') - - if fdecl["extensible"]: - res += (""" -int base_num = %d; -symbol_c *param_value = NULL; -do{ - char my_name[10]; - sprintf(my_name, "IN%%d", base_num++); - identifier_c param_name(my_name); - - /* Get the value from a foo( = ) style call */ - param_value = function_call_param_iterator.search(¶m_name); - - /* Get the value from a foo() style call */ - if (param_value == NULL) - param_value = function_call_param_iterator.next(); - if (param_value != NULL){ - symbol_c *current_type_symbol = search_expression_type->get_type(param_value); - last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; - - /*Function specific CODE */ - %s - } - -}while(param_value != NULL); -%s -"""%(fdecl["baseinputnumber"]+2, code.replace('\n','\n '), end_code)) - else: - #res += code + end_code - res += end_code + if code_gen[0] is not None: + 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]) + res += "break;\n" else: res += "return return_type_symbol;\n" - return res.replace('\n','\n'+indent) ################################################################### @@ -336,7 +331,6 @@ case function_none : ERROR; } -return NULL; """ ################################################################### @@ -369,7 +363,6 @@ case function_none : ERROR; } -return NULL; """ ################################################################### @@ -379,10 +372,20 @@ """ search_type_code = matiec_header + """ -void *compute_standard_function_st(function_invocation_c *symbol) { - - function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); - function_call_param_iterator_c function_call_param_iterator(symbol); +void *compute_standard_function_default(function_invocation_c *st_symbol = NULL, il_formal_funct_call_c *il_symbol = NULL) { + function_type_t current_function_type; + function_call_param_iterator_c *tmp_function_call_param_iterator; + if (st_symbol != NULL && il_symbol == NULL) { + current_function_type = get_function_type((identifier_c *)st_symbol->function_name); + tmp_function_call_param_iterator = new function_call_param_iterator_c(st_symbol); + } + else if (st_symbol == NULL && il_symbol != NULL) { + current_function_type = get_function_type((identifier_c *)il_symbol->function_name); + tmp_function_call_param_iterator = new function_call_param_iterator_c(il_symbol); + } + else + ERROR; + function_call_param_iterator_c function_call_param_iterator(*tmp_function_call_param_iterator); search_expression_type_c* search_expression_type = this; switch(current_function_type){ @@ -487,10 +490,6 @@ else: break -if len(sys.argv) != 2 : - print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" - sys.exit(0) - # Now, print that out, or write to files from sys.argv for path, name, ext in [ ('stage4/generate_c','function_type_decl','h'),