comparison trunk/src/main.d @ 520:f203c5248d0b

Added 'compile' command. Fixes in config.d: changed 'auto' to 'var'; fixed format argument indices. dil.Lexer and dil.Parser add their errors to infoMan. Fix in enum TOK: Cent belongs to sublist of integral types.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 15 Dec 2007 22:25:18 +0100
parents 6160ab7b1816
children 50e64bab9c7a
comparison
equal deleted inserted replaced
519:9ebc799c7dc5 520:f203c5248d0b
9 import dil.Token; 9 import dil.Token;
10 import dil.Messages; 10 import dil.Messages;
11 import dil.Settings; 11 import dil.Settings;
12 import dil.SettingsLoader; 12 import dil.SettingsLoader;
13 import dil.CompilerInfo; 13 import dil.CompilerInfo;
14 import dil.Module;
14 import dil.Declarations, dil.Expressions, dil.SyntaxTree; 15 import dil.Declarations, dil.Expressions, dil.SyntaxTree;
16 import dil.Information;
15 import dil.File; 17 import dil.File;
16 import cmd.Generate; 18 import cmd.Generate;
17 import cmd.Statistics; 19 import cmd.Statistics;
18 import cmd.ImportGraph; 20 import cmd.ImportGraph;
19 import common; 21 import common;
31 return Stdout(helpMain()).newline; 33 return Stdout(helpMain()).newline;
32 34
33 string command = args[1]; 35 string command = args[1];
34 switch (command) 36 switch (command)
35 { 37 {
38 case "c", "compile":
39 if (args.length < 2)
40 return printHelp("compile");
41
42 auto infoMan = new InformationManager();
43 auto filePaths = args[2..$];
44 foreach (filePath; filePaths)
45 {
46 auto mod = new Module(filePath, infoMan);
47 mod.parse();
48 }
49
50 foreach (info; infoMan.info)
51 {
52 char[] errorFormat;
53 if (info.classinfo is LexerError.classinfo)
54 errorFormat = GlobalSettings.lexerErrorFormat;
55 else if (info.classinfo is ParserError.classinfo)
56 errorFormat = GlobalSettings.parserErrorFormat;
57 else if (info.classinfo is SemanticError.classinfo)
58 errorFormat = GlobalSettings.semanticErrorFormat;
59 else
60 continue;
61 auto err = cast(Problem)info;
62 Stderr.formatln(errorFormat, err.filePath, err.loc, err.col, err.getMsg);
63 }
64 break;
36 case "gen", "generate": 65 case "gen", "generate":
37 char[] fileName; 66 char[] fileName;
38 DocOption options = DocOption.Tokens; 67 DocOption options = DocOption.Tokens;
39 foreach (arg; args[2..$]) 68 foreach (arg; args[2..$])
40 { 69 {
158 case "parse": 187 case "parse":
159 if (args.length == 3) 188 if (args.length == 3)
160 parse(args[2]); 189 parse(args[2]);
161 break; 190 break;
162 case "?", "help": 191 case "?", "help":
163 if (args.length == 3) 192 printHelp(args.length >= 3 ? args[2] : "");
164 printHelp(args[2]);
165 else
166 Stdout(helpMain());
167 break; 193 break;
168 default: 194 default:
169 } 195 }
170 } 196 }
171 197
172 const char[] COMMANDS = 198 const char[] COMMANDS =
199 " compile (c)\n"
173 " generate (gen)\n" 200 " generate (gen)\n"
174 " help (?)\n" 201 " help (?)\n"
175 " importgraph (igraph)\n" 202 " importgraph (igraph)\n"
176 " statistics (stats)\n" 203 " statistics (stats)\n"
177 " tokenize (tok)\n"; 204 " tokenize (tok)\n";
194 void printHelp(char[] command) 221 void printHelp(char[] command)
195 { 222 {
196 char[] msg; 223 char[] msg;
197 switch (command) 224 switch (command)
198 { 225 {
226 case "c", "compile":
227 msg = "Compile D source files.
228 Usage:
229 dil compile file.d [file2.d, ...] [Options]
230
231 This command only parses the source files and does little semantic analysis.
232 Errors are printed to standard error output.
233
234 Options:
235
236 Example:
237 dil c src/main.d";
238 break;
199 case "gen", "generate": 239 case "gen", "generate":
200 msg = GetMsg(MID.HelpGenerate); 240 msg = GetMsg(MID.HelpGenerate);
201 break; 241 break;
202 case "importgraph", "igraph": 242 case "importgraph", "igraph":
203 msg = GetMsg(MID.HelpImportGraph); 243 msg = GetMsg(MID.HelpImportGraph);