Fixed earlier XSLT optimizations. Some/most results were missing.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 18 Feb 2018 21:51:33 +0100
changeset 1945 90bf6bd94b94
parent 1944 6162e34fb246
child 1946 95fa4e05e30f
Fixed earlier XSLT optimizations. Some/most results were missing.
plcopen/POUVariablesCollector.py
plcopen/XSLTModelQuery.py
plcopen/instances_path.xslt
plcopen/instances_path.ysl2
plcopen/pou_variables.xslt
plcopen/pou_variables.ysl2
--- a/plcopen/POUVariablesCollector.py	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/POUVariablesCollector.py	Sun Feb 18 21:51:33 2018 +0100
@@ -63,9 +63,14 @@
         XSLTModelQuery.__init__(self,
                                 controller,
                                 "pou_variables.xslt",
-                                [(name, lambda *x : getattr(self.factory, name)(*x)) 
+                                [(name, self.FactoryCaller(name)) 
                                     for name in ["SetRoot", "AddVariable"]])
 
+    def FactoryCaller(self, funcname):
+        def CallFactory(*args):
+            return getattr(self.factory, funcname)(*args)
+        return CallFactory
+
     def Collect(self, root, debug):
         self.factory = VariablesTreeInfosFactory()
         self._process_xslt(root, debug)
--- a/plcopen/XSLTModelQuery.py	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/XSLTModelQuery.py	Sun Feb 18 21:51:33 2018 +0100
@@ -21,7 +21,7 @@
         # merge xslt extensions for library access to query specific ones
         xsltext = [
             ("GetProject", lambda *_ignored: 
-                controller.GetProject(self.debug)),
+                [controller.GetProject(self.debug)]),
             ("GetStdLibs", lambda *_ignored: 
                 [lib for lib in StdBlckLibs.values()]),
             ("GetExtensions", lambda *_ignored: 
--- a/plcopen/instances_path.xslt	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/instances_path.xslt	Sun Feb 18 21:51:33 2018 +0100
@@ -45,7 +45,7 @@
         <xsl:variable name="type_name">
           <xsl:value-of select="@typeName"/>
         </xsl:variable>
-        <xsl:apply-templates select="$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |&#10;                         $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
+        <xsl:apply-templates select="$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |&#10;                         $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
           <xsl:with-param name="instance_path">
             <xsl:value-of select="$pou_instance_path"/>
           </xsl:with-param>
@@ -92,7 +92,7 @@
         <xsl:variable name="type_name">
           <xsl:value-of select="@name"/>
         </xsl:variable>
-        <xsl:apply-templates select="$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |&#10;                         $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
+        <xsl:apply-templates select="$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |&#10;                         $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]">
           <xsl:with-param name="instance_path">
             <xsl:value-of select="$variable_path"/>
           </xsl:with-param>
--- a/plcopen/instances_path.ysl2	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/instances_path.ysl2	Sun Feb 18 21:51:33 2018 +0100
@@ -45,8 +45,8 @@
             }
             otherwise {
                 variable "type_name" > «@typeName»
-                apply """$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
-                         $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+                apply """$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                         $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
                     with "instance_path" > «$pou_instance_path»
                 }
             }
@@ -83,8 +83,8 @@
             }
             otherwise {
                 variable "type_name" > «@name»
-                apply """$all/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
-                         $all/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+                apply """$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                         $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
                     with "instance_path" > «$variable_path»
                 }
             }
--- a/plcopen/pou_variables.xslt	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/pou_variables.xslt	Sun Feb 18 21:51:33 2018 +0100
@@ -9,6 +9,7 @@
   <xsl:variable name="project" select="ns:GetProject()"/>
   <xsl:variable name="stdlib" select="ns:GetStdLibs()"/>
   <xsl:variable name="extensions" select="ns:GetExtensions()"/>
+  <xsl:variable name="all" select="$project | $stdlib | $extensions"/>
   <xsl:template name="add_root">
     <xsl:param name="class"/>
     <xsl:param name="type"/>
@@ -204,7 +205,7 @@
   <xsl:template mode="var_class" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:param name="default_class"/>
     <xsl:variable name="type_name" select="@name"/>
-    <xsl:variable name="pou_infos" select="($project|$stdlib|$extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]"/>
+    <xsl:variable name="pou_infos" select="$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name]"/>
     <xsl:choose>
       <xsl:when test="$pou_infos">
         <xsl:apply-templates mode="var_class" select="$pou_infos"/>
@@ -245,7 +246,7 @@
   </xsl:template>
   <xsl:template mode="var_edit" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:variable name="type_name" select="@name"/>
-    <xsl:variable name="pou_infos" select="$project/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]"/>
+    <xsl:variable name="pou_infos" select="$project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]"/>
     <xsl:choose>
       <xsl:when test="$pou_infos">
         <xsl:text>true</xsl:text>
@@ -263,9 +264,9 @@
   </xsl:template>
   <xsl:template mode="var_debug" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:variable name="type_name" select="@name"/>
-    <xsl:variable name="datatype_infos" select="($project|$stdlib|$extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]"/>
+    <xsl:variable name="datatype_infos" select="&#10;            $project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |&#10;            $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]&#10;        "/>
     <xsl:choose>
-      <xsl:when test="$datatype_infos != ''">
+      <xsl:when test="$datatype_infos">
         <xsl:apply-templates mode="var_debug" select="$datatype_infos"/>
       </xsl:when>
       <xsl:otherwise>
--- a/plcopen/pou_variables.ysl2	Sun Feb 18 21:30:48 2018 +0100
+++ b/plcopen/pou_variables.ysl2	Sun Feb 18 21:51:33 2018 +0100
@@ -16,6 +16,8 @@
     variable "stdlib", "ns:GetStdLibs()";
 
     variable "extensions", "ns:GetExtensions()";
+
+    variable "all", "$project | $stdlib | $extensions";
     
     function "add_root" {
         param "class";
@@ -171,7 +173,7 @@
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_class" {
         param "default_class";
         variable "type_name", "@name";
-        variable "pou_infos", "($project|$stdlib|$extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
+        variable "pou_infos", "$all/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
         choose {
             when "$pou_infos" {
                 apply "$pou_infos", mode="var_class";
@@ -218,7 +220,7 @@
     
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_edit" {
         variable "type_name", "@name";
-        variable "pou_infos", "$project/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
+        variable "pou_infos", "$project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
         choose {
             when "$pou_infos" > true
             otherwise > false
@@ -235,9 +237,12 @@
     
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_debug" {
         variable "type_name", "@name";
-        variable "datatype_infos", "($project|$stdlib|$extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
+        variable "datatype_infos", """
+            $project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+            $all/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]
+        """;
         choose {
-            when "$datatype_infos != ''" {
+            when "$datatype_infos" {
                 apply "$datatype_infos", mode="var_debug";
             }
             otherwise > false