blob: f03113dc657a566648193c5894c8c1d5fd4d2684 [file] [log] [blame]
* 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-2022 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2, Walter Bright)
* License: $(LINK2, Boost License 1.0)
* Source: $(LINK2, _imphint.d)
* Documentation:
* Coverage:
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)
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",
assert(importHint("printf") !is null);
assert(importHint("fabs") !is null);
assert(importHint("xxxxx") is null);