depgen: Combine preproc:symtable sym-ref generation cases

This does not impact performance, but it makes it less confusing.  What a
mess this whole thing is.  I'll have to incrementally refactor it until it
makes sense enough to optimize.

For this who don't know, from XSLT 1.0 days: "rtf" means "result tree
fragment", before sequences were a thing, and you had to treat generated
trees specially.  Yeah, old code.

DEV-15114
main
Mike Gerwitz 2023-10-18 16:28:42 -04:00
parent e20076235e
commit b3f92e0678
1 changed files with 52 additions and 71 deletions

View File

@ -142,7 +142,7 @@
<!-- grab the original source symbol for these references and augment them <!-- grab the original source symbol for these references and augment them
with any additional dependency metadata --> with any additional dependency metadata -->
<variable name="syms-rtf"> <variable name="syms" as="element( preproc:sym )*">
<for-each select="$uniq"> <for-each select="$uniq">
<variable name="name" select="@name" /> <variable name="name" select="@name" />
<variable name="sym" as="element( preproc:sym )?" <variable name="sym" as="element( preproc:sym )?"
@ -178,8 +178,6 @@
</for-each> </for-each>
</variable> </variable>
<variable name="syms" select="$syms-rtf/preproc:sym" />
<!-- only applicable if the symbol is @lax and the symbol was not <!-- only applicable if the symbol is @lax and the symbol was not
found in the local symbol table --> found in the local symbol table -->
<variable name="lax" select=" <variable name="lax" select="
@ -202,24 +200,17 @@
</for-each> </for-each>
<!-- @tex provided an non-empty, or function --> <!-- @tex provided an non-empty, or function -->
<for-each select=" <for-each select="$syms">
$syms[ <preproc:sym-ref>
( @tex and not( @tex='' ) ) <choose>
or @type='func' <!-- even if function, @tex overrides symbol -->
]"> <when test="@tex and not( @tex='' )">
<attribute name="tex" select="@tex" />
<choose>
<!-- even if function, @tex overrides symbol -->
<when test="@tex and not( @tex='' )">
<preproc:sym-ref tex="{@tex}">
<sequence select="@*" /> <sequence select="@*" />
<sequence select="preproc:meta/@*" /> <sequence select="preproc:meta/@*" />
</preproc:sym-ref> </when>
</when>
<!-- must be a function; use its name --> <when test="@type = 'func'">
<otherwise>
<preproc:sym-ref>
<sequence select="@*" /> <sequence select="@*" />
<sequence select="preproc:meta/@*" /> <sequence select="preproc:meta/@*" />
@ -228,63 +219,53 @@
<value-of select="@name" /> <value-of select="@name" />
<text>}</text> <text>}</text>
</attribute> </attribute>
</preproc:sym-ref> </when>
</otherwise>
</choose>
</for-each>
<!-- no @tex, @tex empty, no function --> <otherwise>
<for-each select=" <variable name="name" select="@name" />
$syms[ <variable name="sym" select="." />
( not( @tex ) or @tex='' )
and not( @type='func' )
]">
<variable name="name" select="@name" /> <!-- minimal attribute copy (avoid data duplication as much as
<variable name="sym" select="." /> possible to reduce modification headaches later on) -->
<sequence select="@name, @parent" />
<sequence select="preproc:meta/@*" />
<preproc:sym-ref> <!-- assign a symbol -->
<!-- minimal attribute copy (avoid data duplication as much as <variable name="pos" select="position()" />
possible to reduce modification headaches later on) --> <attribute name="tex">
<sequence select="@name, @parent" /> <variable name="texsym" select="
<sequence select="preproc:meta/@*" /> $tex-defaults/preproc:syms/preproc:sym[ $pos ]
<!-- assign a symbol -->
<variable name="pos" select="position()" />
<attribute name="tex">
<variable name="texsym" select="
$tex-defaults/preproc:syms/preproc:sym[
position() = $pos
]
" />
<choose>
<when test="$sym/@tex and not( $sym/@tex='' )">
<value-of select="$sym/@tex" />
</when>
<!-- scalar/vector default -->
<when test="$texsym and number( $sym/@dim ) lt 2">
<value-of select="$texsym/@value" />
</when>
<!-- matrix default -->
<when test="$texsym">
<value-of select="$texsym/@vec" />
</when>
<!-- no default available; generate one -->
<otherwise>
<value-of select="
if ( number( $sym/@dim ) lt 2 ) then '\theta'
else '\Theta'
" /> " />
<text>_{</text>
<value-of select="$pos" /> <choose>
<text>}</text> <when test="$sym/@tex and not( $sym/@tex='' )">
</otherwise> <value-of select="$sym/@tex" />
</choose> </when>
</attribute>
<!-- scalar/vector default -->
<when test="$texsym and number( $sym/@dim ) lt 2">
<value-of select="$texsym/@value" />
</when>
<!-- matrix default -->
<when test="$texsym">
<value-of select="$texsym/@vec" />
</when>
<!-- no default available; generate one -->
<otherwise>
<value-of select="
if ( number( $sym/@dim ) lt 2 ) then '\theta'
else '\Theta'
" />
<text>_{</text>
<value-of select="$pos" />
<text>}</text>
</otherwise>
</choose>
</attribute>
</otherwise>
</choose>
</preproc:sym-ref> </preproc:sym-ref>
</for-each> </for-each>
</preproc:sym-dep> </preproc:sym-dep>