map compiler: Use symbol table

This allows for the proper importing of symbols into the package
generated by the map compiler, which in turn allows for processing
their default values.
master
Mike Gerwitz 2017-05-08 16:47:14 -04:00
parent 8e5666f845
commit b7596515b3
3 changed files with 91 additions and 57 deletions

View File

@ -97,7 +97,25 @@
</call-template> </call-template>
<!-- copy all source nodes --> <!-- copy all source nodes -->
<copy-of select="*" /> <sequence select="node()" />
</lv:package>
</variable>
<!-- process symbol table -->
<variable name="pkg-with-symtable" as="element( lv:package )">
<call-template name="preproc:gen-deps">
<with-param name="pkg" as="element( lv:package )">
<apply-templates select="$pkg" mode="preproc:sym-discover">
<with-param name="orig-root" select="." />
</apply-templates>
</with-param>
</call-template>
</variable>
<!-- final result with compiled fragments -->
<lv:package>
<sequence select="$pkg-with-symtable/@*,
$pkg-with-symtable/node()" />
<preproc:fragments> <preproc:fragments>
<!-- special fragment to be output as the head --> <!-- special fragment to be output as the head -->
@ -110,6 +128,7 @@
<!-- compile mapped --> <!-- compile mapped -->
<apply-templates select="./lvm:*" mode="lvmc:compile"> <apply-templates select="./lvm:*" mode="lvmc:compile">
<with-param name="symtable" select="$pkg-with-symtable/preproc:symtable" />
<with-param name="rater" select="$rater" /> <with-param name="rater" select="$rater" />
<with-param name="type" select="'map'" /> <with-param name="type" select="'map'" />
</apply-templates> </apply-templates>
@ -121,16 +140,6 @@
</preproc:fragment> </preproc:fragment>
</preproc:fragments> </preproc:fragments>
</lv:package> </lv:package>
</variable>
<!-- output the result after symbol processing -->
<call-template name="preproc:gen-deps">
<with-param name="pkg" as="element( lv:package )">
<apply-templates select="$pkg" mode="preproc:sym-discover">
<with-param name="orig-root" select="." />
</apply-templates>
</with-param>
</call-template>
</template> </template>
@ -140,6 +149,12 @@
<template match="lvm:return-map" mode="lvmc:compile" priority="8"> <template match="lvm:return-map" mode="lvmc:compile" priority="8">
<param name="rater" /> <param name="rater" />
<!-- we don't have use for this right now, but it's required
by other parts of this system -->
<variable name="dummy-symtable" as="element( preproc:symtable )">
<preproc:symtable lvmc:sym-ignore="true" />
</variable>
<variable name="pkg"> <variable name="pkg">
<lv:package name="{$__srcpkg}" lvmc:type="retmap"> <lv:package name="{$__srcpkg}" lvmc:type="retmap">
<!-- initial symbol table; full table will be generated below --> <!-- initial symbol table; full table will be generated below -->
@ -160,6 +175,7 @@
</preproc:fragment> </preproc:fragment>
<apply-templates select="./lvm:*" mode="lvmc:compile"> <apply-templates select="./lvm:*" mode="lvmc:compile">
<with-param name="symtable" select="$dummy-symtable" />
<with-param name="rater" select="$rater" /> <with-param name="rater" select="$rater" />
<with-param name="type" select="'retmap'" /> <with-param name="type" select="'retmap'" />
</apply-templates> </apply-templates>
@ -210,7 +226,7 @@
<!-- allow mappings to be overridden after import, which allows defaults <!-- allow mappings to be overridden after import, which allows defaults
to be set and then overridden --> to be set and then overridden -->
<preproc:sym name=":{$type-prefix}:{$name}" virtual="true" <preproc:sym name=":{$type-prefix}:{$name}" virtual="true"
type="{$type-prefix}" pollute="true"> keep="true" type="{$type-prefix}" pollute="true">
<!-- for consistency and cleanliness, only copy over if set --> <!-- for consistency and cleanliness, only copy over if set -->
<if test="@override='true'"> <if test="@override='true'">
@ -231,7 +247,7 @@
Directly map an input to the output Directly map an input to the output
--> -->
<template match="lvm:pass" mode="lvmc:compile" priority="5"> <template match="lvm:pass" mode="lvmc:compile" priority="5">
<param name="rater" /> <param name="symtable" as="element( preproc:symtable )" />
<param name="type" /> <param name="type" />
<preproc:fragment id=":{$type}:{@name}"> <preproc:fragment id=":{$type}:{@name}">
@ -239,7 +255,7 @@
<value-of select="@name" /> <value-of select="@name" />
<text>']=</text> <text>']=</text>
<call-template name="lvmc:gen-input-default"> <call-template name="lvmc:gen-input-default">
<with-param name="rater" select="$rater" /> <with-param name="symtable" select="$symtable" />
<with-param name="to" select="@name" /> <with-param name="to" select="@name" />
<with-param name="from" select="@name" /> <with-param name="from" select="@name" />
</call-template> </call-template>
@ -269,7 +285,7 @@
Maps an input to an output of a different name Maps an input to an output of a different name
--> -->
<template match="lvm:map[ @from ]" mode="lvmc:compile" priority="5"> <template match="lvm:map[ @from ]" mode="lvmc:compile" priority="5">
<param name="rater" /> <param name="symtable" as="element( preproc:symtable )" />
<param name="type" /> <param name="type" />
<!-- if src and dest are identical, then it may as well be lvm:pass --> <!-- if src and dest are identical, then it may as well be lvm:pass -->
@ -287,7 +303,7 @@
<value-of select="@to" /> <value-of select="@to" />
<text>']=</text> <text>']=</text>
<call-template name="lvmc:gen-input-default"> <call-template name="lvmc:gen-input-default">
<with-param name="rater" select="$rater" /> <with-param name="symtable" select="$symtable" />
<with-param name="to" select="@to" /> <with-param name="to" select="@to" />
<with-param name="from" select="@from" /> <with-param name="from" select="@from" />
</call-template> </call-template>
@ -395,20 +411,22 @@
if it were, this needs to reference its symbol table. if it were, this needs to reference its symbol table.
--> -->
<template name="lvmc:gen-input-default"> <template name="lvmc:gen-input-default">
<param name="rater" /> <param name="symtable" as="element( preproc:symtable )" />
<param name="to" /> <param name="to" />
<!-- use one or the other; latter takes precedence --> <!-- use one or the other; latter takes precedence -->
<param name="from" /> <param name="from" />
<param name="from-str" /> <param name="from-str" />
<variable name="default"> <variable name="sym" as="element( preproc:sym )?"
<if test="$rater"> select="$symtable/preproc:sym[ @name=$to and @src ]" />
<value-of select="concat( '''',
lvmc:escape-string( <if test="not( $sym ) and not( $symtable/@lvmc:sym-ignore )">
$rater/lv:param[ @name=$to ]/@default ), <message terminate="yes"
'''' )" /> select="concat(
'error: unknown destination identifier `',
string( $to ),
''' (did you import the package?)' )" />
</if> </if>
</variable>
<variable name="from-var"> <variable name="from-var">
<choose> <choose>
@ -425,11 +443,11 @@
</variable> </variable>
<choose> <choose>
<when test="$default and not( $default = '' )"> <when test="$sym and $sym/@default and not( $sym/@default = '' )">
<text>set_defaults(</text> <text>set_defaults(</text>
<value-of select="$from-var" /> <value-of select="$from-var" />
<text>,'</text> <text>,'</text>
<value-of select="$default" /> <value-of select="lvmc:escape-string( $sym/@default )" />
<text>')</text> <text>')</text>
</when> </when>
@ -466,6 +484,7 @@
<template match="lvm:map[*]" mode="lvmc:compile" priority="5"> <template match="lvm:map[*]" mode="lvmc:compile" priority="5">
<param name="symtable" as="element( preproc:symtable )" />
<param name="rater" /> <param name="rater" />
<param name="type" /> <param name="type" />
@ -475,6 +494,7 @@
<text>']=</text> <text>']=</text>
<apply-templates select="./lvm:*" mode="lvmc:compile"> <apply-templates select="./lvm:*" mode="lvmc:compile">
<with-param name="symtable" select="$symtable" />
<with-param name="rater" select="$rater" /> <with-param name="rater" select="$rater" />
</apply-templates> </apply-templates>
@ -588,7 +608,7 @@
<template match="lvm:map//lvm:from[*]" mode="lvmc:compile" priority="5"> <template match="lvm:map//lvm:from[*]" mode="lvmc:compile" priority="5">
<param name="rater" /> <param name="symtable" as="element( preproc:symtable )" />
<variable name="to" select="ancestor::lvm:map/@to" /> <variable name="to" select="ancestor::lvm:map/@to" />
@ -627,7 +647,7 @@
<!-- otherwise, generate one --> <!-- otherwise, generate one -->
<otherwise> <otherwise>
<call-template name="lvmc:gen-input-default"> <call-template name="lvmc:gen-input-default">
<with-param name="rater" select="$rater" /> <with-param name="symtable" select="$symtable" />
<with-param name="to" select="$to" /> <with-param name="to" select="$to" />
<with-param name="from-str"> <with-param name="from-str">
<text>''+val[i]</text> <text>''+val[i]</text>
@ -779,14 +799,17 @@
<!-- import symbols --> <!-- import symbols -->
<template match="lvm:import" mode="preproc:symtable" priority="5"> <template match="lvm:import[ @path ]" mode="preproc:symtable" priority="5">
<!-- original root passed to sym-discover --> <!-- original root passed to sym-discover -->
<param name="orig-root" /> <param name="orig-root" />
<variable name="src" as="xs:string"
select="@path" />
<!-- perform symbol import --> <!-- perform symbol import -->
<call-template name="preproc:symimport"> <call-template name="preproc:symimport">
<with-param name="orig-root" select="$orig-root" /> <with-param name="orig-root" select="$orig-root" />
<with-param name="package" select="@path" /> <with-param name="package" select="$src" />
<with-param name="export" select="'true'" /> <with-param name="export" select="'true'" />
</call-template> </call-template>
</template> </template>

View File

@ -382,10 +382,18 @@
</xs:documentation> </xs:documentation>
</xs:annotation> </xs:annotation>
<xs:attribute name="path" type="xs:string" use="required"> <xs:attribute name="path" type="xs:string">
<xs:annotation> <xs:annotation>
<xs:documentation xml:lang="en"> <xs:documentation xml:lang="en">
Path to source file Path to source map file
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="package" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">
Path to source package
</xs:documentation> </xs:documentation>
</xs:annotation> </xs:annotation>
</xs:attribute> </xs:attribute>
@ -401,6 +409,9 @@
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded"
processContents="lax" />
<xs:element name="import" type="importType" <xs:element name="import" type="importType"
minOccurs="0" maxOccurs="unbounded" /> minOccurs="0" maxOccurs="unbounded" />
<xs:element name="class" type="classDescriptorType" <xs:element name="class" type="classDescriptorType"

View File

@ -52,8 +52,8 @@
<xsl:template match="lvm:program-map|lvm:return-map"> <xsl:template match="lvm:program-map|lvm:return-map">
<!-- output deps, one per line --> <!-- output deps, one per line -->
<xsl:for-each select="lvm:import[ @path ]"> <xsl:for-each select="lvm:import[ @path ]|lv:import[ @package ]">
<xsl:value-of select="concat( @path, $nl )" /> <xsl:value-of select="concat( @path|@package, $nl )" />
</xsl:for-each> </xsl:for-each>
</xsl:template> </xsl:template>