Skip to content

Commit

Permalink
Backport "Modules can't be marked as deprecated"
Browse files Browse the repository at this point in the history
Original D2 commit : 2af112e
"fix Issue 12567 - Modules can't be marked as deprecated "
  • Loading branch information
Mihails Strasuns committed Sep 11, 2014
1 parent d50d2cb commit 313a89e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/import.c
Expand Up @@ -151,14 +151,27 @@ void Import::importAll(Scope *sc)
if (!mod)
{
load(sc);
mod->importAll(0);

/* Default to private importing
*/
enum PROT prot = sc->protection;
if (!sc->explicitProtection)
prot = PROTprivate;
sc->scopesym->importScope(this, prot);

if (mod)
{
if (mod->md && mod->md->isdeprecated)
{
Expression *msg = mod->md->msg;
if (StringExp *se = msg ? msg->toString() : NULL)
mod->deprecation(loc, "is deprecated - %s", se->string);
else
mod->deprecation(loc, "is deprecated");
}

mod->importAll(0);

/* Default to private importing
*/
enum PROT prot = sc->protection;
if (!sc->explicitProtection)
prot = PROTprivate;
sc->scopesym->importScope(this, prot);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/module.c
Expand Up @@ -36,6 +36,7 @@
#include "dsymbol.h"
#include "hdrgen.h"
#include "lexer.h"
#include "expression.h"

#define MARS 1
#include "html.h"
Expand Down Expand Up @@ -638,6 +639,14 @@ void Module::importAll(Scope *prevsc)
return;
}

if (md && md->msg)
{
if (StringExp *se = md->msg->toString())
md->msg = se;
else
md->msg->error("string expected, not '%s'", md->msg->toChars());
}

/* Note that modules get their own scope, from scratch.
* This is so regardless of where in the syntax a module
* gets imported, it is unaffected by context.
Expand Down Expand Up @@ -1063,6 +1072,8 @@ ModuleDeclaration::ModuleDeclaration(Identifiers *packages, Identifier *id)
{
this->packages = packages;
this->id = id;
this->isdeprecated = false;
this->msg = NULL;
}

char *ModuleDeclaration::toChars()
Expand Down
2 changes: 2 additions & 0 deletions src/module.h
Expand Up @@ -181,6 +181,8 @@ struct ModuleDeclaration
Identifier *id;
Identifiers *packages; // array of Identifier's representing packages
bool safe;
bool isdeprecated; // if it is a deprecated module
Expression *msg;

ModuleDeclaration(Identifiers *packages, Identifier *id);

Expand Down
33 changes: 33 additions & 0 deletions src/parse.c
Expand Up @@ -71,6 +71,26 @@ Dsymbols *Parser::parseModule()
{
Dsymbols *decldefs;

bool isdeprecated = false;
Expression *msg = NULL;

if (token.value == TOKdeprecated)
{
Token *tk;
if (skipParensIf(peek(&token), &tk) && tk->value == TOKmodule)
{
// deprecated (...) module ...
isdeprecated = true;
nextToken();
if (token.value == TOKlparen)
{
check(TOKlparen);
msg = parseAssignExp();
check(TOKrparen);
}
}
}

// ModuleDeclation leads off
if (token.value == TOKmodule)
{
Expand Down Expand Up @@ -101,6 +121,8 @@ Dsymbols *Parser::parseModule()
}

md = new ModuleDeclaration(a, id);
md->isdeprecated = isdeprecated;
md->msg = msg;

check(TOKsemicolon, "module declaration");
addComment(mod, comment);
Expand Down Expand Up @@ -4240,6 +4262,17 @@ int Parser::skipParens(Token *t, Token **pt)
return 0;
}

int Parser::skipParensIf(Token *t, Token **pt)
{
if (t->value != TOKlparen)
{
if (pt)
*pt = t;
return 1;
}
return skipParens(t, pt);
}

/********************************* Expression Parser ***************************/

Expression *Parser::parsePrimaryExp()
Expand Down
1 change: 1 addition & 0 deletions src/parse.h
Expand Up @@ -117,6 +117,7 @@ struct Parser : Lexer
int isExpression(Token **pt);
int isTemplateInstance(Token *t, Token **pt);
int skipParens(Token *t, Token **pt);
int skipParensIf(Token *t, Token **pt);

Expression *parseExpression();
Expression *parsePrimaryExp();
Expand Down

0 comments on commit 313a89e

Please sign in to comment.