Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#834): Add Logging And Improve Unroll #859

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/org/eolang/jeo/representation/CanonicalXmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo.representation;

import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
Expand Down Expand Up @@ -126,8 +127,18 @@ private String toEo() {
* @return Parsed XMIR.
* @throws IOException If fails.
*/
@SuppressWarnings("PMD.GuardLogStatement")
private XML parse(final String eoprog) throws IOException {
return new EoSyntax(this.name, new InputOf(eoprog)).parsed();
final long start = System.currentTimeMillis();
final XML parsed = new EoSyntax(this.name, new InputOf(eoprog)).parsed();
final long end = System.currentTimeMillis();
Logger.info(
this,
"We need to parse XMIR by using EoSyntax#parsed to make unrolling. The '%s' was parsed in %[ms]s",
this.name,
end - start
);
return parsed;
}

/**
Expand Down
95 changes: 58 additions & 37 deletions src/main/resources/org/eolang/parser/add-refs.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="add-refs" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eo="http://eolang.com" id="add-refs" version="2.0">
<!--
Here we go through all objects and find what their @base
are referring to. If we find the object they refer to,
Expand All @@ -32,52 +32,50 @@ SOFTWARE.
global or just a mistake.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:key name="o-by-name" match="o[@name]" use="@name"/>
<xsl:template match="o[@base]">
<xsl:apply-templates select="." mode="with-base"/>
</xsl:template>
<xsl:template match="o[@base]" mode="with-base">
<xsl:template match="o[not(starts-with(@base, '.'))]" mode="with-base">
<xsl:apply-templates select="." mode="no-dots"/>
</xsl:template>
<xsl:template match="o[@base!='$' and @base!='^']" mode="no-dots">
<xsl:variable name="current" select="."/>
<xsl:variable name="source" select="eo:closest($current, key('o-by-name', @base))"/>
<xsl:copy>
<xsl:variable name="parent" select="ancestor::*[o[@name=$current/@base]][1]"/>
<xsl:if test="$parent">
<xsl:variable name="source" select="$parent/o[@name=$current/@base]"/>
<xsl:if test="$parent">
<xsl:if test="count($source)!=1">
<xsl:message terminate="yes">
<xsl:text>Duplicate names inside "</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>", the base is "</xsl:text>
<xsl:value-of select="@base"/>
<xsl:text>" at the line #</xsl:text>
<xsl:if test="$source">
<xsl:if test="count($source)!=1">
<xsl:message terminate="yes">
<xsl:text>Duplicate names inside "</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>", the base is "</xsl:text>
<xsl:value-of select="@base"/>
<xsl:text>" at the line #</xsl:text>
<xsl:value-of select="@line"/>
<xsl:text> pointing to </xsl:text>
<xsl:for-each select="$source">
<xsl:if test="position()&gt;1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>/&gt;</xsl:text>
<xsl:text> at line #</xsl:text>
<xsl:value-of select="@line"/>
<xsl:text> pointing to </xsl:text>
<xsl:for-each select="$source">
<xsl:if test="position()&gt;1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>/&gt;</xsl:text>
<xsl:text> at line #</xsl:text>
<xsl:value-of select="@line"/>
</xsl:for-each>
<xsl:text>; it's internal bug</xsl:text>
</xsl:message>
</xsl:if>
<xsl:if test="not($source/@line)">
<xsl:message terminate="yes">
<xsl:text>Attribute @line is absent at "</xsl:text>
<xsl:value-of select="$source/@name"/>
<xsl:text>"</xsl:text>
</xsl:message>
</xsl:if>
<xsl:attribute name="ref">
<xsl:value-of select="$source/@line"/>
</xsl:attribute>
</xsl:for-each>
<xsl:text>; it's internal bug</xsl:text>
</xsl:message>
</xsl:if>
<xsl:if test="not($source/@line)">
<xsl:message terminate="yes">
<xsl:text>Attribute @line is absent at "</xsl:text>
<xsl:value-of select="$source/@name"/>
<xsl:text>"</xsl:text>
</xsl:message>
</xsl:if>
<xsl:attribute name="ref">
<xsl:value-of select="$source/@line"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
Expand All @@ -87,4 +85,27 @@ SOFTWARE.
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:function name="eo:closest" as="node()?">
<xsl:param name="current-node" as="node()"/>
<xsl:param name="nodes" as="node()*"/>
<xsl:variable name="intersecting-nodes" select="$nodes[eo:has-intersecting-route($current-node, .)]"/>
<xsl:for-each select="$intersecting-nodes">
<xsl:sort select="string-length(eo:get-route(.))" order="descending" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:function>
<xsl:function name="eo:has-intersecting-route" as="xs:boolean">
<xsl:param name="node1" as="node()"/>
<xsl:param name="node2" as="node()"/>
<xsl:variable name="route1" select="eo:get-route($node1)"/>
<xsl:variable name="route2" select="eo:get-route($node2)"/>
<xsl:sequence select="starts-with($route1, $route2)"/>
</xsl:function>
<xsl:function name="eo:get-route" as="xs:string">
<xsl:param name="node" as="node()"/>
<xsl:variable name="ancestors" select="$node/ancestor::*"/>
<xsl:sequence select="string-join(for $ancestor in $ancestors return generate-id($ancestor), '/')"/>
</xsl:function>
</xsl:stylesheet>
Loading