6.4.6.2.6. Identifier Cross references

6.4.6.2.6. Identifier Cross references

This is a bit hacky. When a tangler calls 'set_fc_anchor' with a file name and line number, an anchor with the name
  original_file_name + ':' + str(original_lineno)
is generated. Tanglers which call this function supply the original source file name and line number (not the file and line being written to).

Tanglers generate an entry for the identifier occurence which contains both the original source file and line number, and the output code file and line number.

The cross reference table the html weaver generates displays the output code file and line number (not the orginal file and line number), but it generates a reference of the form

  '#' + original_file_name + ':' + str(original_lineno)
using the original file name and line number.

The stacking weaver must trap calls to 'identifier_reference' because the hyperlinks the child weaver charged with generating this table would fail to refer to the specific html file containing the anchor. Instead, the stacking weaver must build the table.

To do that, the stacking weaver must know in which html child document the reference was generated so it can generate a hyperlink of the form:

  childname + '#' + original_file_name + ':' + str(original_lineno)
Unfortunately, the ids dictionary in the global frame currently being used to hold identifier cross references on a document wide basis, does not have this information available. It wouldn't make sense either, the information in that table is generated by tanglers, and has nothing to do with the weaver.

Therefore, the stacking weaver must _also_ intercept calls to 'set_fc_anchor', and create an entry in a dictionary keyed by the original filename and original line number, which tells in which html file the anchor was set: the stacking weaver knows that!

Start python section to interscript/weavers/web.py[7]
   453: #line 603 "web_weaver.ipk"
   454:   def mk_identref(self,filename,target):
   455:     sink = named_file_sink(
   456:       self.pass_frame,
   457:       self.basedir+filename,
   458:       self.master.weaver_prefix,
   459:       eol=self.eol)
   460:     self.mk_head(sink)
   461:     w = sink.writeline
   462:     w( '<BODY>')
   463: 
   464:     ids = self.master.ids
   465:     if len(ids) == 0:
   466:       ids = self.pass_frame.ids
   467:     w('<H1>Index of Identifiers</H1>')
   468:     self.print_table(ids,sink)
   469: 
   470:     w('</BODY>')
   471:     w('</HTML>')
   472: 
   473:   def mk_sectionref(self,filename,target):
   474:     sink = named_file_sink(
   475:       self.pass_frame,
   476:       self.basedir+filename,
   477:       self.master.weaver_prefix,
   478:       eol=self.eol)
   479:     self.mk_head(sink)
   480:     w = sink.writeline
   481:     w( '<BODY>')
   482: 
   483:     dict = self.pass_frame.section_index
   484:     w('<H1>Index of Sections</H1>')
   485:     keys = dict.keys()
   486:     keys.sort()
   487:     w = sink.writeline
   488:     w('<TABLE COLS="1" BORDER="1" CELLPADDING="2">')
   489:     for k in keys:
   490:       w('<TR><TD VALIGN="Top"><CODE> '+k+' </CODE>: ')
   491:       nsections = len(dict[k])
   492:       for i in range(nsections):
   493:         name = k + '['+str(i+1)+']'
   494:         anchor = '<A HREF='+self.get_anchor(name)+' TARGET="'+target+'">'+str(i+1)+'</A>'
   495:         w(anchor+' ')
   496:       w('</TD></TR>')
   497:     w('</TABLE>')
   498:     w('</BODY>')
   499:     w('</HTML>')
   500: 
   501:   def mk_classref(self,filename,target):
   502:     sink = named_file_sink(
   503:       self.pass_frame,
   504:       self.basedir+filename,
   505:       self.master.weaver_prefix,
   506:       eol=self.eol)
   507:     w = sink.writeline
   508:     self.mk_head(sink)
   509:     w( '<BODY>')
   510: 
   511:     ids = self.master.classes
   512:     if len(ids) == 0:
   513:       ids = self.pass_frame.classes
   514:     w('<H1>Index of Classes</H1>')
   515:     self.print_table(ids,sink)
   516:     w('</BODY>')
   517:     w('</HTML>')
   518: 
   519:   def mk_funcref(self,filename,target):
   520:     sink = named_file_sink(
   521:       self.pass_frame,
   522:       self.basedir+filename,
   523:       self.master.weaver_prefix,
   524:       eol=self.eol)
   525:     w = sink.writeline
   526:     self.mk_head(sink)
   527:     w( '<BODY>')
   528: 
   529:     ids = self.master.functions
   530:     if len(ids) == 0:
   531:       ids = self.pass_frame.functions
   532:     w('<H1>Index of Functions</H1>')
   533:     self.print_table(ids,sink)
   534: 
   535:     w('</BODY>')
   536:     w('</HTML>')
   537: 
   538:   def mk_testref(self,filename,target):
   539:     sink = named_file_sink(
   540:       self.pass_frame,
   541:       self.basedir+filename,
   542:       self.master.weaver_prefix,
   543:       eol=self.eol)
   544:     w = sink.writeline
   545:     self.mk_head(sink)
   546:     w( '<BODY>')
   547: 
   548:     ids = self.master.tests
   549:     if len(ids) == 0:
   550:       ids = self.pass_frame.tests
   551:     w('<H1>Index of Tests</H1>')
   552:     w('<TABLE CLASS="TEST_SUMMARY_TABLE" COLS="4" BORDER="1">')
   553:     w('<TR><TH>No</TH><TH>Description</TH><TH>Kind</TH><TH>Result</TH><TR>')
   554:     keys = ids.keys()
   555:     keys.sort()
   556:     for key in keys:
   557:       descr, label, kind, result = ids[key]
   558:       print 'test entry:',descr,label,kind,result
   559:       href = self.get_anchor(label)
   560:       print 'href=',href
   561:       w('<TR><TD>'+str(key)+'</TD><TD><A TARGET="'+target+'" HREF="'+href+'">'+descr+'</A></TD><TD>'+kind+'</TD><TD>'+result+'</TD></TR>')
   562:     w('</TABLE>')
   563:     w('</BODY>')
   564:     w('</HTML>')
   565: 
   566: 
   567:   def mk_filestatus(self,filename):
   568:     print 'Creating file status file:',filename
   569:     filestatus_output = simple_named_file_sink(
   570:       self.pass_frame,self.basedir+filename, self.master.weaver_prefix,eol='\r\n')
   571:     filestatus_weaver = html_weaver(
   572:       self.pass_frame,
   573:       filestatus_output,title='File Status')
   574:     filestatus_weaver.print_file_status(hlevel=1)
   575: 
   576:   def set_fc_anchor(self,file,count):
   577:     filename = self.base[0].sink.basename
   578:     self.anchor_file[(file,count)]=filename
   579:     for weaver in self.base:
   580:       weaver.set_fc_anchor(file,count)
   581: 
   582:   def heading_reference(self, *args, **kwds): pass # always generated
   583:   def identifier_reference(self, *args, **kwds): pass # always generated
   584:   def class_reference(self, *args, **kwds): pass # always generated
   585:   def function_reference(self, *args, **kwds): pass # always generated
   586:   def test_reference(self, *args, **kwds): pass # always generated
   587: 
   588: 
End python section to interscript/weavers/web.py[7]