plcopen/structures.py
changeset 23 cce8d5662738
parent 22 a765fae3b361
child 25 8dc68e669d99
equal deleted inserted replaced
22:a765fae3b361 23:cce8d5662738
   478         if type(fdecls) != type(tuple()):
   478         if type(fdecls) != type(tuple()):
   479             res = ""
   479             res = ""
   480             for Paramname, ParamTypes in fdecls.iteritems():
   480             for Paramname, ParamTypes in fdecls.iteritems():
   481                 if do_il:
   481                 if do_il:
   482                     res += """
   482                     res += """
   483 {
   483 {"""
       
   484                     if not do_type_search_only:
       
   485                         res += """
   484     /* Get the value from a foo(<param_name> = <param_value>) style call */
   486     /* Get the value from a foo(<param_name> = <param_value>) style call */
   485     symbol_c *%(input_name)s_param_value = &this->default_variable_name;
   487     symbol_c *%(input_name)s_param_value = &this->default_variable_name;
   486     
   488 """%{"input_name":Paramname}
       
   489                     res += """
       
   490     symbol_c *%(input_name)s_type_symbol = param_data_type;
   487     last_type_symbol = param_data_type;
   491     last_type_symbol = param_data_type;
   488 """%{"input_name":Paramname}
   492 """%{"input_name":Paramname}
   489                 else:
   493                 else:
   490                     res += """
   494                     res += """
   491 {
   495 {
   704     {
   708     {
   705         symbol_c *last_type_symbol = NULL;
   709         symbol_c *last_type_symbol = NULL;
   706 """    %(fname, fname.lower())
   710 """    %(fname, fname.lower())
   707         indent =  "    "
   711         indent =  "    "
   708 
   712 
   709         il_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n    ')
   713         il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n    ')
   710         
   714         
   711         il_code_gen += """
   715         il_code_gen += """
   712     }/*function_%s*/
   716     }/*function_%s*/
   713     break;
   717     break;
   714 """    %(fname.lower())
   718 """    %(fname.lower())
   715     st_code_gen +=  """
   719     il_code_gen +=  """
   716     case function_none :
   720     case function_none :
   717     ERROR;
   721     ERROR;
   718 }
   722 }
   719 return NULL;
   723 return NULL;
   720 """
   724 """
   724     search_type_code =  """
   728     search_type_code =  """
   725 /****
   729 /****
   726  * IEC 61131-3 standard function lib
   730  * IEC 61131-3 standard function lib
   727  * generated code, do not edit by hand
   731  * generated code, do not edit by hand
   728  */
   732  */
   729 switch(current_function_type){
   733 
       
   734 void *compute_standard_function_st(function_invocation_c *symbol) {
       
   735 
       
   736   function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
       
   737   function_call_param_iterator_c function_call_param_iterator(symbol);
       
   738   search_expression_type_c* search_expression_type = this;
       
   739 
       
   740   switch(current_function_type){
   730 """
   741 """
   731     
   742     
   732     for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
   743     for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
   733         search_type_code += """
   744         search_type_code += """
   734 /****
   745 /****
   747     break;
   758     break;
   748 """    %(fname.lower())
   759 """    %(fname.lower())
   749     search_type_code += """
   760     search_type_code += """
   750     case function_none :
   761     case function_none :
   751     ERROR;
   762     ERROR;
       
   763   }
       
   764   return NULL;
   752 }
   765 }
   753 return NULL;
   766 
       
   767 void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type) {
       
   768   
       
   769   function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
       
   770   function_call_param_iterator_c function_call_param_iterator(symbol);  
       
   771   search_expression_type_c* search_expression_type = this;
       
   772 
       
   773   switch(current_function_type){
       
   774 """
       
   775 
       
   776     for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
       
   777         search_type_code += """
       
   778 /****
       
   779  *%s
       
   780  */
       
   781     case function_%s :
       
   782     {
       
   783         symbol_c *last_type_symbol = NULL;
       
   784 """    %(fname, fname.lower())
       
   785         indent =  "    "
       
   786 
       
   787         search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n    ')
       
   788         
       
   789         search_type_code += """
       
   790     }/*function_%s*/
       
   791     break;
       
   792 """    %(fname.lower())
       
   793     search_type_code += """
       
   794     case function_none :
       
   795     ERROR;
       
   796   }
       
   797   return NULL;
       
   798 }
   754 """
   799 """
   755 
   800 
   756 
   801 
   757     # Now, print that out, or write to files from sys.argv
   802     # Now, print that out, or write to files from sys.argv
   758     for name, ext in [
   803     for name, ext in [