1 /**
2 	Sorts packages, modules and definitions in the syntax tree.
3 
4 	Copyright: © 2012 RejectedSoftware e.K.
5 	License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
6 	Authors: Sönke Ludwig
7 */
8 module ddox.processors.sort;
9 
10 import ddox.entities;
11 
12 import std.algorithm;
13 
14 
15 void sortModules(alias pred)(Package root)
16 {
17 	void sortModule(Module mod)
18 	{
19 		sort!pred(mod.members);
20 	}
21 
22 	foreach( p; root.packages ) sortModules!pred(p);
23 	foreach( m; root.modules ) sortModule(m);
24 	sort!pred(root.packages);
25 	sort!pred(root.modules);
26 }
27 
28 void sortDecls(alias pred)(Package root)
29 {
30 	void sortDecl(Declaration decl)
31 	{
32 		if( auto td = cast(TemplateDeclaration)decl ){
33 			foreach (sd; td.members) sortDecl(sd);
34 			sort!pred(td.members);
35 		}
36 		else if( auto ctd = cast(CompositeTypeDeclaration)decl ){
37 			foreach (sd; ctd.members) sortDecl(sd);
38 			sort!pred(ctd.members);
39 		}
40 	}
41 
42 	void sortModule(Module mod)
43 	{
44 		foreach( d; mod.members ) sortDecl(d);
45 	}
46 
47 	foreach( p; root.packages ) sortDecls!pred(p);
48 	foreach( m; root.modules ) sortModule(m);
49 }