| 1 |
// Compiler implementation of the D programming language |
|---|
| 2 |
// Copyright (c) 2010 by Digital Mars |
|---|
| 3 |
// All Rights Reserved |
|---|
| 4 |
// written by Walter Bright |
|---|
| 5 |
// http://www.digitalmars.com |
|---|
| 6 |
// License for redistribution is by either the Artistic License |
|---|
| 7 |
// in artistic.txt, or the GNU General Public License in gnu.txt. |
|---|
| 8 |
// See the included readme.txt for details. |
|---|
| 9 |
|
|---|
| 10 |
#include <stdio.h> |
|---|
| 11 |
#include <stdlib.h> |
|---|
| 12 |
#include <ctype.h> |
|---|
| 13 |
#include <assert.h> |
|---|
| 14 |
#include <string.h> |
|---|
| 15 |
|
|---|
| 16 |
#include "mars.h" |
|---|
| 17 |
|
|---|
| 18 |
/****************************************** |
|---|
| 19 |
* Looks for undefined identifier s to see |
|---|
| 20 |
* if it might be undefined because an import |
|---|
| 21 |
* was not specified. |
|---|
| 22 |
* Not meant to be a comprehensive list of names in each module, |
|---|
| 23 |
* just the most common ones. |
|---|
| 24 |
*/ |
|---|
| 25 |
|
|---|
| 26 |
const char *importHint(const char *s) |
|---|
| 27 |
{ |
|---|
| 28 |
#if DMDV1 |
|---|
| 29 |
static const char *modules[] = |
|---|
| 30 |
{ "std.c.stdio", |
|---|
| 31 |
"std.stdio", |
|---|
| 32 |
"std.math", |
|---|
| 33 |
"std.c.stdarg", |
|---|
| 34 |
}; |
|---|
| 35 |
static const char *names[] = |
|---|
| 36 |
{ |
|---|
| 37 |
"printf", NULL, |
|---|
| 38 |
"writefln", NULL, |
|---|
| 39 |
"sin", "cos", "sqrt", "fabs", NULL, |
|---|
| 40 |
"__va_argsave_t", NULL, |
|---|
| 41 |
}; |
|---|
| 42 |
#else |
|---|
| 43 |
static const char *modules[] = |
|---|
| 44 |
{ "core.stdc.stdio", |
|---|
| 45 |
"std.stdio", |
|---|
| 46 |
"std.math", |
|---|
| 47 |
"core.vararg", |
|---|
| 48 |
}; |
|---|
| 49 |
static const char *names[] = |
|---|
| 50 |
{ |
|---|
| 51 |
"printf", NULL, |
|---|
| 52 |
"writeln", NULL, |
|---|
| 53 |
"sin", "cos", "sqrt", "fabs", NULL, |
|---|
| 54 |
"__va_argsave_t", NULL, |
|---|
| 55 |
}; |
|---|
| 56 |
#endif |
|---|
| 57 |
int m = 0; |
|---|
| 58 |
for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) |
|---|
| 59 |
{ |
|---|
| 60 |
const char *p = names[n]; |
|---|
| 61 |
if (p == NULL) |
|---|
| 62 |
{ m++; |
|---|
| 63 |
continue; |
|---|
| 64 |
} |
|---|
| 65 |
assert(m < sizeof(modules)/sizeof(modules[0])); |
|---|
| 66 |
if (strcmp(s, p) == 0) |
|---|
| 67 |
return modules[m]; |
|---|
| 68 |
} |
|---|
| 69 |
return NULL; // didn't find it |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
#if UNITTEST |
|---|
| 73 |
|
|---|
| 74 |
void unittest_importHint() |
|---|
| 75 |
{ |
|---|
| 76 |
const char *p; |
|---|
| 77 |
|
|---|
| 78 |
p = importHint("printf"); |
|---|
| 79 |
assert(p); |
|---|
| 80 |
p = importHint("fabs"); |
|---|
| 81 |
assert(p); |
|---|
| 82 |
p = importHint("xxxxx"); |
|---|
| 83 |
assert(!p); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
#endif |
|---|