# HG changeset patch # User Laurent Bessard # Date 1345385221 -7200 # Node ID 75096d6c271c6d651f97661b569ef7e2cd4d8597 # Parent 330f578e228dc5a9ecf616272c45b70ad3157a60 Fix bug while generating code with structured_variables as Standard Function inputs (enable to compute function return type in some cases) diff -r 330f578e228d -r 75096d6c271c PLCGenerator.py --- a/PLCGenerator.py Sun Aug 19 16:02:12 2012 +0200 +++ b/PLCGenerator.py Sun Aug 19 16:07:01 2012 +0200 @@ -27,7 +27,6 @@ from types import * import re - # Dictionary associating PLCOpen variable categories to the corresponding # IEC 61131-3 variable categories varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", @@ -76,6 +75,9 @@ else: return cmp(ay, by) +REAL_MODEL = re.compile("[0-9]+\.[0-9]+$") +INTEGER_MODEL = re.compile("[0-9]+$") + #------------------------------------------------------------------------------- # Specific exception for PLC generating errors #------------------------------------------------------------------------------- @@ -485,11 +487,26 @@ # Return the type of a variable defined in interface def GetVariableType(self, name): - for list_type, option, located, vars in self.Interface: - for var_type, var_name, var_address, var_initial in vars: - if name == var_name: - return var_type - return None + parts = name.split('.') + current_type = None + if len(parts) > 0: + name = parts.pop(0) + for list_type, option, located, vars in self.Interface: + for var_type, var_name, var_address, var_initial in vars: + if name == var_name: + current_type = var_type + break + while current_type is not None and len(parts) > 0: + tagname = self.ParentGenerator.Controler.ComputeDataTypeName(current_type) + infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname) + name = parts.pop(0) + current_type = None + if infos is not None and infos["type"] == "Structure": + for element in infos["elements"]: + if element["Name"] == name: + current_type = element["Type"] + break + return current_type # Return connectors linked by a connection to the given connector def GetConnectedConnector(self, connector, body): @@ -632,6 +649,10 @@ parts = expression.split("#") if len(parts) > 1: var_type = parts[0] + elif REAL_MODEL.match(expression): + var_type = "ANY_REAL" + elif INTEGER_MODEL.match(expression): + var_type = "ANY_NUM" elif expression.startswith("'"): var_type = "STRING" elif expression.startswith('"'):