Next: , Previous: , Up: Top   [Contents][Index]


Appendix C Symbol Table

The symbol table holds declarations for each symbol known to a particular package. Symbol tables are represented by preproc:syms elements.10

A symbol is an abstract representation of some object—a calculation, classification, typedef, etc.—containing the source location and useful metadata.

TODO: Document symbol format and metadata.
Symbols are represented by preproc:sym elements.

function: element( preproc:sym )* symtable:find-duplicates (symtable as element( preproc:syms ))

xmlns:symtable="http://www.lovullo.com/tame/symtable"

Produce a list of duplicate symbols in $symtable, grouped by @name. All duplicates will be returned—that is, if \(S_1\) appears before duplicate \(S_2\) in the symbol table, both \(S_1\) and \(S_2\) will be returned.

If two symbols have duplicate @names but the same @src, then they are not considered to be duplicates, unless another duplicate symbol of the same @name is found with a different @src, in which case all symbols will be returned. An exception to this rule is made when both symbols lack a @src, meaning that they are both defined in the same package. This allows sloppy comparison on concatenated symbol tables before tidying it up.

Externs are ignored, since they represent symbols that need to be satisfied at some point—this will be checked during linking.

Symbols (preproc:sym nodes) are returned by reference.

This method name is “find” duplicates rather than “get” to emphasize that processing is performed, which is potentially intensive given a large symbol table $symtable.

Definition:

<function name="symtable:find-duplicates"  as="element( preproc:sym )*">
  <param name="symtable"  as="element( preproc:syms )" />

  <for-each-group select="$symtable/preproc:sym[ not( @extern = 'true' ) ]"  group-by="@name">
    <!-- @src may be omitted to convey a local symbol -->
    <variable name="srcs"  as="xs:string*"  select="distinct-values( for $sym in current-group() return if ( exists( $sym/@src ) ) then $sym/@src else '.' )" />

    <sequence select="if ( count( $srcs ) gt 1 ) then current-group() else if ( ( $srcs[ 1 ] = '.' ) and ( count( current-group() ) gt 1 ) ) then current-group() else ()" />
  </for-each-group>
</function>

Footnotes

(10)

The preproc namespace exists for legacy reasons; it will change in the future.


Next: , Previous: , Up: Top   [Contents][Index]