Mercurial > projects > dil
annotate trunk/src/dil/semantic/Module.d @ 683:1ae72234db26
Implemented some methods in SemanticPass1.
Renamed Symbol.ident to name.
Added a constructor to Symbol.
Adapted constructors of classes that inherit from Symbol.
Added Alias and OverloadSet Symbol classes.
Renamed idents and values to names and inits in VariablesDeclaration.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 21 Jan 2008 17:10:12 +0100 |
parents | 6b3e397229c5 |
children | 1564e41f454e |
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; |
579
90d0cff4107e
Moved ImportParser.d to package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
578
diff
changeset
|
10 import dil.parser.ImportParser; |
576
0df647660e76
Moved Lexer.d to new package 'lexer'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
11 import dil.lexer.Lexer; |
364 | 12 import dil.File; |
592
b8dd677e0ace
Moved dil.Scope to dil.semantic.Scope.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
590
diff
changeset
|
13 import dil.semantic.Scope; |
589
de365ddcfbd4
Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
585
diff
changeset
|
14 import dil.semantic.Symbol; |
590
641041912670
Moved dil.Symbols to dil.semantic.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
589
diff
changeset
|
15 import dil.semantic.Symbols; |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
16 import dil.Information; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
17 import tango.io.FilePath; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
18 import tango.io.FileConst; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
19 import common; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
20 |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
21 alias FileConst.PathSeparatorChar dirSep; |
364 | 22 |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
23 class Module : ScopeSymbol |
364 | 24 { |
368 | 25 bool isLightweight; /// If true an ImportParser is used instead of a full Parser. |
370 | 26 string filePath; /// Path to the source file. |
27 string moduleFQN; /// Fully qualified name of the module. | |
364 | 28 string packageName; |
29 string moduleName; | |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
30 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
673
diff
changeset
|
31 CompoundDeclaration root; /// The root of the AST. |
364 | 32 ImportDeclaration[] imports; |
33 ModuleDeclaration moduleDecl; | |
365 | 34 private Parser parser; |
364 | 35 |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
36 Module[] modules; |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
37 |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
520
diff
changeset
|
38 InfoManager infoMan; |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
39 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
40 this(string filePath, bool isLightweight = false) |
364 | 41 { |
683
1ae72234db26
Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
42 super(SYM.Module, null, null); |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
43 |
370 | 44 this.filePath = filePath; |
368 | 45 this.isLightweight = isLightweight; |
364 | 46 } |
47 | |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
520
diff
changeset
|
48 this(string filePath, InfoManager infoMan) |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
49 { |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
50 this(filePath, false); |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
51 this.infoMan = infoMan; |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
52 } |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
53 |
364 | 54 void parse() |
55 { | |
370 | 56 auto sourceText = loadFile(filePath); |
368 | 57 if (this.isLightweight) |
370 | 58 this.parser = new ImportParser(sourceText, filePath); |
368 | 59 else |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
516
diff
changeset
|
60 this.parser = new Parser(sourceText, filePath, infoMan); |
364 | 61 |
368 | 62 this.root = parser.start(); |
364 | 63 |
64 if (root.children.length) | |
65 { | |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
649
diff
changeset
|
66 // moduleDecl will be null if first node isn't a ModuleDeclaration. |
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
649
diff
changeset
|
67 this.moduleDecl = root.children[0].Is!(ModuleDeclaration); |
365 | 68 if (moduleDecl) |
69 { | |
370 | 70 this.setFQN(moduleDecl.getFQN()); |
365 | 71 } |
72 else | |
73 { | |
370 | 74 // Take base name of file path as module name. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
75 auto str = (new FilePath(filePath)).name(); |
510
dd3ce87b3569
Added module dil.Unicode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
503
diff
changeset
|
76 if (!Lexer.isReservedIdentifier(str)) |
370 | 77 { |
78 this.moduleFQN = moduleName = str; | |
79 } | |
80 // else | |
81 // TODO: error: file name has invalid identifier characters. | |
365 | 82 } |
364 | 83 |
84 this.imports = parser.imports; | |
85 } | |
86 } | |
366 | 87 |
563
c838ed7f2ac9
Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
88 /// 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
|
89 bool hasErrors() |
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
90 { |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
593
diff
changeset
|
91 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
|
92 } |
7cb97346bc6f
Using class Module in SettingsLoader.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
510
diff
changeset
|
93 |
366 | 94 string[] getImports() |
95 { | |
96 string[] result; | |
97 foreach (import_; imports) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
98 result ~= import_.getModuleFQNs(dirSep); |
366 | 99 return result; |
100 } | |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
101 |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
102 string getFQN() |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
103 { |
370 | 104 return moduleFQN; |
105 } | |
106 | |
107 void setFQN(string moduleFQN) | |
108 { | |
109 uint i = moduleFQN.length; | |
110 if (i != 0) // Don't decrement if string has zero length. | |
111 i--; | |
112 // Find last dot. | |
113 for (; i != 0 && moduleFQN[i] != '.'; i--) | |
114 {} | |
115 this.moduleFQN = moduleFQN; | |
116 this.packageName = moduleFQN[0..i]; | |
117 this.moduleName = moduleFQN[(i == 0 ? 0 : i+1) .. $]; | |
118 } | |
119 | |
120 string getFQNPath() | |
121 { | |
122 if (packageName.length) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
370
diff
changeset
|
123 return packageName ~ dirSep ~ moduleName; |
370 | 124 else |
125 return moduleName; | |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
126 } |
364 | 127 } |