Skip to content

Commit

Permalink
Moved version dependency to the right place.
Browse files Browse the repository at this point in the history
depsDebug are currently printed for every occurrence of debug(something)
-> have to find out why.
  • Loading branch information
eskimor committed Jun 4, 2013
1 parent ab3f315 commit 058ab8d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
56 changes: 35 additions & 21 deletions src/cond.c
Expand Up @@ -84,16 +84,39 @@ 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 || !sc || !sc->module)
return;
OutBuffer *ob = global.params.moduleDeps;
Module* md = sc->module;
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 +127,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 +148,7 @@ void VersionCondition::setGlobalLevel(unsigned level)
global.params.versionlevel = level;
}

void VersionCondition::checkPredefined(Loc loc, const char *ident)
bool VersionCondition::isPredefined(const char *ident)
{
static const char* reserved[] =
{
Expand Down Expand Up @@ -211,16 +236,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 All @@ -240,19 +261,6 @@ void VersionCondition::addPredefinedGlobalIdent(const char *ident)
VersionCondition::VersionCondition(Module *mod, unsigned level, Identifier *ident)
: DVCondition(mod, level, ident)
{
if (global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL)
{
OutBuffer *ob = global.params.moduleDeps;
ob->writestring("depsVersion ");
ob->writestring(mod->toPrettyChars());
ob->writestring(" (");
escapePath(ob, mod->srcfile->toChars());
ob->writestring(") : ");
if(ident)
ob->printf("%s\n", ident->toChars());
else
ob->printf("%d\n", level);
}
}

int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
Expand All @@ -262,10 +270,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 @@ -277,6 +289,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
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
3 changes: 1 addition & 2 deletions src/statement.c
Expand Up @@ -2696,10 +2696,10 @@ Statement *ConditionalStatement::syntaxCopy()
return s;
}


Statement *ConditionalStatement::semantic(Scope *sc)
{
//printf("ConditionalStatement::semantic()\n");

// If we can short-circuit evaluate the if statement, don't do the
// semantic analysis of the skipped code.
// This feature allows a limited form of conditional compilation.
Expand Down Expand Up @@ -2728,7 +2728,6 @@ Statement *ConditionalStatement::semantic(Scope *sc)
Statements *ConditionalStatement::flatten(Scope *sc)
{
Statement *s;

//printf("ConditionalStatement::flatten()\n");
if (condition->include(sc, NULL))
{
Expand Down

0 comments on commit 058ab8d

Please sign in to comment.