# HG changeset patch # User Aziz K?ksal # Date 1205345490 -3600 # Node ID 615c1386b18d534ac15952f720461355931d5663 # Parent 49e32b5bc161ba328780f7613e3a8807707afe70 Added code to class Package. diff -r 49e32b5bc161 -r 615c1386b18d src/dil/ModuleManager.d --- 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; diff -r 49e32b5bc161 -r 615c1386b18d src/dil/semantic/Module.d --- 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. diff -r 49e32b5bc161 -r 615c1386b18d src/dil/semantic/Package.d --- 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); + } } diff -r 49e32b5bc161 -r 615c1386b18d src/dil/semantic/Symbol.d --- 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"));