Skip to content

Commit

Permalink
Merge pull request #4055 from MartinNowak/2.066
Browse files Browse the repository at this point in the history
2.066
  • Loading branch information
DmitryOlshansky committed Oct 11, 2014
2 parents 0588458 + 194b4c2 commit 4539521
Show file tree
Hide file tree
Showing 33 changed files with 178 additions and 572 deletions.
8 changes: 4 additions & 4 deletions src/backend/cgelem.c
Expand Up @@ -2347,13 +2347,13 @@ STATIC elem * eldiv(elem *e, goal_t goal)
* Convert (a op b) op c to a op (b op c).
*/

STATIC elem * swaplog(elem *e)
STATIC elem * swaplog(elem *e, goal_t goal)
{ elem *e1;

e1 = e->E1;
e->E1 = e1->E2;
e1->E2 = e;
return optelem(e1,GOALvalue);
return optelem(e1,goal);
}

STATIC elem * eloror(elem *e, goal_t goal)
Expand Down Expand Up @@ -2386,7 +2386,7 @@ STATIC elem * eloror(elem *e, goal_t goal)
}
if (e1->Eoper == OPoror)
{ /* convert (a||b)||c to a||(b||c). This will find more CSEs. */
return swaplog(e);
return swaplog(e, goal);
}
e2 = elscancommas(e2);
e1 = elscancommas(e1);
Expand Down Expand Up @@ -2723,7 +2723,7 @@ STATIC elem * elandand(elem *e, goal_t goal)
}
if (e1->Eoper == OPandand)
{ /* convert (a&&b)&&c to a&&(b&&c). This will find more CSEs. */
return swaplog(e);
return swaplog(e, goal);
}
e2 = elscancommas(e2);

Expand Down
11 changes: 11 additions & 0 deletions src/hdrgen.c
Expand Up @@ -80,6 +80,17 @@ void toCBuffer(Module *m, OutBuffer *buf, HdrGenState *hgs)
{
if (m->md)
{
if (m->md->isdeprecated)
{
if (m->md->msg)
{
buf->writestring("deprecated(");
toCBuffer(m->md->msg, buf, hgs);
buf->writestring(") ");
}
else
buf->writestring("deprecated ");
}
buf->writestring("module ");
buf->writestring(m->md->toChars());
buf->writeByte(';');
Expand Down
9 changes: 9 additions & 0 deletions src/import.c
Expand Up @@ -190,6 +190,15 @@ void Import::importAll(Scope *sc)
load(sc);
if (mod) // if successfully loaded module
{
if (mod->md && mod->md->isdeprecated)
{
Expression *msg = mod->md->msg;
if (StringExp *se = msg ? msg->toStringExp() : NULL)
mod->deprecation(loc, "is deprecated - %s", se->string);
else
mod->deprecation(loc, "is deprecated");
}

mod->importAll(NULL);

if (!isstatic && !aliasId && !names.dim)
Expand Down
13 changes: 11 additions & 2 deletions src/module.c
Expand Up @@ -22,6 +22,7 @@
#include "import.h"
#include "dsymbol.h"
#include "hdrgen.h"
#include "expression.h"
#include "lexer.h"

#ifdef IN_GCC
Expand Down Expand Up @@ -642,6 +643,14 @@ void Module::importAll(Scope *prevsc)
return;
}

if (md && md->msg)
{
if (StringExp *se = md->msg->toStringExp())
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 @@ -1039,6 +1048,8 @@ ModuleDeclaration::ModuleDeclaration(Loc loc, Identifiers *packages, Identifier
this->packages = packages;
this->id = id;
this->safe = safe;
this->isdeprecated = false;
this->msg = NULL;
}

char *ModuleDeclaration::toChars()
Expand Down Expand Up @@ -1234,5 +1245,3 @@ const char *lookForSourceFile(const char *filename)
}
return NULL;
}


2 changes: 2 additions & 0 deletions src/module.h
Expand Up @@ -187,6 +187,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(Loc loc, Identifiers *packages, Identifier *id, bool safe);

Expand Down
30 changes: 27 additions & 3 deletions src/parse.c
Expand Up @@ -98,6 +98,25 @@ Parser::Parser(Loc loc, Module *module, const utf8_t *base, size_t length, int d
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 All @@ -112,7 +131,8 @@ Dsymbols *Parser::parseModule()
{
nextToken();
if (token.value != TOKidentifier)
{ error("module (system) identifier expected");
{
error("module (system) identifier expected");
goto Lerr;
}
Identifier *id = token.ident;
Expand All @@ -127,7 +147,8 @@ Dsymbols *Parser::parseModule()
#endif

if (token.value != TOKidentifier)
{ error("Identifier expected following module");
{
error("Identifier expected following module");
goto Lerr;
}
else
Expand All @@ -143,13 +164,16 @@ Dsymbols *Parser::parseModule()
a->push(id);
nextToken();
if (token.value != TOKidentifier)
{ error("Identifier expected following package");
{
error("Identifier expected following package");
goto Lerr;
}
id = token.ident;
}

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

if (token.value != TOKsemicolon)
error("';' expected following module declaration instead of %s", token.toChars());
Expand Down
6 changes: 3 additions & 3 deletions test/compilable/extra-files/header-postscript.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

grep -v "D import file generated from" ${RESULTS_DIR}/compilable/header.di > ${RESULTS_DIR}/compilable/header.di.2
diff --strip-trailing-cr compilable/extra-files/header.di ${RESULTS_DIR}/compilable/header.di.2
grep -v "D import file generated from" ${RESULTS_DIR}/compilable/$1.di > ${RESULTS_DIR}/compilable/$1.di.2
diff --strip-trailing-cr compilable/extra-files/$1.di ${RESULTS_DIR}/compilable/$1.di.2
if [ $? -ne 0 ]; then
exit 1;
fi

rm ${RESULTS_DIR}/compilable/header.di{,.2}
rm ${RESULTS_DIR}/compilable/$1.di{,.2}

@@ -1,8 +1,3 @@
// PERMUTE_ARGS: -dw
// REQUIRED_ARGS: -H -Hd${RESULTS_DIR}/compilable
// POST_SCRIPT: compilable/extra-files/header-postscript.sh
// REQUIRED_ARGS: -d

module foo.bar;

import core.vararg;
Expand All @@ -15,7 +10,7 @@ static assert(true, "message");

typedef double mydbl = 10;

int main()
int testmain()
in
{
assert(1+(2+3) == -(1 - 2*3));
Expand Down
Expand Up @@ -5,7 +5,7 @@ pragma (lib, "test");
pragma (msg, "Hello World");
static assert(true, "message");
typedef double mydbl = 10;
int main();
int testmain();
struct S
{
int m;
Expand Down
2 changes: 2 additions & 0 deletions test/compilable/extra-files/header12567a.di
@@ -0,0 +1,2 @@
deprecated module header12567a;
void main();
2 changes: 2 additions & 0 deletions test/compilable/extra-files/header12567b.di
@@ -0,0 +1,2 @@
deprecated("message") module header12567b;
void main();
Expand Up @@ -5,7 +5,7 @@ pragma (lib, "test");
pragma (msg, "Hello World");
static assert(true, "message");
typedef double mydbl = 10;
int main()
int testmain()
in
{
assert(1 + (2 + 3) == -(1 - 2 * 3));
Expand Down
@@ -1,7 +1,3 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -H -Hd${RESULTS_DIR}/compilable
// POST_SCRIPT: compilable/extra-files/xheader-postscript.sh

// for D 2.0 only

class C { }
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions test/compilable/extra-files/inlineheader-postscript.sh

This file was deleted.

10 changes: 0 additions & 10 deletions test/compilable/extra-files/inlinexheader-postscript.sh

This file was deleted.

10 changes: 0 additions & 10 deletions test/compilable/extra-files/xheader-postscript.sh

This file was deleted.

4 changes: 4 additions & 0 deletions test/compilable/imports/a12567.d
@@ -0,0 +1,4 @@
deprecated("This module will be removed in future release.")
module imports.a12567;

void foo() {}

0 comments on commit 4539521

Please sign in to comment.