File: Synopsis/Processors/ModuleSorter.py 1
2
3
4
5
6
7
8from Synopsis.Processor import Processor, Parameter
9from Synopsis import ASG
10
11class ModuleSorter(Processor, ASG.Visitor):
12 """A processor that sorts declarations in a module alphabetically."""
13
14 def process(self, ir, **kwds):
15
16 self.set_parameters(kwds)
17 self.ir = self.merge_input(ir)
18
19 self.__scopestack = []
20 self.__currscope = []
21
22 for decl in self.ir.asg.declarations:
23 decl.accept(self)
24
25 return self.output_and_return_ir()
26
27
28 def visit_meta_module(self, module):
29 """Visits all children of the module, and if there are no declarations
30 after that removes the module"""
31
32 def compare(a, b): return cmp(a.name, b.name)
33 module.declarations.sort(compare)
34
Generated on Thu Apr 16 16:27:16 2009 by
synopsis (version devel)