Mercurial > projects > dil
changeset 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 | 49e32b5bc161 |
children | 35d238d502cb |
files | src/dil/ModuleManager.d src/dil/semantic/Module.d src/dil/semantic/Package.d src/dil/semantic/Symbol.d |
diffstat | 4 files changed, 52 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dil/ModuleManager.d Wed Mar 12 17:01:27 2008 +0100 +++ b/src/dil/ModuleManager.d Wed Mar 12 19:11:30 2008 +0100 @@ -5,6 +5,7 @@ module dil.ModuleManager; import dil.semantic.Module; +import dil.semantic.Package; import dil.Location; import dil.Information; import dil.Messages;
--- a/src/dil/semantic/Module.d Wed Mar 12 17:01:27 2008 +0100 +++ b/src/dil/semantic/Module.d Wed Mar 12 19:11:30 2008 +0100 @@ -8,6 +8,7 @@ import dil.ast.Declarations; import dil.parser.Parser; import dil.lexer.Lexer; +import dil.lexer.IdTable; import dil.semantic.Symbol; import dil.semantic.Symbols; import dil.Location; @@ -109,10 +110,12 @@ auto location = parser.lexer.firstToken().getErrorLocation(); auto msg = Format(MSG.InvalidModuleName, str); infoMan ~= new LexerError(location, msg); - str = "_"; + str = "__module_name"; } this.moduleFQN = this.moduleName = str; } + // Set the symbol name. + this.name = IdTable.lookup(this.moduleName); } /// Returns the first token of the module's source text.
--- a/src/dil/semantic/Package.d Wed Mar 12 17:01:27 2008 +0100 +++ b/src/dil/semantic/Package.d Wed Mar 12 19:11:30 2008 +0100 @@ -5,8 +5,52 @@ module dil.semantic.Package; import dil.semantic.Symbol; +import dil.semantic.Symbols; +import dil.semantic.Module; +import dil.lexer.IdTable; +import common; -class Package : Symbol +/// A package groups modules and other packages. +class Package : ScopeSymbol { + string pckgName; /// The name of the package. E.g.: 'dil'. + Package[] packages; /// The sub-packages contained in this package. + Module[] modules; /// The modules contained in this package. + /// Constructs a Package object. + this(string pckgName) + { + auto ident = IdTable.inStatic(pckgName); + super(SYM.Package, ident, null); + this.pckgName = pckgName; + } + + /// Returns true if this is the root package. + bool isRoot() + { + return parent is null; + } + + /// Returns the parent package or null if this is the root. + Package parentPackage() + { + if (isRoot()) + return null; + assert(parent.isPackage); + return parent.to!(Package); + } + + /// Adds a module to this package. + void add(Module modul) + { + modules ~= modul; + insert(modul, modul.name); + } + + /// Adds a package to this package. + void add(Package pckg) + { + packages ~= pckg; + insert(pckg, pckg.name); + } }
--- a/src/dil/semantic/Symbol.d Wed Mar 12 17:01:27 2008 +0100 +++ b/src/dil/semantic/Symbol.d Wed Mar 12 19:11:30 2008 +0100 @@ -12,6 +12,7 @@ enum SYM { Module, + Package, Class, Interface, Struct, @@ -78,6 +79,7 @@ const char[] isX = `bool is`~kind~`(){ return sid == SYM.`~kind~`; }`; } mixin(isX!("Module")); + mixin(isX!("Package")); mixin(isX!("Class")); mixin(isX!("Interface")); mixin(isX!("Struct"));