Mercurial > projects > dil
comparison src/dil/ModuleManager.d @ 817:e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 12 Mar 2008 23:33:14 +0100 |
parents | 35d238d502cb |
children | 372fa4fbbb1d |
comparison
equal
deleted
inserted
replaced
816:35d238d502cb | 817:e6fb7ed87d3a |
---|---|
53 newModule.parse(); | 53 newModule.parse(); |
54 | 54 |
55 auto moduleFQNPath = newModule.getFQNPath(); | 55 auto moduleFQNPath = newModule.getFQNPath(); |
56 if (auto existingModule = moduleFQNPath in moduleFQNPathTable) | 56 if (auto existingModule = moduleFQNPath in moduleFQNPathTable) |
57 { // Error: two module files have the same f.q. module name. | 57 { // Error: two module files have the same f.q. module name. |
58 auto location = newModule.moduleDecl.begin.getErrorLocation(); | 58 auto location = newModule.getModuleDeclToken().getErrorLocation(); |
59 auto msg = Format(MSG.ConflictingModuleFiles, newModule.filePath()); | 59 auto msg = Format(MSG.ConflictingModuleFiles, newModule.filePath()); |
60 infoMan ~= new SemanticError(location, msg); | 60 infoMan ~= new SemanticError(location, msg); |
61 return *existingModule; | 61 return *existingModule; |
62 } | 62 } |
63 | |
63 // Insert new module. | 64 // Insert new module. |
64 moduleFQNPathTable[moduleFQNPath] = newModule; | 65 moduleFQNPathTable[moduleFQNPath] = newModule; |
65 absFilePathTable[absFilePath] = newModule; | 66 absFilePathTable[absFilePath] = newModule; |
66 loadedModules ~= newModule; | 67 loadedModules ~= newModule; |
67 // Add the module to its package. | 68 // Add the module to its package. |
68 auto pckg = getPackage(newModule.packageName); | 69 auto pckg = getPackage(newModule.packageName); |
69 pckg.add(newModule); | 70 pckg.add(newModule); |
71 | |
72 if (auto p = newModule.getFQN() in packageTable) | |
73 { // Error: module and package share the same name. | |
74 auto location = newModule.getModuleDeclToken().getErrorLocation(); | |
75 auto msg = Format(MSG.ConflictingModuleAndPackage, newModule.getFQN()); | |
76 infoMan ~= new SemanticError(location, msg); | |
77 } | |
78 | |
70 return newModule; | 79 return newModule; |
71 } | 80 } |
72 | 81 |
73 /// Returns the package given a fully package name. | 82 /// Returns the package given a fully package name. |
74 /// Returns the root package for an empty string. | 83 /// Returns the root package for an empty string. |
100 { | 109 { |
101 uint lastDotIndex; | 110 uint lastDotIndex; |
102 foreach_reverse (i, c; pckgFQN) | 111 foreach_reverse (i, c; pckgFQN) |
103 if (c == '.') | 112 if (c == '.') |
104 { lastDotIndex = i; break; } // Found last dot. | 113 { lastDotIndex = i; break; } // Found last dot. |
105 prevFQN = pckgFQN[0..lastDotIndex]; | |
106 if (lastDotIndex == 0) | 114 if (lastDotIndex == 0) |
107 lastName = pckgFQN; // Special case - no dot found. | 115 lastName = pckgFQN; // Special case - no dot found. |
108 else | 116 else |
117 { | |
118 prevFQN = pckgFQN[0..lastDotIndex]; | |
109 lastName = pckgFQN[lastDotIndex+1..$]; | 119 lastName = pckgFQN[lastDotIndex+1..$]; |
120 } | |
110 } | 121 } |
111 | 122 |
112 /// Loads a module given an FQN path. | 123 /// Loads a module given an FQN path. |
113 Module loadModule(string moduleFQNPath) | 124 Module loadModule(string moduleFQNPath) |
114 { | 125 { |
121 if (moduleFilePath.length) | 132 if (moduleFilePath.length) |
122 { // Load the found module file. | 133 { // Load the found module file. |
123 auto modul = loadModuleFile(moduleFilePath); | 134 auto modul = loadModuleFile(moduleFilePath); |
124 if (modul.getFQNPath() != moduleFQNPath) | 135 if (modul.getFQNPath() != moduleFQNPath) |
125 { // Error: the requested module is not in the correct package. | 136 { // Error: the requested module is not in the correct package. |
126 auto location = modul.moduleDecl.begin.getErrorLocation(); | 137 auto location = modul.getModuleDeclToken().getErrorLocation(); |
127 auto msg = Format(MSG.ModuleNotInPackage, getPackageFQN(moduleFQNPath)); | 138 auto msg = Format(MSG.ModuleNotInPackage, getPackageFQN(moduleFQNPath)); |
128 infoMan ~= new SemanticError(location, msg); | 139 infoMan ~= new SemanticError(location, msg); |
129 } | 140 } |
130 return modul; | 141 return modul; |
131 } | 142 } |