Skip to content
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

Merged
merged 8 commits into from
Jun 9, 2013
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the extra whitespace?

{
printf("library %s\n", name);
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent spacing, use space between if and ( throughout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, no need to be coy about it: if (global.params.moduleDeps && !global.params.moduleDepsFile)

{
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);
}
}
Expand Down
45 changes: 37 additions & 8 deletions src/cond.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be made const?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is static.

{
static const char* reserved[] =
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/cond.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ class VersionCondition : public DVCondition
{
public:
static void setGlobalLevel(unsigned level);
static void checkPredefined(Loc loc, const char *ident);
static bool isPredefined(const char *ident);
static void checkPredefined(Loc loc, const char *ident)
{
if(isPredefined(ident))
error(loc, "version identifier '%s' is reserved and cannot be set", ident);
}
static void addGlobalIdent(const char *ident);
static void addPredefinedGlobalIdent(const char *ident);

Expand Down
14 changes: 14 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -7072,6 +7072,20 @@ Expression *FileExp::semantic(Scope *sc)

if (global.params.verbose)
printf("file %s\t(%s)\n", (char *)se->string, name);
if (global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL)
{
OutBuffer *ob = global.params.moduleDeps;
ob->writestring("depsFile ");
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
ob->writestring(") : ");
ob->writestring((char *) se->string);
ob->writestring(" (");
escapePath(ob, name);
ob->writestring(")");
ob->writenl();
}

{ File f(name);
if (f.read())
Expand Down
23 changes: 2 additions & 21 deletions src/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,6 @@ void Import::load(Scope *sc)
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}

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++;
}
}

void Import::importAll(Scope *sc)
{
if (!mod)
Expand Down Expand Up @@ -276,7 +256,8 @@ void Import::semantic(Scope *sc)
*/

OutBuffer *ob = global.params.moduleDeps;

if(!global.params.moduleDepsFile)
ob->writestring("depsImport ");
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
Expand Down
1 change: 1 addition & 0 deletions src/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ class Import : public Dsymbol
Import *isImport() { return this; }
};


#endif /* DMD_IMPORT_H */
59 changes: 49 additions & 10 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down Expand Up @@ -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]=='=')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (p[5] == '=')

{
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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,7 @@ void obj_append(Dsymbol *s);
void obj_write_deferred(Library *library);

const char *importHint(const char *s);
/// Little helper function for writting out deps.
void escapePath(OutBuffer *buf, const char *fname);

#endif /* DMD_MARS_H */