Optimize single-true-match classes into aliases
Single-predicate classifications matching on TRUE can be optimized into aliases. These sometimes occur in hand-written code, but can also be generated by templates.master
parent
3eca3cf8dc
commit
603e9fb342
|
@ -533,6 +533,56 @@
|
|||
</function>
|
||||
|
||||
|
||||
<!--
|
||||
Single-TRUE-match classifications are effectively aliases
|
||||
-->
|
||||
<template mode="compile" priority="7"
|
||||
match="lv:classify[ count( lv:match ) = 1
|
||||
and lv:match/@value='TRUE' ]">
|
||||
<param name="symtable-map" as="map(*)" tunnel="yes" />
|
||||
|
||||
<variable name="src" as="xs:string"
|
||||
select="lv:match/@on" />
|
||||
<variable name="src-sym" as="element( preproc:sym )"
|
||||
select="$symtable-map( $src )" />
|
||||
|
||||
<choose>
|
||||
<!-- we only handle aliasing of other classifications -->
|
||||
<when test="$src-sym/@type = 'cgen'">
|
||||
<sequence select="$compiler:nl" />
|
||||
|
||||
<!-- simply alias the @yields -->
|
||||
<sequence select="concat( 'args[''', @yields, '''] = ',
|
||||
'args[''', $src, ''']; ')" />
|
||||
|
||||
<variable name="class-sym" as="element( preproc:sym )"
|
||||
select="$symtable-map( $src-sym/@parent )" />
|
||||
|
||||
<variable name="cdest" as="xs:string"
|
||||
select="if ( @preproc:generated = 'true' ) then
|
||||
'genclasses'
|
||||
else
|
||||
'classes'" />
|
||||
|
||||
<variable name="cdest-src" as="xs:string"
|
||||
select="if ( $class-sym/@preproc:generated = 'true' ) then
|
||||
'genclasses'
|
||||
else
|
||||
'classes'" />
|
||||
|
||||
<sequence select="concat( $cdest, '[''', @as, '''] = ',
|
||||
$cdest-src, '[''',
|
||||
$class-sym/@orig-name, '''];' )" />
|
||||
</when>
|
||||
|
||||
<!-- they must otherwise undergo the usual computation -->
|
||||
<otherwise>
|
||||
<next-match />
|
||||
</otherwise>
|
||||
</choose>
|
||||
</template>
|
||||
|
||||
|
||||
<!--
|
||||
Generate code to perform a classification
|
||||
|
||||
|
@ -542,7 +592,7 @@
|
|||
|
||||
@return generated classification expression
|
||||
-->
|
||||
<template match="lv:classify" mode="compile">
|
||||
<template match="lv:classify" mode="compile" priority="5">
|
||||
<param name="symtable-map" as="map(*)" tunnel="yes" />
|
||||
<param name="noclass" />
|
||||
<param name="ignores" />
|
||||
|
|
Loading…
Reference in New Issue