Mercurial > projects > dil
comparison trunk/src/dil/semantic/Module.d @ 798:c24be8d4f6ab
Added documentation comments.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 01 Mar 2008 02:53:06 +0100 |
parents | 9f61e8af55d5 |
children |
comparison
equal
deleted
inserted
replaced
797:cf2ad5df025c | 798:c24be8d4f6ab |
---|---|
21 | 21 |
22 /// Represents a semantic D module and a source file. | 22 /// Represents a semantic D module and a source file. |
23 class Module : ScopeSymbol | 23 class Module : ScopeSymbol |
24 { | 24 { |
25 SourceText sourceText; /// The source file of this module. | 25 SourceText sourceText; /// The source file of this module. |
26 string moduleFQN; /// Fully qualified name of the module. E.g. dil.ast.Node | 26 string moduleFQN; /// Fully qualified name of the module. E.g.: dil.ast.Node |
27 string packageName; /// E.g. dil.ast | 27 string packageName; /// E.g.: dil.ast |
28 string moduleName; /// E.g. Node | 28 string moduleName; /// E.g.: Node |
29 | 29 |
30 CompoundDeclaration root; /// The root of the parse tree. | 30 CompoundDeclaration root; /// The root of the parse tree. |
31 ImportDeclaration[] imports; /// ImportDeclarations found in this file. | 31 ImportDeclaration[] imports; /// ImportDeclarations found in this file. |
32 ModuleDeclaration moduleDecl; /// The optional ModuleDeclaration in this file. | 32 ModuleDeclaration moduleDecl; /// The optional ModuleDeclaration in this file. |
33 Parser parser; /// The parser used to parse this file. | 33 Parser parser; /// The parser used to parse this file. |
34 | 34 |
35 Module[] modules; | 35 // Module[] modules; |
36 | 36 |
37 InfoManager infoMan; | 37 InfoManager infoMan; /// Collects error messages. |
38 | 38 |
39 this() | 39 this() |
40 { | 40 { |
41 super(SYM.Module, null, null); | 41 super(SYM.Module, null, null); |
42 } | 42 } |
43 | 43 |
44 /// Constructs a Module object. | |
44 /// Params: | 45 /// Params: |
45 /// filePath = file path to the source text; loaded in the constructor. | 46 /// filePath = file path to the source text; loaded in the constructor. |
46 /// infoMan = used for collecting error messages. | 47 /// infoMan = used for collecting error messages. |
47 this(string filePath, InfoManager infoMan = null) | 48 this(string filePath, InfoManager infoMan = null) |
48 { | 49 { |
50 this.sourceText = new SourceText(filePath); | 51 this.sourceText = new SourceText(filePath); |
51 this.infoMan = infoMan; | 52 this.infoMan = infoMan; |
52 this.sourceText.load(infoMan); | 53 this.sourceText.load(infoMan); |
53 } | 54 } |
54 | 55 |
56 /// Returns the file path of the source text. | |
55 string filePath() | 57 string filePath() |
56 { | 58 { |
57 return sourceText.filePath; | 59 return sourceText.filePath; |
58 } | 60 } |
59 | 61 |
62 /// Returns the file extension: "d" or "di". | |
60 string fileExtension() | 63 string fileExtension() |
61 { | 64 { |
62 foreach_reverse(i, c; filePath) | 65 foreach_reverse(i, c; filePath) |
63 if (c == '.') | 66 if (c == '.') |
64 return filePath[i+1..$]; | 67 return filePath[i+1..$]; |
65 return ""; | 68 return ""; |
66 } | 69 } |
67 | 70 |
71 /// Sets the parser to be used for parsing the source text. | |
68 void setParser(Parser parser) | 72 void setParser(Parser parser) |
69 { | 73 { |
70 this.parser = parser; | 74 this.parser = parser; |
71 } | 75 } |
72 | 76 |
73 /// Starts the parser. | 77 /// Parses the module. |
78 /// Throws: | |
79 /// An Exception if the there's no ModuleDeclaration and | |
80 /// the file name is an invalid or reserved D identifier. | |
74 void parse() | 81 void parse() |
75 { | 82 { |
76 if (this.parser is null) | 83 if (this.parser is null) |
77 this.parser = new Parser(sourceText, infoMan); | 84 this.parser = new Parser(sourceText, infoMan); |
78 | 85 |
93 throw new Exception("'"~str~"' is not a valid module name; it's a reserved or invalid D identifier."); | 100 throw new Exception("'"~str~"' is not a valid module name; it's a reserved or invalid D identifier."); |
94 this.moduleFQN = this.moduleName = str; | 101 this.moduleFQN = this.moduleName = str; |
95 } | 102 } |
96 } | 103 } |
97 | 104 |
105 /// Returns the first token of the module's source text. | |
98 Token* firstToken() | 106 Token* firstToken() |
99 { | 107 { |
100 return parser.lexer.firstToken(); | 108 return parser.lexer.firstToken(); |
101 } | 109 } |
102 | 110 |
104 bool hasErrors() | 112 bool hasErrors() |
105 { | 113 { |
106 return parser.errors.length || parser.lexer.errors.length; | 114 return parser.errors.length || parser.lexer.errors.length; |
107 } | 115 } |
108 | 116 |
117 /// Returns a list of import paths. | |
118 /// E.g.: ["dil/ast/Node", "dil/semantic/Module"] | |
109 string[] getImportPaths() | 119 string[] getImportPaths() |
110 { | 120 { |
111 string[] result; | 121 string[] result; |
112 foreach (import_; imports) | 122 foreach (import_; imports) |
113 result ~= import_.getModuleFQNs(dirSep); | 123 result ~= import_.getModuleFQNs(dirSep); |
119 string getFQN() | 129 string getFQN() |
120 { | 130 { |
121 return moduleFQN; | 131 return moduleFQN; |
122 } | 132 } |
123 | 133 |
134 /// Set's the module's FQN. | |
124 void setFQN(string moduleFQN) | 135 void setFQN(string moduleFQN) |
125 { | 136 { |
126 uint i = moduleFQN.length; | 137 uint i = moduleFQN.length; |
127 if (i != 0) // Don't decrement if string has zero length. | 138 if (i != 0) // Don't decrement if string has zero length. |
128 i--; | 139 i--; |
132 this.moduleFQN = moduleFQN; | 143 this.moduleFQN = moduleFQN; |
133 this.packageName = moduleFQN[0..i]; | 144 this.packageName = moduleFQN[0..i]; |
134 this.moduleName = moduleFQN[(i == 0 ? 0 : i+1) .. $]; | 145 this.moduleName = moduleFQN[(i == 0 ? 0 : i+1) .. $]; |
135 } | 146 } |
136 | 147 |
137 /// Returns e.g. the FQN with slashes instead of dots. | 148 /// Returns the module's FQN with slashes instead of dots. |
138 /// E.g.: dil/ast/Node | 149 /// E.g.: dil/ast/Node |
139 string getFQNPath() | 150 string getFQNPath() |
140 { | 151 { |
141 string FQNPath = moduleFQN.dup; | 152 string FQNPath = moduleFQN.dup; |
142 foreach (i, c; FQNPath) | 153 foreach (i, c; FQNPath) |