diff -r 24577755485d -r d1f6ea56555d PLCGenerator.py --- a/PLCGenerator.py Mon Jun 10 09:54:24 2013 +0200 +++ b/PLCGenerator.py Mon Jun 10 11:22:05 2013 +0200 @@ -900,11 +900,12 @@ connections = instance.connectionPointIn.getconnections() if connections is not None: expression = self.ComputeExpression(body, connections) - self.Program += [(self.CurrentIndent, ()), - (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), - (" := ", ())] - self.Program += expression - self.Program += [(";\n", ())] + if expression is not None: + self.Program += [(self.CurrentIndent, ()), + (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), + (" := ", ())] + self.Program += expression + self.Program += [(";\n", ())] elif isinstance(instance, plcopen.fbdObjects_block): block_type = instance.gettypeName() self.ParentGenerator.GeneratePouProgram(block_type) @@ -920,16 +921,20 @@ elif isinstance(instance, plcopen.commonObjects_connector): connector = instance.getname() if self.ComputedConnectors.get(connector, None): - continue - self.ComputedConnectors[connector] = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) + continue + expression = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) + if expression is not None: + self.ComputedConnectors[connector] = expression elif isinstance(instance, plcopen.ldObjects_coil): connections = instance.connectionPointIn.getconnections() if connections is not None: coil_info = (self.TagName, "coil", instance.getlocalId()) - expression = self.ExtractModifier(instance, self.ComputeExpression(body, connections), coil_info) - self.Program += [(self.CurrentIndent, ())] - self.Program += [(instance.getvariable(), coil_info + ("reference",))] - self.Program += [(" := ", ())] + expression + [(";\n", ())] + expression = self.ComputeExpression(body, connections) + if expression is not None: + expression = self.ExtractModifier(instance, expression, coil_info) + self.Program += [(self.CurrentIndent, ())] + self.Program += [(instance.getvariable(), coil_info + ("reference",))] + self.Program += [(" := ", ())] + expression + [(";\n", ())] def FactorizePaths(self, paths): same_paths = {} @@ -995,8 +1000,9 @@ connections = connector.connectionPointIn.getconnections() if connections is not None: expression = self.ComputeExpression(body, connections, order) - self.ComputedConnectors[name] = expression - paths.append(str(expression)) + if expression is not None: + self.ComputedConnectors[name] = expression + paths.append(str(expression)) else: raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) elif isinstance(next, plcopen.ldObjects_contact): @@ -1039,6 +1045,8 @@ def ComputeExpression(self, body, connections, order = False, to_inout = False): paths = self.GeneratePaths(connections, body, order, to_inout) + if len(paths) == 0: + return None if len(paths) > 1: factorized_paths = self.FactorizePaths(paths) if len(factorized_paths) > 1: @@ -1262,9 +1270,10 @@ connections = instance.connectionPointIn.getconnections() if connections is not None: expression = self.ComputeExpression(transitionBody, connections) - transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] - self.SFCComputedBlocks += self.Program - self.Program = [] + if expression is not None: + transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] + self.SFCComputedBlocks += self.Program + self.Program = [] if not transition_infos.has_key("content"): raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"] self.TagName = previous_tagname @@ -1275,9 +1284,10 @@ connections = transition.getconnections() if connections is not None: expression = self.ComputeExpression(body, connections) - transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] - self.SFCComputedBlocks += self.Program - self.Program = [] + if expression is not None: + transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] + self.SFCComputedBlocks += self.Program + self.Program = [] for step in steps: self.GenerateSFCStep(step, pou) step_name = step.getname()