1 /**
2  * Compiler implementation of the
3  * $(LINK2 http://www.dlang.org, D programming language).
4  *
5  * Copyright:   Copyright (c) 1999-2016 by Digital Mars, All Rights Reserved
6  * Authors:     $(LINK2 http://www.digitalmars.com, Walter Bright)
7  * License:     $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source:      $(DMDSRC _imphint.d)
9  */
10 
11 module ddmd.imphint;
12 
13 import core.stdc..string;
14 
15 /******************************************
16  * Looks for undefined identifier s to see
17  * if it might be undefined because an import
18  * was not specified.
19  * Not meant to be a comprehensive list of names in each module,
20  * just the most common ones.
21  */
22 extern (C++) const(char)* importHint(const(char)* s)
23 {
24     static __gshared const(char)** modules = ["core.stdc.stdio", "std.stdio", "std.math", null];
25     static __gshared const(char)** names =
26     [
27         "printf",
28         null,
29         "writeln",
30         null,
31         "sin",
32         "cos",
33         "sqrt",
34         "fabs",
35         null
36     ];
37     int m = 0;
38     for (int n = 0; modules[m]; n++)
39     {
40         const(char)* p = names[n];
41         if (p is null)
42         {
43             m++;
44             continue;
45         }
46         assert(modules[m]);
47         if (strcmp(s, p) == 0)
48             return modules[m];
49     }
50     return null; // didn't find it
51 }
52 
53 unittest
54 {
55     const(char)* p;
56     p = importHint("printf");
57     assert(p);
58     p = importHint("fabs");
59     assert(p);
60     p = importHint("xxxxx");
61     assert(!p);
62 }