Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Formatter/xref.py
1| # $Id: xref.py,v 1.3 2002/10/29 12:53:52 chalky Exp $
2| #
3| # This file is a part of Synopsis.
4| # Copyright (C) 2002 Stephen Davies
5| #
6| # Synopsis is free software; you can redistribute it and/or modify it
7| # under the terms of the GNU General Public License as published by
8| # the Free Software Foundation; either version 2 of the License, or
9| # (at your option) any later version.
10| #
11| # This program is distributed in the hope that it will be useful,
12| # but WITHOUT ANY WARRANTY; without even the implied warranty of
13| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14| # General Public License for more details.
15| #
16| # You should have received a copy of the GNU General Public License
17| # along with this program; if not, write to the Free Software
18| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19| # 02111-1307, USA.
20| #
21| # $Log: xref.py,v $
22| # Revision 1.3 2002/10/29 12:53:52 chalky
23| # More even splitting of pages
24| #
25| # Revision 1.2 2002/10/29 12:43:55 chalky
26| # Added flexible TOC support to link to things other than ScopePages
27| #
28| # Revision 1.1 2002/10/28 17:38:57 chalky
29| # Created module to handle xref data
30| #
31| #
32|
33| import string, cPickle
34|
35| class CrossReferencer:
36| """Handle cross-reference files"""
37| def __init__(self):
38| self.__data = {}
39| self.__index = {}
40| self.__file_map = {}
41| self.__file_info = []
42|
43| def load(self, filename):
44| """Loads data from the given filename"""
45| f = open(filename, 'rb')
46| self.__data, self.__index = cPickle.load(f)
47| f.close()
48| # Split the data into multiple files based on size
49| page = 0
50| count = 0
51| self.__file_info.append([])
52| names = self.__data.keys()
53| names.sort()
54| for name in names:
55| if count > 200:
56| count = 0
57| page = page + 1
58| self.__file_info.append([])
59| self.__file_info[page].append(name)
60| self.__file_map[name] = page
61| target_data = self.__data[name]
62| l0, l1, l2 = len(target_data[0]), len(target_data[1]), len(target_data[2])
63| count = count + 1 + l0 + l1 + l2
64| if l0: count = count + 1
65| if l1: count = count + 1
66| if l2: count = count + 1
67|
68| def get_info(self, name):
69| """Retrieves the info for the give name. The info is returned as a
70| 3-tuple of [list of definitions], [list of calls], [list of
71| other references]. The element of each list is another 3-tuple of
72| (file, line, scope of reference). The last element is the scope in
73| which the reference was made, which is often a function scope, denoted
74| as starting with a backtick, eg: Builder::`add_operation(std::string).
75| Returns None if there is no xref info for the given name.
76| """
77| if not self.__data.has_key(name): return None
78| return self.__data[name]
79|
80| def get_possible_names(self, name):
81| """Returns a list of possible scoped names that end with the given
82| name. These scoped names can be passed to get_info(). Returns None if
83| there is no scoped name ending with the given name."""
84| if not self.__index.has_key(name): return None
85| return self.__index[name]
86|
87| def get_page_for(self, name):
88| """Returns the number of the page that the xref info for the given
89| name is on, or None if not found."""
90| if not self.__file_map.has_key(name): return None
91| return self.__file_map[name]
92|
93| def get_page_info(self):
94| """Returns a list of pages, each consisting of a list of names on that
95| page. This method is intended to be used by whatever generates the
96| files..."""
97| return self.__file_info
98|
99| def get_all_names(self):
100| """Returns a list of all names"""
101| return self.__data.keys()
102|