Mercurial > projects > dil
annotate src/dil/ModuleManager.d @ 816:35d238d502cb
The ModuleManager handles packages as well now.
Added options -ps and -pm to command compile.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 12 Mar 2008 22:41:45 +0100 |
parents | 615c1386b18d |
children | e6fb7ed87d3a |
rev | line source |
---|---|
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
1 /++ |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
2 Author: Aziz Köksal |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
3 License: GPL3 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
4 +/ |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
5 module dil.ModuleManager; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
6 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
7 import dil.semantic.Module; |
815
615c1386b18d
Added code to class Package.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
813
diff
changeset
|
8 import dil.semantic.Package; |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
9 import dil.Location; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
10 import dil.Information; |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
11 import dil.Messages; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
12 import common; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
13 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
14 import tango.io.FilePath; |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
15 import tango.io.FileSystem; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
16 import tango.io.FileConst; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
17 |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
18 alias FileConst.PathSeparatorChar dirSep; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
19 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
20 /// Manages loaded modules in a table. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
21 class ModuleManager |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
22 { |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
23 /// The root package. Contains all other modules and packages. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
24 Package rootPackage; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
25 /// Maps full package names to packages. E.g.: dil.ast |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
26 Package[string] packageTable; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
27 /// Maps FQN paths to modules. E.g.: dil/ast/Node |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
28 Module[string] moduleFQNPathTable; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
29 /// Maps absolute file paths to modules. E.g.: /home/user/dil/src/main.d |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
30 Module[string] absFilePathTable; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
31 Module[] loadedModules; /// Loaded modules in sequential order. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
32 string[] importPaths; /// Where to look for module files. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
33 InfoManager infoMan; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
34 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
35 /// Constructs a ModuleManager object. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
36 this(string[] importPaths, InfoManager infoMan) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
37 { |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
38 this.rootPackage = new Package(null); |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
39 packageTable[""] = this.rootPackage; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
40 this.importPaths = importPaths; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
41 this.infoMan = infoMan; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
42 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
43 |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
44 /// Loads a module given a file path. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
45 Module loadModuleFile(string moduleFilePath) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
46 { |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
47 auto absFilePath = FileSystem.toAbsolute(moduleFilePath); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
48 if (auto existingModule = absFilePath in absFilePathTable) |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
49 return *existingModule; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
50 |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
51 // Create a new module. |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
52 auto newModule = new Module(moduleFilePath, infoMan); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
53 newModule.parse(); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
54 |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
55 auto moduleFQNPath = newModule.getFQNPath(); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
56 if (auto existingModule = moduleFQNPath in moduleFQNPathTable) |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
57 { // Error: two module files have the same f.q. module name. |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
58 auto location = newModule.moduleDecl.begin.getErrorLocation(); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
59 auto msg = Format(MSG.ConflictingModuleFiles, newModule.filePath()); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
60 infoMan ~= new SemanticError(location, msg); |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
61 return *existingModule; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
62 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
63 // Insert new module. |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
64 moduleFQNPathTable[moduleFQNPath] = newModule; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
65 absFilePathTable[absFilePath] = newModule; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
66 loadedModules ~= newModule; |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
67 // Add the module to its package. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
68 auto pckg = getPackage(newModule.packageName); |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
69 pckg.add(newModule); |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
70 return newModule; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
71 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
72 |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
73 /// Returns the package given a fully package name. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
74 /// Returns the root package for an empty string. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
75 Package getPackage(string pckgFQN) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
76 { |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
77 auto pPckg = pckgFQN in packageTable; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
78 if (pPckg) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
79 return *pPckg; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
80 |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
81 string prevFQN, lastPckgName; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
82 // E.g.: pckgFQN = 'dil.ast', prevFQN = 'dil', lastPckgName = 'ast' |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
83 splitPackageFQN(pckgFQN, prevFQN, lastPckgName); |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
84 // Recursively build package hierarchy. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
85 auto parentPckg = getPackage(prevFQN); // E.g.: 'dil' |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
86 // Create a new package. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
87 auto pckg = new Package(lastPckgName); // E.g.: 'ast' |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
88 parentPckg.add(pckg); // 'dil'.add('ast') |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
89 // Insert the package into the table. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
90 packageTable[pckgFQN] = pckg; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
91 return pckg; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
92 } |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
93 |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
94 /// Splits e.g. 'dil.ast.xyz' into 'dil.ast' and 'xyz'. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
95 /// Params: |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
96 /// pckgFQN = the full package name to be split. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
97 /// prevFQN = set to 'dil.ast' in the example. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
98 /// lastName = the last package name; set to 'xyz' in the example. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
99 void splitPackageFQN(string pckgFQN, ref string prevFQN, ref string lastName) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
100 { |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
101 uint lastDotIndex; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
102 foreach_reverse (i, c; pckgFQN) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
103 if (c == '.') |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
104 { lastDotIndex = i; break; } // Found last dot. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
105 prevFQN = pckgFQN[0..lastDotIndex]; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
106 if (lastDotIndex == 0) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
107 lastName = pckgFQN; // Special case - no dot found. |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
108 else |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
109 lastName = pckgFQN[lastDotIndex+1..$]; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
110 } |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
111 |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
112 /// Loads a module given an FQN path. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
113 Module loadModule(string moduleFQNPath) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
114 { |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
115 // Look up in table if the module is already loaded. |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
116 Module* pModul = moduleFQNPath in moduleFQNPathTable; |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
117 if (pModul) |
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
118 return *pModul; |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
119 // Locate the module in the file system. |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
120 auto moduleFilePath = findModuleFilePath(moduleFQNPath, importPaths); |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
121 if (moduleFilePath.length) |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
122 { // Load the found module file. |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
123 auto modul = loadModuleFile(moduleFilePath); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
124 if (modul.getFQNPath() != moduleFQNPath) |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
125 { // Error: the requested module is not in the correct package. |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
126 auto location = modul.moduleDecl.begin.getErrorLocation(); |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
127 auto msg = Format(MSG.ModuleNotInPackage, getPackageFQN(moduleFQNPath)); |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
128 infoMan ~= new SemanticError(location, msg); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
129 } |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
130 return modul; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
131 } |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
132 return null; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
133 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
134 |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
135 /// Returns e.g. 'dil.ast' for 'dil/ast/Node'. |
816
35d238d502cb
The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
136 string getPackageFQN(string moduleFQNPath) |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
137 { |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
138 string pckg = moduleFQNPath.dup; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
139 uint lastDirSep; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
140 foreach (i, c; pckg) |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
141 if (c == dirSep) |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
142 (pckg[i] = '.'), (lastDirSep = i); |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
143 return pckg[0..lastDirSep]; |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
144 } |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
145 |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
146 /// Searches for a module in the file system looking in importPaths. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
147 /// Returns: the file path to the module, or null if it wasn't found. |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
148 static string findModuleFilePath(string moduleFQNPath, string[] importPaths) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
149 { |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
150 auto filePath = new FilePath(); |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
151 foreach (importPath; importPaths) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
152 { |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
153 filePath.set(importPath); // E.g.: src/ |
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
154 filePath.append(moduleFQNPath); // E.g.: dil/ast/Node |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
155 foreach (moduleSuffix; [".d", ".di"/*interface file*/]) |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
156 { |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
157 filePath.suffix(moduleSuffix); |
813
1abffc396594
Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
812
diff
changeset
|
158 if (filePath.exists()) // E.g.: src/dil/ast/Node.d |
812
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
159 return filePath.toString(); |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
160 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
161 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
162 return null; |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
163 } |
3b567bce56f3
Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
164 } |