# HG changeset patch # User Aziz K?ksal # Date 1205361194 -3600 # Node ID e6fb7ed87d3a49a42b72932f2fadda2ce1faf689 # Parent 35d238d502cb241a16d76236525e870a00cb5d37 Added error message MSG.ConflictingModuleAndPackage. diff -r 35d238d502cb -r e6fb7ed87d3a src/dil/Messages.d --- a/src/dil/Messages.d Wed Mar 12 22:41:45 2008 +0100 +++ b/src/dil/Messages.d Wed Mar 12 23:33:14 2008 +0100 @@ -156,7 +156,8 @@ auto MissingCatchOrFinally = "try statement is missing a catch or finally body."; // Semantic analysis: auto CouldntLoadModule = "couldn't load module '{}'"; - auto ConflictingModuleFiles = "module is in conflict with '{}'"; + auto ConflictingModuleFiles = "module is in conflict with module '{}'"; + auto ConflictingModuleAndPackage = "module is in conflict with package '{}'"; auto ModuleNotInPackage = "expected module to be in package '{}'"; auto UndefinedIdentifier = "undefined identifier '{}'"; auto DeclConflictsWithDecl = "declaration '{}' conflicts with declaration @{}"; diff -r 35d238d502cb -r e6fb7ed87d3a src/dil/ModuleManager.d --- a/src/dil/ModuleManager.d Wed Mar 12 22:41:45 2008 +0100 +++ b/src/dil/ModuleManager.d Wed Mar 12 23:33:14 2008 +0100 @@ -55,11 +55,12 @@ auto moduleFQNPath = newModule.getFQNPath(); if (auto existingModule = moduleFQNPath in moduleFQNPathTable) { // Error: two module files have the same f.q. module name. - auto location = newModule.moduleDecl.begin.getErrorLocation(); + auto location = newModule.getModuleDeclToken().getErrorLocation(); auto msg = Format(MSG.ConflictingModuleFiles, newModule.filePath()); infoMan ~= new SemanticError(location, msg); return *existingModule; } + // Insert new module. moduleFQNPathTable[moduleFQNPath] = newModule; absFilePathTable[absFilePath] = newModule; @@ -67,6 +68,14 @@ // Add the module to its package. auto pckg = getPackage(newModule.packageName); pckg.add(newModule); + + if (auto p = newModule.getFQN() in packageTable) + { // Error: module and package share the same name. + auto location = newModule.getModuleDeclToken().getErrorLocation(); + auto msg = Format(MSG.ConflictingModuleAndPackage, newModule.getFQN()); + infoMan ~= new SemanticError(location, msg); + } + return newModule; } @@ -102,11 +111,13 @@ foreach_reverse (i, c; pckgFQN) if (c == '.') { lastDotIndex = i; break; } // Found last dot. - prevFQN = pckgFQN[0..lastDotIndex]; if (lastDotIndex == 0) lastName = pckgFQN; // Special case - no dot found. else + { + prevFQN = pckgFQN[0..lastDotIndex]; lastName = pckgFQN[lastDotIndex+1..$]; + } } /// Loads a module given an FQN path. @@ -123,7 +134,7 @@ auto modul = loadModuleFile(moduleFilePath); if (modul.getFQNPath() != moduleFQNPath) { // Error: the requested module is not in the correct package. - auto location = modul.moduleDecl.begin.getErrorLocation(); + auto location = modul.getModuleDeclToken().getErrorLocation(); auto msg = Format(MSG.ModuleNotInPackage, getPackageFQN(moduleFQNPath)); infoMan ~= new SemanticError(location, msg); } diff -r 35d238d502cb -r e6fb7ed87d3a src/dil/semantic/Module.d --- a/src/dil/semantic/Module.d Wed Mar 12 22:41:45 2008 +0100 +++ b/src/dil/semantic/Module.d Wed Mar 12 23:33:14 2008 +0100 @@ -124,6 +124,13 @@ return parser.lexer.firstToken(); } + /// Returns the begin token of the module declaration + /// or, if it doesn't exist, the first token in the source text. + Token* getModuleDeclToken() + { + return moduleDecl ? moduleDecl.begin : firstToken(); + } + /// Returns true if there are errors in the source file. bool hasErrors() { @@ -157,8 +164,13 @@ for (; i != 0 && moduleFQN[i] != '.'; i--) {} this.moduleFQN = moduleFQN; - this.packageName = moduleFQN[0..i]; - this.moduleName = moduleFQN[(i == 0 ? 0 : i+1) .. $]; + if (i == 0) + this.moduleName = moduleFQN; // No dot found. + else + { + this.packageName = moduleFQN[0..i]; + this.moduleName = moduleFQN[i+1..$]; + } } /// Returns the module's FQN with slashes instead of dots.