aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/imphint.d
blob: ea2f13d91791a34b03d92df0fe26d84c960e288d (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
 * Give import hints for common symbol names that couldn't be resolved.
 *
 * For example, prompt to `import std.stdio` when using `writeln`.
 *
 * Copyright:   Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
 * Authors:     $(LINK2 https://www.digitalmars.com, Walter Bright)
 * License:     $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
 * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/imphint.d, _imphint.d)
 * Documentation:  https://dlang.org/phobos/dmd_imphint.html
 * Coverage:    https://codecov.io/gh/dlang/dmd/src/master/src/dmd/imphint.d
 */

module dmd.imphint;

/******************************************
 * Looks for undefined identifier s to see
 * if it might be undefined because an import
 * was not specified.
 * Not meant to be a comprehensive list of names in each module,
 * just the most common ones.
 */
const(char)[] importHint(const(char)[] s) @safe
{
    if (auto entry = s in hints)
        return *entry;
    return null;
}

private immutable string[string] hints;

shared static this()
{
    // in alphabetic order
    hints = [
        "AliasSeq": "std.meta",
        "appender": "std.array",
        "array": "std.array",
        "calloc": "core.stdc.stdlib",
        "chdir": "std.file",
        "cos": "std.math",
        "dirEntries": "std.file",
        "drop": "std.range",
        "each": "std.algorithm",
        "empty": "std.range",
        "endsWith": "std.algorithm",
        "enforce": "std.exception",
        "enumerate": "std.range",
        "equal": "std.algorithm",
        "exists": "std.file",
        "fabs": "std.math",
        "filter": "std.algorithm",
        "format": "std.format",
        "free": "core.stdc.stdlib",
        "front": "std.range",
        "iota": "std.range",
        "isDir": "std.file",
        "isFile": "std.file",
        "join": "std.array",
        "joiner": "std.algorithm",
        "malloc": "core.stdc.stdlib",
        "map": "std.algorithm",
        "max": "std.algorithm",
        "min": "std.algorithm",
        "mkdir": "std.file",
        "popFront": "std.range",
        "printf": "core.stdc.stdio",
        "realloc": "core.stdc.stdlib",
        "replace": "std.array",
        "rmdir": "std.file",
        "sin": "std.math",
        "sort": "std.algorithm",
        "split": "std.array",
        "sqrt": "std.math",
        "startsWith": "std.algorithm",
        "take": "std.range",
        "text": "std.conv",
        "to": "std.conv",
        "writefln": "std.stdio",
        "writeln": "std.stdio",
        "__va_argsave_t": "core.stdc.stdarg",
        "__va_list_tag": "core.stdc.stdarg",
    ];
}

unittest
{
    assert(importHint("printf") !is null);
    assert(importHint("fabs") !is null);
    assert(importHint("xxxxx") is null);
}