[Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters ClassTree.py,1.7,1.8 TOC.py,1.4,1.5

Stefan Seefeld stefan at synopsis.fresco.org
Thu Nov 13 17:30:08 UTC 2003


Update of /cvs/synopsis/Synopsis/Synopsis/Formatters
In directory frida:/tmp/cvs-serv30074

Modified Files:
	ClassTree.py TOC.py 
Log Message:
indentation and other cleanup

Index: ClassTree.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Formatters/ClassTree.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -p -d -r1.7 -r1.8
--- ClassTree.py	11 Nov 2003 12:50:56 -0000	1.7
+++ ClassTree.py	13 Nov 2003 17:30:06 -0000	1.8
@@ -1,181 +1,156 @@
 # $Id$
 #
-# This file is a part of Synopsis.
-# Copyright (C) 2000, 2001 Stephen Davies
-# Copyright (C) 2000, 2001 Stefan Seefeld
-#
-# Synopsis is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-#
-# $Log$
-# Revision 1.7  2003/11/11 12:50:56  stefan
-# remove 'Core' module
-#
-# Revision 1.6  2003/02/01 05:38:17  chalky
-# Include Unknown parents in the class tree, so they appear in the inheritance
-# graphs
-#
-# Revision 1.5  2002/09/20 10:37:07  chalky
-# Fix a crash bug
-#
-# Revision 1.4  2002/01/09 11:43:41  chalky
-# Inheritance pics
-#
-# Revision 1.3  2001/07/04 08:18:04  uid20151
-# Comments
-#
-# Revision 1.2  2001/04/06 02:37:08  chalky
-# Add all superclasses to classes list, so that Unknown superclasses are in
-# graphs too (and hence, if they are roots, make sure we dont miss subgraphs!)
-#
-# Revision 1.1  2001/02/05 05:53:04  chalky
-# Moved from HTML/core.py. Added graphs()
-#
+# Copyright (C) 2000 Stefan Seefeld
+# Copyright (C) 2000 Stephen Davies
+# All rights reserved.
+# Licensed to the public under the terms of the GNU LGPL (>= 2),
+# see the file COPYING for details.
 #
 
 """Contains the utility class ClassTree, for creating inheritance trees."""
 
-# Synopsis modules
 from Synopsis import AST, Type
 
 
 def sort(list):
-    "Utility func to sort and return the given list"
-    list.sort()
-    return list
-
+   "Utility func to sort and return the given list"
 
+   list.sort()
+   return list
 
 class ClassTree(AST.Visitor):
-    """Maintains a tree of classes directed by inheritance. This object always
-    exists in HTML, since it is used for other things such as printing class bases."""
-    # TODO - only create if needed (if Info tells us to)
-    def __init__(self):
-	self.__superclasses = {}
-	self.__subclasses = {}
-	self.__classes = []
-	# Graph stuffs:
-	self.__buckets = [] # List of buckets, each a list of classnames
-	self.__processed = {} # Map of processed class names
+   """Maintains a tree of classes directed by inheritance. This object always
+   exists in HTML, since it is used for other things such as printing class bases."""
+   # TODO - only create if needed (if Info tells us to)
+
+   def __init__(self):
+      self.__superclasses = {}
+      self.__subclasses = {}
+      self.__classes = []
+      # Graph stuffs:
+      self.__buckets = [] # List of buckets, each a list of classnames
+      self.__processed = {} # Map of processed class names
     
-    def add_inheritance(self, supername, subname):
-	"""Adds an edge to the graph. Supername and subname are the scoped
-	names of the two classes involved in the edge, and are copied before
-	being stored."""
-	supername, subname = tuple(supername), tuple(subname)
-	self.add_class(supername)
-	if not self.__subclasses.has_key(supername):
-	    subs = self.__subclasses[supername] = []
-	else:
-	    subs = self.__subclasses[supername]
-	if subname not in subs:
-	    subs.append(subname)
-	if not self.__superclasses.has_key(subname):
-	    sups = self.__superclasses[subname] = []
-	else:
-	    sups = self.__superclasses[subname]
-	if supername not in sups:
-	    sups.append(supername)
+   def add_inheritance(self, supername, subname):
+      """Adds an edge to the graph. Supername and subname are the scoped
+      names of the two classes involved in the edge, and are copied before
+      being stored."""
+
+      supername, subname = tuple(supername), tuple(subname)
+      self.add_class(supername)
+      if not self.__subclasses.has_key(supername):
+         subs = self.__subclasses[supername] = []
+      else:
+         subs = self.__subclasses[supername]
+      if subname not in subs:
+         subs.append(subname)
+      if not self.__superclasses.has_key(subname):
+         sups = self.__superclasses[subname] = []
+      else:
+         sups = self.__superclasses[subname]
+      if supername not in sups:
+         sups.append(supername)
     
-    def subclasses(self, classname):
-	"""Returns a sorted list of all classes derived from the given
-	class"""
-	classname = tuple(classname)
-	if self.__subclasses.has_key(classname):
-	    return sort(self.__subclasses[classname])
-	return []
-    def superclasses(self, classname):
-	"""Returns a sorted list of all classes the given class derives
-	from. The classes are returned as scoped names, which you may use to
-	lookup the class declarations in the 'types' dictionary if you need
-	to."""
-	classname = tuple(classname)
-	if self.__superclasses.has_key(classname):
-	    return sort(self.__superclasses[classname])
-	return []
+   def subclasses(self, classname):
+      """Returns a sorted list of all classes derived from the given
+      class"""
+
+      classname = tuple(classname)
+      if self.__subclasses.has_key(classname):
+         return sort(self.__subclasses[classname])
+      return []
+
+   def superclasses(self, classname):
+      """Returns a sorted list of all classes the given class derives
+      from. The classes are returned as scoped names, which you may use to
+      lookup the class declarations in the 'types' dictionary if you need
+      to."""
+
+      classname = tuple(classname)
+      if self.__superclasses.has_key(classname):
+         return sort(self.__superclasses[classname])
+      return []
     
-    def classes(self):
-	"""Returns a sorted list of all class names"""
-	return sort(self.__classes)
-    def add_class(self, name):
-	"""Adds a class to the list of classes by name"""
-	name = tuple(name)
-	if name not in self.__classes:
-	    self.__classes.append(tuple(name))
+   def classes(self):
+      """Returns a sorted list of all class names"""
+
+      return sort(self.__classes)
+
+   def add_class(self, name):
+      """Adds a class to the list of classes by name"""
+
+      name = tuple(name)
+      if name not in self.__classes:
+         self.__classes.append(tuple(name))
     
-    def _is_root(self, name): return not self.__superclasses.has_key(name)
-    def _is_leaf(self, name): return not self.__subclasses.has_key(name)
-    def roots(self):
-	"""Returns a list of classes that have no superclasses"""
-	return filter(self._is_root, self.classes())
+   def _is_root(self, name): return not self.__superclasses.has_key(name)
+   def _is_leaf(self, name): return not self.__subclasses.has_key(name)
+   def roots(self):
+      """Returns a list of classes that have no superclasses"""
 
-    #
-    # Graph methods
-    #
-    def graphs(self):
-	"""Returns a list of graphs. Each graph is just a list of connected
-	classes."""
-	self._make_graphs()
-	return self.__buckets
+      return filter(self._is_root, self.classes())
 
-    def leaves(self, graph):
-	"""Returns a list of leaves in the given graph. A leaf is a class with
-	no subclasses"""
-	return filter(self._is_leaf, graph)
+   #
+   # Graph methods
+   #
+   def graphs(self):
+      """Returns a list of graphs. Each graph is just a list of connected
+      classes."""
 
-    def _make_graphs(self):
-	for root in self.roots():
-	    if self.__processed.has_key(root):
-		# Already processed this class
-		continue
-	    bucket = [] ; self.__buckets.append(bucket)
-	    classes = [root]
-	    while len(classes):
-		name = classes.pop()
-		if self.__processed.has_key(name):
-		    # Already processed this class
-		    continue
-		# Add to bucket
-		bucket.append(name)
-		self.__processed[name] = None
-		# Add super- and sub-classes
-		classes.extend( self.superclasses(name) )
-		classes.extend( self.subclasses(name) )
-    #
-    # AST Visitor
-    #
+      self._make_graphs()
+      return self.__buckets
 
-    def visitAST(self, ast):
-	for decl in ast.declarations():
-	    decl.accept(self)
-    def visitScope(self, scope):
-	for decl in scope.declarations():
-	    decl.accept(self)
-    def visitClass(self, clas):
-	"""Adds this class and all edges to the lists"""
-	name = clas.name()
-	self.add_class(name)
-	for inheritance in clas.parents():
-	    parent = inheritance.parent()
-	    if hasattr(parent, 'declaration'):	
-		self.add_inheritance(parent.declaration().name(), name)
-	    elif isinstance(parent, Type.Parametrized) and parent.template():
-		self.add_inheritance(parent.template().name(), name)
-	    elif isinstance(parent, Type.Unknown):
-		self.add_inheritance(parent.link(), name)
-	for decl in clas.declarations():
-	    decl.accept(self)
+   def leaves(self, graph):
+      """Returns a list of leaves in the given graph. A leaf is a class with
+      no subclasses"""
+
+      return filter(self._is_leaf, graph)
+
+   def _make_graphs(self):
+
+      for root in self.roots():
+         if self.__processed.has_key(root):
+            # Already processed this class
+            continue
+         bucket = [] ; self.__buckets.append(bucket)
+         classes = [root]
+         while len(classes):
+            name = classes.pop()
+            if self.__processed.has_key(name):
+               # Already processed this class
+               continue
+            # Add to bucket
+            bucket.append(name)
+            self.__processed[name] = None
+            # Add super- and sub-classes
+            classes.extend( self.superclasses(name) )
+            classes.extend( self.subclasses(name) )
+   #
+   # AST Visitor
+   #
+
+   def visitAST(self, ast):
+
+      for decl in ast.declarations():
+         decl.accept(self)
+
+   def visitScope(self, scope):
+      for decl in scope.declarations():
+         decl.accept(self)
+
+   def visitClass(self, clas):
+      """Adds this class and all edges to the lists"""
+      name = clas.name()
+      self.add_class(name)
+      for inheritance in clas.parents():
+         parent = inheritance.parent()
+         if hasattr(parent, 'declaration'):	
+            self.add_inheritance(parent.declaration().name(), name)
+         elif isinstance(parent, Type.Parametrized) and parent.template():
+            self.add_inheritance(parent.template().name(), name)
+         elif isinstance(parent, Type.Unknown):
+            self.add_inheritance(parent.link(), name)
+      for decl in clas.declarations():
+         decl.accept(self)
 
 

Index: TOC.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Formatters/TOC.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -p -d -r1.4 -r1.5
--- TOC.py	11 Nov 2003 12:50:56 -0000	1.4
+++ TOC.py	13 Nov 2003 17:30:06 -0000	1.5
@@ -1,137 +1,118 @@
 # $Id$
 #
-# This file is a part of Synopsis.
-# Copyright (C) 2000, 2001 Stephen Davies
-# Copyright (C) 2000, 2001 Stefan Seefeld
-#
-# Synopsis is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-#
-# $Log$
-# Revision 1.4  2003/11/11 12:50:56  stefan
-# remove 'Core' module
-#
-# Revision 1.3  2002/11/01 04:05:06  chalky
-# Don't let comma replacement screw up ampersands
-#
-# Revision 1.2  2001/02/13 05:20:04  chalky
-# Made C++ parser mangle functions by formatting their parameter types
-#
-# Revision 1.1  2001/02/01 18:37:25  chalky
-# moved TOC out to here
-#
+# Copyright (C) 2000 Stefan Seefeld
+# Copyright (C) 2000 Stephen Davies
+# All rights reserved.
+# Licensed to the public under the terms of the GNU LGPL (>= 2),
+# see the file COPYING for details.
 #
 
 """Table of Contents classes"""
 
-import string, re
-
 from Synopsis import AST, Util
 
-# Not sure how this should be set..
-verbose = 0
+import string, re
 
 class Linker:
-    """Abstract class for linking declarations. This class has only one
-    method, link(decl), which returns the link for the given declaration. This
-    is dependant on the type of formatter used, and so a Linker derivative
-    must be passed to the TOC upon creation."""
-    def link(decl): pass
+   """Abstract class for linking declarations. This class has only one
+   method, link(decl), which returns the link for the given declaration. This
+   is dependant on the type of formatter used, and so a Linker derivative
+   must be passed to the TOC upon creation."""
+
+   def link(decl): pass
 
 class TocEntry:
-    """Struct for an entry in the table of contents.
-    Vars: link, lang, type (all strings)
-    Also: name (scoped)"""
-    def __init__(self, name, link, lang, type):
-	self.name = name
-	self.link = link
-	self.lang = lang
-	self.type = type
+   """Struct for an entry in the table of contents.
+   Vars: link, lang, type (all strings)
+   Also: name (scoped)"""
+
+   def __init__(self, name, link, lang, type):
+
+      self.name = name
+      self.link = link
+      self.lang = lang
+      self.type = type
 
 class TableOfContents(AST.Visitor):
-    """
-    Maintains a dictionary of all declarations which can be looked up to create
-    cross references. Names are fully scoped.
-    """
-    def __init__(self, linker):
-	"""linker is an instance that implements the Linker interface and is
-	used to generate the links from declarations."""
-	self.__toc = {}
-	self.linker = linker
+   """
+   Maintains a dictionary of all declarations which can be looked up to create
+   cross references. Names are fully scoped.
+   """
+
+   def __init__(self, linker):
+      """linker is an instance that implements the Linker interface and is
+      used to generate the links from declarations."""
+
+      self.__toc = {}
+      self.linker = linker
     
-    def lookup(self, name):
-	name = tuple(name)
-        if self.__toc.has_key(name): return self.__toc[name]
-	if verbose and len(name) > 1:
-	    print "Warning: TOC lookup of",name,"failed!"
-        return None
+   def lookup(self, name):
 
-    # def referenceName(self, name, scope, label=None, **keys):
-    #     """Same as reference but takes a tuple name"""
-    #     if not label: label = Util.ccolonName(name, scope)
-    #     entry = self[name]
-    #     if entry: return apply(href, (entry.link, label), keys)
-    #     return label or ''
+      name = tuple(name)
+      if self.__toc.has_key(name): return self.__toc[name]
+      if verbose and len(name) > 1:
+         print "Warning: TOC lookup of",name,"failed!"
+      return None
 
+   # def referenceName(self, name, scope, label=None, **keys):
+   #     """Same as reference but takes a tuple name"""
+   #     if not label: label = Util.ccolonName(name, scope)
+   #     entry = self[name]
+   #     if entry: return apply(href, (entry.link, label), keys)
+   #     return label or ''
 
-    def size(self): return len(self.__toc)
+   def size(self): return len(self.__toc)
     
-    __getitem__ = lookup
+   __getitem__ = lookup
     
-    def insert(self, entry): self.__toc[tuple(entry.name)] = entry
+   def insert(self, entry): self.__toc[tuple(entry.name)] = entry
     
-    def store(self, file):
-        """store the table of contents into a file, such that it can be used later when cross referencing"""
-        fout = open(file, 'w')
-	nocomma = lambda str: str.replace("&","&").replace(",","&2c;")
-        for name in self.__toc.keys():
-            scopedname = nocomma(string.join(name, "::"))
-            lang = self.__toc[tuple(name)].lang
-	    link = nocomma(self.__toc[tuple(name)].link)
-            fout.write(scopedname + "," + lang + "," + link + "\n")
-            
-    def load(self, resource):
-        args = string.split(resource, "|")
-        file = args[0]
-        if len(args) > 1: url = args[1]
-        else: url = ""
-        fin = open(file, 'r')
-        line = fin.readline()
-	recomma = lambda str: re.sub("&2c;",",",str)
-        while line:
-            if line[-1] == '\n': line = line[:-1]
-            scopedname, lang, link = string.split(line, ",")
-	    scopedname, link = recomma(scopedname), recomma(link)
-	    param_index = string.find(scopedname, '(')
-	    if param_index >= 0:
-		name = string.split(scopedname[:param_index], "::")
-		name = name[:-1] + [name[-1]+scopedname[param_index:]]
-	    else:
-		name = string.split(scopedname, "::")
-            if len(url): link = string.join([url, link], "/")
-            entry = TocEntry(name, link, lang, "decl")
-            self.insert(entry)
-            line = fin.readline()
+   def store(self, file):
+      """store the table of contents into a file, such that it can be used later when cross referencing"""
+
+      fout = open(file, 'w')
+      nocomma = lambda str: str.replace("&","&").replace(",","&2c;")
+      for name in self.__toc.keys():
+         scopedname = nocomma(string.join(name, "::"))
+         lang = self.__toc[tuple(name)].lang
+         link = nocomma(self.__toc[tuple(name)].link)
+         fout.write(scopedname + "," + lang + "," + link + "\n")
+
+   def load(self, resource):
+
+      args = string.split(resource, "|")
+      file = args[0]
+      if len(args) > 1: url = args[1]
+      else: url = ""
+      fin = open(file, 'r')
+      line = fin.readline()
+      recomma = lambda str: re.sub("&2c;",",",str)
+      while line:
+         if line[-1] == '\n': line = line[:-1]
+         scopedname, lang, link = string.split(line, ",")
+         scopedname, link = recomma(scopedname), recomma(link)
+         param_index = string.find(scopedname, '(')
+         if param_index >= 0:
+            name = string.split(scopedname[:param_index], "::")
+            name = name[:-1] + [name[-1]+scopedname[param_index:]]
+         else:
+            name = string.split(scopedname, "::")
+         if len(url): link = string.join([url, link], "/")
+         entry = TocEntry(name, link, lang, "decl")
+         self.insert(entry)
+         line = fin.readline()
     
-    def visitAST(self, ast):
-	for decl in ast.declarations():
-	    decl.accept(self)
-    def visitDeclaration(self, decl):
-	entry = TocEntry(decl.name(), self.linker.link(decl), decl.language(), "decl")
-	self.insert(entry)
-    def visitForward(self, decl):
-	pass
+   def visitAST(self, ast):
+
+      for decl in ast.declarations():
+         decl.accept(self)
+
+   def visitDeclaration(self, decl):
+
+      entry = TocEntry(decl.name(), self.linker.link(decl), decl.language(), "decl")
+      self.insert(entry)
+
+   def visitForward(self, decl):
+      pass
 
 





More information about the Synopsis-changes mailing list