-
-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented feature 767 (ready for review & pull) #1839
Changes from 7 commits
00ed71a
ab3f315
058ab8d
9085036
9ea48b9
f4aa30f
63623af
e025f4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1038,12 +1038,26 @@ void PragmaDeclaration::semantic(Scope *sc) | |
StringExp *se = e->toString(); | ||
if (!se) | ||
error("string expected for library name, not '%s'", e->toChars()); | ||
else if (global.params.verbose) | ||
else | ||
{ | ||
char *name = (char *)mem.malloc(se->len + 1); | ||
memcpy(name, se->string, se->len); | ||
name[se->len] = 0; | ||
printf("library %s\n", name); | ||
if (global.params.verbose) | ||
{ | ||
printf("library %s\n", name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean here :o) |
||
} | ||
if(global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inconsistent spacing, use space between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, no need to be coy about it: |
||
{ | ||
OutBuffer *ob = global.params.moduleDeps; | ||
ob->writestring("depsLib "); | ||
ob->writestring(sc->module->toPrettyChars()); | ||
ob->writestring(" ("); | ||
escapePath(ob, sc->module->srcfile->toChars()); | ||
ob->writestring(") : "); | ||
ob->writestring((char *) name); | ||
ob->writenl(); | ||
} | ||
mem.free(name); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,16 +84,41 @@ DebugCondition::DebugCondition(Module *mod, unsigned level, Identifier *ident) | |
{ | ||
} | ||
|
||
// Helper for printing dependency information | ||
void printDepsConditional(Scope *sc, DVCondition* condition, const char* depType) | ||
{ | ||
if(global.params.moduleDeps == NULL || global.params.moduleDepsFile != NULL) | ||
return; | ||
OutBuffer *ob = global.params.moduleDeps; | ||
Module* md = sc && sc->module ? sc->module : condition->mod; | ||
if(!md) | ||
return; | ||
ob->writestring(depType); | ||
ob->writestring(md->toPrettyChars()); | ||
ob->writestring(" ("); | ||
escapePath(ob, md->srcfile->toChars()); | ||
ob->writestring(") : "); | ||
if(condition->ident) | ||
ob->printf("%s\n", condition->ident->toChars()); | ||
else | ||
ob->printf("%d\n", condition->level); | ||
} | ||
|
||
|
||
int DebugCondition::include(Scope *sc, ScopeDsymbol *s) | ||
{ | ||
//printf("DebugCondition::include() level = %d, debuglevel = %d\n", level, global.params.debuglevel); | ||
if (inc == 0) | ||
{ | ||
inc = 2; | ||
bool definedInModule = false; | ||
if (ident) | ||
{ | ||
if (findCondition(mod->debugids, ident)) | ||
{ | ||
inc = 1; | ||
definedInModule = true; | ||
} | ||
else if (findCondition(global.params.debugids, ident)) | ||
inc = 1; | ||
else | ||
|
@@ -104,6 +129,8 @@ int DebugCondition::include(Scope *sc, ScopeDsymbol *s) | |
} | ||
else if (level <= global.params.debuglevel || level <= mod->debuglevel) | ||
inc = 1; | ||
if(!definedInModule) | ||
printDepsConditional(sc, this, "depsDebug "); | ||
} | ||
return (inc == 1); | ||
} | ||
|
@@ -123,7 +150,7 @@ void VersionCondition::setGlobalLevel(unsigned level) | |
global.params.versionlevel = level; | ||
} | ||
|
||
void VersionCondition::checkPredefined(Loc loc, const char *ident) | ||
bool VersionCondition::isPredefined(const char *ident) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be made const? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is static. |
||
{ | ||
static const char* reserved[] = | ||
{ | ||
|
@@ -211,16 +238,12 @@ void VersionCondition::checkPredefined(Loc loc, const char *ident) | |
for (unsigned i = 0; i < sizeof(reserved) / sizeof(reserved[0]); i++) | ||
{ | ||
if (strcmp(ident, reserved[i]) == 0) | ||
goto Lerror; | ||
return true; | ||
} | ||
|
||
if (ident[0] == 'D' && ident[1] == '_') | ||
goto Lerror; | ||
|
||
return; | ||
|
||
Lerror: | ||
error(loc, "version identifier '%s' is reserved and cannot be set", ident); | ||
return true; | ||
return false; | ||
} | ||
|
||
void VersionCondition::addGlobalIdent(const char *ident) | ||
|
@@ -249,10 +272,14 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s) | |
if (inc == 0) | ||
{ | ||
inc = 2; | ||
bool definedInModule=false; | ||
if (ident) | ||
{ | ||
if (findCondition(mod->versionids, ident)) | ||
{ | ||
inc = 1; | ||
definedInModule = true; | ||
} | ||
else if (findCondition(global.params.versionids, ident)) | ||
inc = 1; | ||
else | ||
|
@@ -264,6 +291,8 @@ int VersionCondition::include(Scope *sc, ScopeDsymbol *s) | |
} | ||
else if (level <= global.params.versionlevel || level <= mod->versionlevel) | ||
inc = 1; | ||
if(!definedInModule && (!ident || (!isPredefined(ident->toChars()) && ident != Lexer::idPool(Token::toChars(TOKunittest)) && ident != Lexer::idPool(Token::toChars(TOKassert))))) | ||
printDepsConditional(sc, this, "depsVersion "); | ||
} | ||
return (inc == 1); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,5 @@ class Import : public Dsymbol | |
Import *isImport() { return this; } | ||
}; | ||
|
||
|
||
#endif /* DMD_IMPORT_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,7 +335,8 @@ Usage:\n\ | |
-debug=ident compile in debug code identified by ident\n\ | ||
-debuglib=name set symbolic debug library to name\n\ | ||
-defaultlib=name set default library to name\n\ | ||
-deps=filename write module dependencies to filename\n%s" | ||
-deps write module import dependencies to stdout. (All dependencies including file/version/debug/lib)\n\ | ||
-deps=filename write module dependencies to filename (only imports - deprecated)\n%s" | ||
" -g add symbolic debug info\n\ | ||
-gc add symbolic debug info, pretend to be C\n\ | ||
-gs always emit stack frame\n\ | ||
|
@@ -882,11 +883,23 @@ Language changes listed by -transition=id:\n\ | |
setdebuglib = 1; | ||
global.params.debuglibname = p + 1 + 9; | ||
} | ||
else if (memcmp(p + 1, "deps=", 5) == 0) | ||
else if (memcmp(p + 1, "deps", 4) == 0) | ||
{ | ||
global.params.moduleDepsFile = p + 1 + 5; | ||
if (!global.params.moduleDepsFile[0]) | ||
goto Lnoarg; | ||
if(global.params.moduleDeps) | ||
{ | ||
error(Loc(), "-deps[=file] can only be provided once!"); | ||
break; | ||
} | ||
if(p[5]=='=') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
global.params.moduleDepsFile = p + 1 + 5; | ||
if (!global.params.moduleDepsFile[0]) | ||
goto Lnoarg; | ||
} // Else output to stdout. | ||
else if(p[5]!='\0') | ||
{ | ||
goto Lerror; | ||
} | ||
global.params.moduleDeps = new OutBuffer; | ||
} | ||
else if (strcmp(p + 1, "main") == 0) | ||
|
@@ -1491,12 +1504,17 @@ Language changes listed by -transition=id:\n\ | |
|
||
if (global.params.moduleDeps != NULL) | ||
{ | ||
assert(global.params.moduleDepsFile != NULL); | ||
|
||
File deps(global.params.moduleDepsFile); | ||
OutBuffer* ob = global.params.moduleDeps; | ||
deps.setbuffer((void*)ob->data, ob->offset); | ||
deps.writev(); | ||
if(global.params.moduleDepsFile != NULL) | ||
{ | ||
File deps(global.params.moduleDepsFile); | ||
deps.setbuffer((void*)ob->data, ob->offset); | ||
deps.writev(); | ||
} | ||
else | ||
{ | ||
printf("%.*s", ob->offset, ob->data); | ||
} | ||
} | ||
|
||
// Scan for functions to inline | ||
|
@@ -1788,6 +1806,27 @@ void getenv_setargv(const char *envvar, size_t *pargc, char** *pargv) | |
*pargv = argv->tdata(); | ||
} | ||
|
||
void escapePath(OutBuffer *buf, const char *fname) | ||
{ | ||
while (1) | ||
{ | ||
switch (*fname) | ||
{ | ||
case 0: | ||
return; | ||
case '(': | ||
case ')': | ||
case '\\': | ||
buf->writebyte('\\'); | ||
default: | ||
buf->writebyte(*fname); | ||
break; | ||
} | ||
fname++; | ||
} | ||
} | ||
|
||
|
||
/*********************************** | ||
* Parse command line arguments for -m32 or -m64 | ||
* to detect the desired architecture. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the extra whitespace?