Mercurial > projects > dil
comparison src/dil/semantic/Package.d @ 815:615c1386b18d
Added code to class Package.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 12 Mar 2008 19:11:30 +0100 |
parents | bcb74c9b895c |
children | 35d238d502cb |
comparison
equal
deleted
inserted
replaced
814:49e32b5bc161 | 815:615c1386b18d |
---|---|
3 License: GPL3 | 3 License: GPL3 |
4 +/ | 4 +/ |
5 module dil.semantic.Package; | 5 module dil.semantic.Package; |
6 | 6 |
7 import dil.semantic.Symbol; | 7 import dil.semantic.Symbol; |
8 import dil.semantic.Symbols; | |
9 import dil.semantic.Module; | |
10 import dil.lexer.IdTable; | |
11 import common; | |
8 | 12 |
9 class Package : Symbol | 13 /// A package groups modules and other packages. |
14 class Package : ScopeSymbol | |
10 { | 15 { |
16 string pckgName; /// The name of the package. E.g.: 'dil'. | |
17 Package[] packages; /// The sub-packages contained in this package. | |
18 Module[] modules; /// The modules contained in this package. | |
11 | 19 |
20 /// Constructs a Package object. | |
21 this(string pckgName) | |
22 { | |
23 auto ident = IdTable.inStatic(pckgName); | |
24 super(SYM.Package, ident, null); | |
25 this.pckgName = pckgName; | |
26 } | |
27 | |
28 /// Returns true if this is the root package. | |
29 bool isRoot() | |
30 { | |
31 return parent is null; | |
32 } | |
33 | |
34 /// Returns the parent package or null if this is the root. | |
35 Package parentPackage() | |
36 { | |
37 if (isRoot()) | |
38 return null; | |
39 assert(parent.isPackage); | |
40 return parent.to!(Package); | |
41 } | |
42 | |
43 /// Adds a module to this package. | |
44 void add(Module modul) | |
45 { | |
46 modules ~= modul; | |
47 insert(modul, modul.name); | |
48 } | |
49 | |
50 /// Adds a package to this package. | |
51 void add(Package pckg) | |
52 { | |
53 packages ~= pckg; | |
54 insert(pckg, pckg.name); | |
55 } | |
12 } | 56 } |