Mercurial > projects > dil
annotate src/dil/semantic/Module.d @ 818:372fa4fbbb1d
Added error messages and applied fixes.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Thu, 13 Mar 2008 02:21:26 +0100 |
parents | e6fb7ed87d3a |
children | 80eb3251e010 |
rev | line source |
---|---|
364 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
593
2848ce3becf5
Moved dil.Module to dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
592
diff
changeset
|
5 module dil.semantic.Module; |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
6 |
580
fa6d3c52757d
Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
579
diff
changeset
|
7 import dil.ast.Node; |
585
05c375fb2d5c
Moved dil.Declarations to dil.ast.Declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
8 import dil.ast.Declarations; |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
9 import dil.parser.Parser; |
576
0df647660e76
Moved Lexer.d to new package 'lexer'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
10 import dil.lexer.Lexer; |
815
615c1386b18d
Added code to class Package.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
814
diff
changeset
|
11 import dil.lexer.IdTable; |
589
de365ddcfbd4
Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
585
diff
changeset
|
12 import dil.semantic.Symbol; |
590
641041912670
Moved dil.Symbols to dil.semantic.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
589
diff
changeset
|
13 import dil.semantic.Symbols; |
814
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
14 import dil.Location; |
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
15 import dil.Messages; |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
16 import dil.Information; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
17 import dil.SourceText; |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
18 import common; |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
19 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
20 import tango.io.FilePath; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
21 import tango.io.FileConst; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
22 |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
23 alias FileConst.PathSeparatorChar dirSep; |
364 | 24 |
777
9f61e8af55d5
Added module dil.Compilation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
773
diff
changeset
|
25 /// Represents a semantic D module and a source file. |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
26 class Module : ScopeSymbol |
364 | 27 { |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
28 SourceText sourceText; /// The source file of this module. |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
29 string moduleFQN; /// Fully qualified name of the module. E.g.: dil.ast.Node |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
30 string packageName; /// E.g.: dil.ast |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
31 string moduleName; /// E.g.: Node |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
32 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
33 CompoundDeclaration root; /// The root of the parse tree. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
34 ImportDeclaration[] imports; /// ImportDeclarations found in this file. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
35 ModuleDeclaration moduleDecl; /// The optional ModuleDeclaration in this file. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
36 Parser parser; /// The parser used to parse this file. |
364 | 37 |
810
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
38 /// Indicates which passes have been run on this module. |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
39 /// |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
40 /// 0 = no pass$(BR) |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
41 /// 1 = semantic pass 1$(BR) |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
42 /// 2 = semantic pass 2 |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
43 uint semanticPass; |
525ee3f848d9
Added modules cmd.Compile and dil.ModuleManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
44 Module[] modules; /// The imported modules. |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
45 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
46 InfoManager infoMan; /// Collects error messages. |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
47 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
48 this() |
364 | 49 { |
683
1ae72234db26
Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
50 super(SYM.Module, null, null); |
364 | 51 } |
52 | |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
53 /// Constructs a Module object. |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
54 /// Params: |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
55 /// filePath = file path to the source text; loaded in the constructor. |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
56 /// infoMan = used for collecting error messages. |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
57 this(string filePath, InfoManager infoMan = null) |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
58 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
59 this(); |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
60 this.sourceText = new SourceText(filePath); |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
61 this.infoMan = infoMan; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
62 this.sourceText.load(infoMan); |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
63 } |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
64 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
65 /// Returns the file path of the source text. |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
66 string filePath() |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
67 { |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
68 return sourceText.filePath; |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
69 } |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
70 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
71 /// Returns the file extension: "d" or "di". |
773
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
72 string fileExtension() |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
73 { |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
74 foreach_reverse(i, c; filePath) |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
75 if (c == '.') |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
76 return filePath[i+1..$]; |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
77 return ""; |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
78 } |
6dbbb403fc58
Improved the DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
764
diff
changeset
|
79 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
80 /// Sets the parser to be used for parsing the source text. |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
81 void setParser(Parser parser) |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
82 { |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
83 this.parser = parser; |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
84 } |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
85 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
86 /// Parses the module. |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
87 /// Throws: |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
88 /// An Exception if the there's no ModuleDeclaration and |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
89 /// the file name is an invalid or reserved D identifier. |
364 | 90 void parse() |
91 { | |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
92 if (this.parser is null) |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
93 this.parser = new Parser(sourceText, infoMan); |
364 | 94 |
368 | 95 this.root = parser.start(); |
719
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
96 this.imports = parser.imports; |
364 | 97 |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
98 // Set the fully qualified name of this module. |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
99 if (this.root.children.length) |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
100 { // moduleDecl will be null if first node isn't a ModuleDeclaration. |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
101 this.moduleDecl = this.root.children[0].Is!(ModuleDeclaration); |
719
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
102 if (this.moduleDecl) |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
103 this.setFQN(moduleDecl.getFQN()); // E.g.: dil.ast.Node |
719
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
104 } |
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
105 |
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
106 if (!this.moduleFQN.length) |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
107 { // Take the base name of the file as the module name. |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
108 auto str = (new FilePath(filePath)).name(); // E.g.: Node |
814
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
109 if (!Lexer.isValidUnreservedIdentifier(str)) |
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
110 { |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
111 auto location = this.firstToken().getErrorLocation(); |
814
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
112 auto msg = Format(MSG.InvalidModuleName, str); |
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
113 infoMan ~= new LexerError(location, msg); |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
114 str = IdTable.genModuleID().str; |
814
49e32b5bc161
Added isValidUnreservedIdentifier() to Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
810
diff
changeset
|
115 } |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
116 this.moduleFQN = this.moduleName = str; |
364 | 117 } |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
118 assert(this.moduleFQN.length); |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
817
diff
changeset
|
119 |
815
615c1386b18d
Added code to class Package.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
814
diff
changeset
|
120 // Set the symbol name. |
615c1386b18d
Added code to class Package.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
814
diff
changeset
|
121 this.name = IdTable.lookup(this.moduleName); |
364 | 122 } |
366 | 123 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
124 /// Returns the first token of the module's source text. |
758
f4b9680c0e16
Revised module dil.SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
125 Token* firstToken() |
f4b9680c0e16
Revised module dil.SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
126 { |
f4b9680c0e16
Revised module dil.SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
127 return parser.lexer.firstToken(); |
f4b9680c0e16
Revised module dil.SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
128 } |
f4b9680c0e16
Revised module dil.SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
129 |
817
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
130 /// Returns the begin token of the module declaration |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
131 /// or, if it doesn't exist, the first token in the source text. |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
132 Token* getModuleDeclToken() |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
133 { |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
134 return moduleDecl ? moduleDecl.begin : firstToken(); |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
135 } |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
136 |
563
c838ed7f2ac9
Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
137 /// Returns true if there are errors in the source file. |
515
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
138 bool hasErrors() |
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
139 { |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
593
diff
changeset
|
140 return parser.errors.length || parser.lexer.errors.length; |
515
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
141 } |
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
142 |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
143 /// Returns a list of import paths. |
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
144 /// E.g.: ["dil/ast/Node", "dil/semantic/Module"] |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
145 string[] getImportPaths() |
366 | 146 { |
147 string[] result; | |
148 foreach (import_; imports) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
149 result ~= import_.getModuleFQNs(dirSep); |
366 | 150 return result; |
151 } | |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
152 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
153 /// Returns the fully qualified name of this module. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
154 /// E.g.: dil.ast.Node |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
155 string getFQN() |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
156 { |
370 | 157 return moduleFQN; |
158 } | |
159 | |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
160 /// Set's the module's FQN. |
370 | 161 void setFQN(string moduleFQN) |
162 { | |
163 uint i = moduleFQN.length; | |
164 if (i != 0) // Don't decrement if string has zero length. | |
165 i--; | |
166 // Find last dot. | |
167 for (; i != 0 && moduleFQN[i] != '.'; i--) | |
168 {} | |
169 this.moduleFQN = moduleFQN; | |
817
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
170 if (i == 0) |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
171 this.moduleName = moduleFQN; // No dot found. |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
172 else |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
173 { |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
174 this.packageName = moduleFQN[0..i]; |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
175 this.moduleName = moduleFQN[i+1..$]; |
e6fb7ed87d3a
Added error message MSG.ConflictingModuleAndPackage.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
815
diff
changeset
|
176 } |
370 | 177 } |
178 | |
798
c24be8d4f6ab
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
777
diff
changeset
|
179 /// Returns the module's FQN with slashes instead of dots. |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
180 /// E.g.: dil/ast/Node |
370 | 181 string getFQNPath() |
182 { | |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
183 string FQNPath = moduleFQN.dup; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
184 foreach (i, c; FQNPath) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
185 if (c == '.') |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
186 FQNPath[i] = dirSep; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
187 return FQNPath; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
188 } |
364 | 189 } |