plcopen/structures.py
branchpython3
changeset 3750 f62625418bff
parent 2456 7373e3048167
child 3751 a80a66ba52d6
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 
    27 import re
    27 import re
    28 from collections import OrderedDict
    28 from collections import OrderedDict
    29 from functools import reduce
    29 from functools import reduce
    30 
    30 
    31 from plcopen.plcopen import LoadProject
    31 from plcopen.plcopen import LoadProject
    51 
    51 
    52 def GetSubTypes(type):
    52 def GetSubTypes(type):
    53     """
    53     """
    54     Returns list of all types that correspont to the ANY* meta type
    54     Returns list of all types that correspont to the ANY* meta type
    55     """
    55     """
    56     return [typename for typename, _parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, type)]
    56     return [typename for typename, _parenttype in list(TypeHierarchy.items()) if not typename.startswith("ANY") and IsOfType(typename, type)]
    57 
    57 
    58 
    58 
    59 DataTypeRange = dict(DataTypeRange_list)
    59 DataTypeRange = dict(DataTypeRange_list)
    60 
    60 
    61 """
    61 """
    76 
    76 
    77 StdBlckLibs = {libname: LoadProject(tc6fname)[0]
    77 StdBlckLibs = {libname: LoadProject(tc6fname)[0]
    78                for libname, tc6fname in StdTC6Libs}
    78                for libname, tc6fname in StdTC6Libs}
    79 StdBlckLst = [{"name": libname, "list":
    79 StdBlckLst = [{"name": libname, "list":
    80                [GetBlockInfos(pous) for pous in lib.getpous()]}
    80                [GetBlockInfos(pous) for pous in lib.getpous()]}
    81               for libname, lib in StdBlckLibs.iteritems()]
    81               for libname, lib in StdBlckLibs.items()]
    82 
    82 
    83 # -------------------------------------------------------------------------------
    83 # -------------------------------------------------------------------------------
    84 #                             Test identifier
    84 #                             Test identifier
    85 # -------------------------------------------------------------------------------
    85 # -------------------------------------------------------------------------------
    86 
    86 
   146     params = []
   146     params = []
   147 
   147 
   148     len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables])
   148     len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables])
   149 
   149 
   150     for param_type in decl:
   150     for param_type in decl:
   151         if param_type in variables.keys():
   151         if param_type in list(variables.keys()):
   152             param_name = param_type
   152             param_name = param_type
   153             param_type = variables[param_type]
   153             param_type = variables[param_type]
   154         elif len_of_not_predifined_variable > 1:
   154         elif len_of_not_predifined_variable > 1:
   155             param_name = "IN%d" % base
   155             param_name = "IN%d" % base
   156             base += 1
   156             base += 1
   200                 Standard_Functions_Decl.append(Current_section)
   200                 Standard_Functions_Decl.append(Current_section)
   201             if Current_section:
   201             if Current_section:
   202                 Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
   202                 Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
   203                 baseinputnumber = int(Function_decl.get("baseinputnumber", 1))
   203                 baseinputnumber = int(Function_decl.get("baseinputnumber", 1))
   204                 Function_decl["baseinputnumber"] = baseinputnumber
   204                 Function_decl["baseinputnumber"] = baseinputnumber
   205                 for param, value in Function_decl.iteritems():
   205                 for param, value in Function_decl.items():
   206                     if param in translate:
   206                     if param in translate:
   207                         Function_decl[param] = translate[param](value)
   207                         Function_decl[param] = translate[param](value)
   208                 Function_decl["type"] = "function"
   208                 Function_decl["type"] = "function"
   209 
   209 
   210                 if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*'):
   210                 if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*'):
   248                         # apply filter given in "filter" column
   248                         # apply filter given in "filter" column
   249                         filter_name = Function_decl["filter"]
   249                         filter_name = Function_decl["filter"]
   250                         store = True
   250                         store = True
   251                         for (InTypes, OutTypes) in ANY_TO_ANY_FILTERS.get(filter_name, []):
   251                         for (InTypes, OutTypes) in ANY_TO_ANY_FILTERS.get(filter_name, []):
   252                             outs = reduce(lambda a, b: a or b,
   252                             outs = reduce(lambda a, b: a or b,
   253                                           map(lambda testtype: IsOfType(
   253                                           [IsOfType(
   254                                               Function_decl["outputs"][0][1],
   254                                               Function_decl["outputs"][0][1],
   255                                               testtype), OutTypes))
   255                                               testtype) for testtype in OutTypes])
   256                             inps = reduce(lambda a, b: a or b,
   256                             inps = reduce(lambda a, b: a or b,
   257                                           map(lambda testtype: IsOfType(
   257                                           [IsOfType(
   258                                               Function_decl["inputs"][0][1],
   258                                               Function_decl["inputs"][0][1],
   259                                               testtype), InTypes))
   259                                               testtype) for testtype in InTypes])
   260                             if inps and outs and Function_decl["outputs"][0][1] != Function_decl["inputs"][0][1]:
   260                             if inps and outs and Function_decl["outputs"][0][1] != Function_decl["inputs"][0][1]:
   261                                 store = True
   261                                 store = True
   262                                 break
   262                                 break
   263                             else:
   263                             else:
   264                                 store = False
   264                                 store = False
   306 
   306 
   307 # Keywords for Type Declaration
   307 # Keywords for Type Declaration
   308 TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"]
   308 TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"]
   309 TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"]
   309 TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"]
   310 TYPE_KEYWORDS = ["ARRAY", "OF", "T", "D", "TIME_OF_DAY", "DATE_AND_TIME"] + TYPE_BLOCK_START_KEYWORDS + TYPE_BLOCK_END_KEYWORDS
   310 TYPE_KEYWORDS = ["ARRAY", "OF", "T", "D", "TIME_OF_DAY", "DATE_AND_TIME"] + TYPE_BLOCK_START_KEYWORDS + TYPE_BLOCK_END_KEYWORDS
   311 TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS])
   311 TYPE_KEYWORDS.extend([keyword for keyword in list(TypeHierarchy.keys()) if keyword not in TYPE_KEYWORDS])
   312 
   312 
   313 
   313 
   314 # Keywords for Variable Declaration
   314 # Keywords for Variable Declaration
   315 VAR_BLOCK_START_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", "VAR_EXTERNAL"]
   315 VAR_BLOCK_START_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", "VAR_EXTERNAL"]
   316 VAR_BLOCK_END_KEYWORDS = ["END_VAR"]
   316 VAR_BLOCK_END_KEYWORDS = ["END_VAR"]