Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Linker/LanguageMapper.py
1| # $Id: LanguageMapper.py,v 1.1 2002/08/23 04:37:26 chalky Exp $
2| #
3| # This file is a part of Synopsis.
4| # Copyright (C) 2000, 2001 Stefan Seefeld
5| # Copyright (C) 2000, 2001 Stephen Davies
6| #
7| # Synopsis is free software; you can redistribute it and/or modify it
8| # under the terms of the GNU General Public License as published by
9| # the Free Software Foundation; either version 2 of the License, or
10| # (at your option) any later version.
11| #
12| # This program is distributed in the hope that it will be useful,
13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15| # General Public License for more details.
16| #
17| # You should have received a copy of the GNU General Public License
18| # along with this program; if not, write to the Free Software
19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20| # 02111-1307, USA.
21| #
22| # $Log: LanguageMapper.py,v $
23| # Revision 1.1 2002/08/23 04:37:26 chalky
24| # Huge refactoring of Linker to make it modular, and use a config system similar
25| # to the HTML package
26| #
27|
28| import string
29|
30| from Synopsis.Core import AST, Type, Util
31|
32| from Linker import config, Operation
33|
34| class LanguageMapper(Operation):
35| def execute(self, ast):
36| declarations = ast.declarations()
37| langs = {}
38| for decl in declarations:
39| lang = decl.language()
40| if langs.has_key(lang):
41| scope = langs[lang]
42| else:
43| scope = AST.Module('',-1,lang,'Language',('%s Namespace'%lang,))
44| langs[lang] = scope
45| scope.declarations().append(decl)
46| keys = langs.keys()
47| # TODO: allow user to specify sort order here
48| keys.sort()
49| declarations[:] = map(lambda key, dict=langs: dict[key], keys)
50|
51| linkerOperation = LanguageMapper