File: Synopsis/Formatters/HTML/Parts/Inheritance.py
  1#
  2# Copyright (C) 2000 Stephen Davies
  3# Copyright (C) 2000 Stefan Seefeld
  4# All rights reserved.
  5# Licensed to the public under the terms of the GNU LGPL (>= 2),
  6# see the file COPYING for details.
  7#
  8
  9from Synopsis.Processor import Parameter
 10from Synopsis import ASG
 11from Synopsis.Formatters.HTML.Part import Part
 12from Synopsis.Formatters.HTML.Fragments import *
 13from Synopsis.Formatters.HTML.Tags import *
 14
 15def short_name(decl):
 16   return isinstance(decl, ASG.Function) and decl.real_name[-1] or decl.name[-1]
 17
 18
 19class Inheritance(Part):
 20
 21   fragments = Parameter([InheritanceFormatter()],
 22                         '')
 23
 24   def register(self, view):
 25
 26      Part.register(self, view)
 27      self.__start_list = 0
 28
 29   def process(self, decl):
 30      "Walk the hierarchy to find inherited members to print."
 31
 32      if not isinstance(decl, (ASG.Class, ASG.ClassTemplate)): return
 33      self.write_start()
 34      names = [short_name(d) for d in decl.declarations]
 35      self._process_superclasses(decl, names)
 36      self.write_end()
 37
 38   def _process_class(self, class_, names):
 39      "Prints info for the given class, and calls _process_superclasses after"
 40
 41      sorter = self.processor.sorter.clone(class_.declarations)
 42      child_names = []
 43
 44      # Iterate through the sections
 45      for section in sorter:
 46         # Write a heading
 47         heading = section+' Inherited from '+ str(self.scope().prune(class_.name))
 48         started = 0 # Lazy section start incase no details for this section
 49         # Iterate through the children in this section
 50         for child in sorter[section]:
 51            child_name = short_name(child)
 52            if child_name in names:
 53               continue
 54            # FIXME: This doesn't account for the inheritance type
 55            # (private etc)
 56            if child.accessibility == ASG.PRIVATE:
 57               continue
 58            # Don't include constructors and destructors!
 59            if (isinstance(child, ASG.Function) and
 60                child.file.annotations['language'] == 'C++' and
 61                len(child.real_name) > 1):
 62               if child.real_name[-1] == child.real_name[-2]: continue
 63               elif child.real_name[-1] == "~"+child.real_name[-2]: continue
 64            # FIXME: skip overriden declarations
 65            child_names.append(child_name)
 66            # Check section heading
 67            if not started:
 68               started = 1
 69               self.write_section_start(heading)
 70            child.accept(self)
 71         # Finish the section
 72         if started: self.write_section_end(heading)
 73
 74      self._process_superclasses(class_, names + child_names)
 75
 76   def _process_superclasses(self, class_, names):
 77      """Iterates through the superclasses of clas and calls _process_clas for
 78      each"""
 79
 80      for inheritance in class_.parents:
 81         parent = inheritance.parent
 82         if isinstance(parent, ASG.DeclaredTypeId):
 83            parent = parent.declaration
 84            if isinstance(parent, ASG.Class):
 85               self._process_class(parent, names)
 86               continue
 87         #print "Ignoring", parent.__class__.__name__, "parent of", clas.name
 88         pass #ignore
 89
 90   def write_section_start(self, heading):
 91      """Creates a table with one row. The row has a td of class 'heading'
 92      containing the heading string"""
 93
 94      self.write('<table width="100%%" summary="%s">\n'%heading)
 95      self.write('<tr><td colspan="2" class="heading">' + heading + '</td></tr>\n')
 96      self.write('<tr><td class="inherited">')
 97      self.__start_list = 1
 98
 99   def write_section_item(self, text):
100      """Adds a table row"""
101
102      if self.__start_list:
103         self.write(text)
104         self.__start_list = 0
105      else:
106         self.write(',\n'+text)
107
108   def write_section_end(self, heading):
109
110      self.write('</td></tr></table>\n')
111
112
113