annotate src/dil/ModuleManager.d @ 832:80eb3251e010

Updated to Tango 0.99.7.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 25 Jul 2008 15:17:07 +0200
parents 438ed3a72c9d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
832
80eb3251e010 Updated to Tango 0.99.7.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 819
diff changeset
16 import tango.io.model.IFile;
813
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.
817
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
58 auto location = newModule.getModuleDeclToken().getErrorLocation();
813
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 }
817
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
63
812
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
64 // Insert new module.
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
65 moduleFQNPathTable[moduleFQNPath] = newModule;
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
66 absFilePathTable[absFilePath] = newModule;
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
67 loadedModules ~= newModule;
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
68 // 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
69 auto pckg = getPackage(newModule.packageName);
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
70 pckg.add(newModule);
817
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
71
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
72 if (auto p = newModule.getFQN() in packageTable)
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
73 { // Error: module and package share the same name.
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
74 auto location = newModule.getModuleDeclToken().getErrorLocation();
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
75 auto msg = Format(MSG.ConflictingModuleAndPackage, newModule.getFQN());
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
76 infoMan ~= new SemanticError(location, msg);
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
77 }
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
78
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
79 return newModule;
812
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
80 }
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
81
819
438ed3a72c9d Added option -d to the compile command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 818
diff changeset
82 /// Returns the package given a f.q. package name.
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
83 /// 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
84 Package getPackage(string pckgFQN)
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
85 {
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
86 auto pPckg = pckgFQN in packageTable;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
87 if (pPckg)
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
88 return *pPckg;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
89
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
90 string prevFQN, lastPckgName;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
91 // 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
92 splitPackageFQN(pckgFQN, prevFQN, lastPckgName);
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
93 // Recursively build package hierarchy.
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
94 auto parentPckg = getPackage(prevFQN); // E.g.: 'dil'
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
95
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
96 // Create a new package.
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
97 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
98 parentPckg.add(pckg); // 'dil'.add('ast')
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
99
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
100 // 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
101 packageTable[pckgFQN] = pckg;
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
102
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
103 return pckg;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
104 }
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
105
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
106 /// 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
107 /// Params:
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
108 /// 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
109 /// 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
110 /// 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
111 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
112 {
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
113 uint lastDotIndex;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
114 foreach_reverse (i, c; pckgFQN)
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
115 if (c == '.')
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
116 { 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
117 if (lastDotIndex == 0)
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
118 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
119 else
817
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
120 {
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
121 prevFQN = pckgFQN[0..lastDotIndex];
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
122 lastName = pckgFQN[lastDotIndex+1..$];
817
e6fb7ed87d3a Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 816
diff changeset
123 }
816
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
124 }
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
125
812
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
126 /// Loads a module given an FQN path.
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
127 Module loadModule(string moduleFQNPath)
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
128 {
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
129 // 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
130 Module* pModul = moduleFQNPath in moduleFQNPathTable;
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
131 if (pModul)
35d238d502cb The ModuleManager handles packages as well now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 815
diff changeset
132 return *pModul;
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
133
812
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
134 // Locate the module in the file system.
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
135 auto moduleFilePath = findModuleFilePath(moduleFQNPath, importPaths);
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
136 if (!moduleFilePath.length)
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
137 return null;
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
138
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
139 // Load the found module file.
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
140 auto modul = loadModuleFile(moduleFilePath);
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
141 if (modul.getFQNPath() != moduleFQNPath)
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
142 { // Error: the requested module is not in the correct package.
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
143 auto location = modul.getModuleDeclToken().getErrorLocation();
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
144 auto msg = Format(MSG.ModuleNotInPackage, getPackageFQN(moduleFQNPath));
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
145 infoMan ~= new SemanticError(location, msg);
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
146 }
818
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
147
372fa4fbbb1d Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 817
diff changeset
148 return modul;
812
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
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
151 /// 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
152 string getPackageFQN(string moduleFQNPath)
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
153 {
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
154 string pckg = moduleFQNPath.dup;
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
155 uint lastDirSep;
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
156 foreach (i, c; pckg)
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
157 if (c == dirSep)
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
158 (pckg[i] = '.'), (lastDirSep = i);
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
159 return pckg[0..lastDirSep];
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
160 }
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
161
812
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
162 /// 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
163 /// 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
164 static string findModuleFilePath(string moduleFQNPath, string[] importPaths)
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
165 {
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
166 auto filePath = new FilePath();
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
167 foreach (importPath; importPaths)
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
168 {
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
169 filePath.set(importPath); // E.g.: src/
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
170 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
171 foreach (moduleSuffix; [".d", ".di"/*interface file*/])
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
172 {
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
173 filePath.suffix(moduleSuffix);
813
1abffc396594 Revised the ModuleManager class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 812
diff changeset
174 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
175 return filePath.toString();
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
176 }
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
177 }
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
178 return null;
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
179 }
3b567bce56f3 Forgot to really add dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
180 }