-
Notifications
You must be signed in to change notification settings - Fork 3
/
d.d
77 lines (69 loc) · 1.5 KB
/
d.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Written in the D programming language
// Author: Timon Gehr
// License: http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0
import std.stdio, std.algorithm, std.array;
import std.conv : to;
import core.memory;
import core.stdc.stdlib;
import std.path;
import module_, scheduler;
bool isOption(string x){
return x.startsWith("--")||x.startsWith("-I")||x.startsWith("-J");
}
string applyOption(ModuleRepository r,string x)in{assert(isOption(x));}body{
if(x.startsWith("-I")){
r.addPath(x[2..$]);
return null;
}
if(x.startsWith("-J")){
r.addJPath(x[2..$]);
return null;
}
x=x[2..$];
switch(x){ // TODO: report DMD bug/update compiler
case "unittest":
import declaration;
UnittestDecl.enabled = true;
break;
default:
return "unrecognized option '"~x~"'";
}
return null;
}
int main(string[] args){
import core.memory; GC.disable();
if(args.empty){
stderr.writeln("error: clever");
return 1;
}
args.popFront();
bool errors = false;
auto r = new ModuleRepository();
Module[] ms;
foreach(x; args){
if(!isOption(x)) continue;
if(auto err=applyOption(r,x)){
stderr.writeln("error: ",err);
errors=true;
}
}
foreach(x; args){
string err;
if(isOption(x)) continue;
auto m=r.getModule(x,false,err);
if(m){
Scheduler().add(m, null);
ms~=m;
}else{
if(err) stderr.writeln("error: ",err);
errors=true;
}
}
if(!ms.length){
stderr.writeln("error: no input files");
return 1;
}
if(errors) return 1;
Scheduler().run();
return r.hasErrors();
}