1 /**
2  * Copyright: Copyright (c) 2015 Jacob Carlborg. All rights reserved.
3  * Authors: Jacob Carlborg
4  * Version: Initial created: Jan 31, 2015
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6  */
7 module clang.Compiler;
8 
9 import std.path;
10 import std.typetuple : staticMap;
11 
12 import mambo.core._;
13 
14 import clang.c.Index;
15 
16 struct Compiler
17 {
18     private
19     {
20         version (Windows)
21             enum root = `C:\`;
22 
23         else
24             enum root = "/";
25 
26         string virtualPath_;
27 
28         static template toInternalHeader (string file)
29         {
30             enum toInternalHeader = InternalHeader(file, import(file));
31         }
32 
33         static struct InternalHeader
34         {
35             string filename;
36             string content;
37         }
38 
39         enum internalHeaders = [staticMap!(toInternalHeader,
40             "float.h", "stdarg.h", "stddef.h")];
41     }
42 
43     string[] extraIncludePaths ()
44     {
45         return [virtualPath];
46     }
47 
48     CXUnsavedFile[] extraHeaders ()
49     {
50         return internalHeaders.map!((e) {
51             auto path = buildPath(virtualPath, e.filename);
52             return CXUnsavedFile(path.toStringz, e.content.ptr, e.content.length);
53         }).toArray;
54     }
55 
56 private:
57 
58     string virtualPath ()
59     {
60         import std.random;
61 
62         if (virtualPath_.any)
63             return virtualPath_;
64 
65         return virtualPath_ = buildPath(root, uniform(1, 10_000_000).toString);
66     }
67 }