Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 7, 2012
2 parents bc34439 + 02a5dca commit d1f5765
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 136 deletions.
45 changes: 28 additions & 17 deletions src/dsymbol.c
Expand Up @@ -216,18 +216,21 @@ const char *Dsymbol::toPrettyChars()
return s;
}

char *Dsymbol::locToChars()
Loc& Dsymbol::getLoc()
{
OutBuffer buf;

if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();

if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
return loc.toChars();
return loc;
}

char *Dsymbol::locToChars()
{
return getLoc().toChars();
}

const char *Dsymbol::kind()
Expand Down Expand Up @@ -598,25 +601,33 @@ int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)

void Dsymbol::error(const char *format, ...)
{
//printf("Dsymbol::error()\n");
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();

if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
va_list ap;
va_start(ap, format);
verror(loc, format, ap, kind(), toPrettyChars());
::verror(getLoc(), format, ap, kind(), toPrettyChars());
va_end(ap);
}

void Dsymbol::error(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verror(loc, format, ap, kind(), toPrettyChars());
::verror(loc, format, ap, kind(), toPrettyChars());
va_end(ap);
}

void Dsymbol::deprecation(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
::vdeprecation(loc, format, ap, kind(), toPrettyChars());
va_end(ap);
}

void Dsymbol::deprecation(const char *format, ...)
{
va_list ap;
va_start(ap, format);
::vdeprecation(getLoc(), format, ap, kind(), toPrettyChars());
va_end(ap);
}

Expand All @@ -640,7 +651,7 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
goto L1;
}

error(loc, "is deprecated");
deprecation(loc, "is deprecated");
}

L1:
Expand Down Expand Up @@ -1240,8 +1251,8 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
{ VarDeclaration **pvar;
Expression *ce;

if (ident == Id::length && !global.params.useDeprecated)
error("using 'length' inside [ ] is deprecated, use '$' instead");
if (ident == Id::length)
deprecation("using 'length' inside [ ] is deprecated, use '$' instead");

L1:

Expand Down
3 changes: 3 additions & 0 deletions src/dsymbol.h
Expand Up @@ -126,11 +126,14 @@ struct Dsymbol : Object
Dsymbol();
Dsymbol(Identifier *);
char *toChars();
Loc& getLoc();
char *locToChars();
int equals(Object *o);
int isAnonymous();
void error(Loc loc, const char *format, ...);
void error(const char *format, ...);
void deprecation(Loc loc, const char *format, ...);
void deprecation(const char *format, ...);
void checkDeprecated(Loc loc, Scope *sc);
Module *getModule();
Module *getAccessModule();
Expand Down
25 changes: 16 additions & 9 deletions src/expression.c
Expand Up @@ -1467,6 +1467,17 @@ void Expression::warning(const char *format, ...)
}
}

void Expression::deprecation(const char *format, ...)
{
if (type != Type::terror)
{
va_list ap;
va_start(ap, format);
::vdeprecation(loc, format, ap);
va_end( ap );
}
}

int Expression::rvalue()
{
if (type && type->toBasetype()->ty == Tvoid)
Expand Down Expand Up @@ -2225,7 +2236,7 @@ void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)

case Tuns32:
L3:
buf->printf("%du", (unsigned)v);
buf->printf("%uu", (unsigned)v);
break;

case Tint64:
Expand Down Expand Up @@ -5459,7 +5470,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
(s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
s != s2)
{
error("shadowing declaration %s is deprecated", s->toPrettyChars());
error("shadowing declaration %s is not allowed", s->toPrettyChars());
return new ErrorExp();
}
}
Expand Down Expand Up @@ -5743,8 +5754,7 @@ Expression *IsExp::semantic(Scope *sc)
break;

case TOKinvariant:
if (!global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
deprecation("use of 'invariant' rather than 'immutable' is deprecated");
case TOKimmutable:
if (!targ->isImmutable())
goto Lno;
Expand Down Expand Up @@ -8635,8 +8645,7 @@ Expression *PtrExp::semantic(Scope *sc)

case Tsarray:
case Tarray:
if (!global.params.useDeprecated)
error("using * on an array is deprecated; use *(%s).ptr instead", e1->toChars());
deprecation("using * on an array is deprecated; use *(%s).ptr instead", e1->toChars());
type = ((TypeArray *)tb)->next;
e1 = e1->castTo(sc, type->pointerTo());
break;
Expand Down Expand Up @@ -8926,9 +8935,7 @@ Expression *DeleteExp::semantic(Scope *sc)
IndexExp *ae = (IndexExp *)(e1);
Type *tb1 = ae->e1->type->toBasetype();
if (tb1->ty == Taarray)
{ if (!global.params.useDeprecated)
error("delete aa[key] deprecated, use aa.remove(key)");
}
deprecation("delete aa[key] deprecated, use aa.remove(key)");
}

return this;
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Expand Up @@ -118,6 +118,7 @@ struct Expression : Object
virtual void dump(int indent);
void error(const char *format, ...);
void warning(const char *format, ...);
void deprecation(const char *format, ...);
virtual int rvalue();

static Expression *combine(Expression *e1, Expression *e2);
Expand Down
3 changes: 1 addition & 2 deletions src/iasm.c
Expand Up @@ -4236,8 +4236,7 @@ STATIC OPND *asm_una_exp()
// Check for offset keyword
if (asmtok->ident == Id::offset)
{
if (!global.params.useDeprecated)
error(asmstate.loc, "offset deprecated, use offsetof");
deprecation(asmstate.loc, "offset deprecated, use offsetof");
goto Loffset;
}
if (asmtok->ident == Id::offsetof)
Expand Down
25 changes: 15 additions & 10 deletions src/lexer.c
Expand Up @@ -315,6 +315,14 @@ void Lexer::error(Loc loc, const char *format, ...)
va_end(ap);
}

void Lexer::deprecation(const char *format, ...)
{
va_list ap;
va_start(ap, format);
::vdeprecation(tokenLoc(), format, ap);
va_end(ap);
}

TOK Lexer::nextToken()
{ Token *t;

Expand Down Expand Up @@ -570,8 +578,7 @@ void Lexer::scan(Token *t)
t->postfix = 0;
t->value = TOKstring;
#if DMDV2
if (!global.params.useDeprecated)
error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
deprecation("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
#endif
return;
}
Expand Down Expand Up @@ -2141,8 +2148,7 @@ TOK Lexer::number(Token *t)
goto L1;

case 'l':
if (1 || !global.params.useDeprecated)
error("'l' suffix is deprecated, use 'L' instead");
error("'l' is not a valid suffix, did you mean 'L'?");
case 'L':
f = FLAGS_long;
L1:
Expand All @@ -2158,8 +2164,8 @@ TOK Lexer::number(Token *t)
}

#if DMDV2
if (state == STATE_octal && n >= 8 && !global.params.useDeprecated)
error("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
if (state == STATE_octal && n >= 8)
deprecation("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
n, p - psuffix, psuffix, n, p - psuffix, psuffix);
#endif

Expand Down Expand Up @@ -2393,17 +2399,16 @@ __body
break;

case 'l':
if (!global.params.useDeprecated)
error("'l' suffix is deprecated, use 'L' instead");
deprecation("'l' suffix is deprecated, use 'L' instead");
case 'L':
result = TOKfloat80v;
p++;
break;
}
if (*p == 'i' || *p == 'I')
{
if (!global.params.useDeprecated && *p == 'I')
error("'I' suffix is deprecated, use 'i' instead");
if (*p == 'I')
deprecation("'I' suffix is deprecated, use 'i' instead");
p++;
switch (result)
{
Expand Down
1 change: 1 addition & 0 deletions src/lexer.h
Expand Up @@ -307,6 +307,7 @@ struct Lexer
TOK inreal(Token *t);
void error(const char *format, ...);
void error(Loc loc, const char *format, ...);
void deprecation(const char *format, ...);
void poundLine();
unsigned decodeUTF();
void getDocComment(Token *t, unsigned lineComment);
Expand Down
99 changes: 48 additions & 51 deletions src/mars.c
Expand Up @@ -192,33 +192,51 @@ void errorSupplemental(Loc loc, const char *format, ...)
va_end( ap );
}

void verror(Loc loc, const char *format, va_list ap, const char *p1, const char *p2)
void deprecation(Loc loc, const char *format, ...)
{
if (!global.gag)
{
char *p = loc.toChars();
va_list ap;
va_start(ap, format);
vdeprecation(loc, format, ap);

va_end( ap );
}

if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
// Just print, doesn't care about gagging
void verrorPrint(Loc loc, const char *header, const char *format, va_list ap,
const char *p1, const char *p2)
{
char *p = loc.toChars();

if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);

fprintf(stdmsg, "Error: ");
if (p1)
fprintf(stdmsg, "%s ", p1);
if (p2)
fprintf(stdmsg, "%s ", p2);
fputs(header, stdmsg);
if (p1)
fprintf(stdmsg, "%s ", p1);
if (p2)
fprintf(stdmsg, "%s ", p2);
#if _MSC_VER
// MS doesn't recognize %zu format
OutBuffer tmp;
tmp.vprintf(format, ap);
fprintf(stdmsg, "%s", tmp.toChars());
// MS doesn't recognize %zu format
OutBuffer tmp;
tmp.vprintf(format, ap);
fprintf(stdmsg, "%s", tmp.toChars());
#else
vfprintf(stdmsg, format, ap);
vfprintf(stdmsg, format, ap);
#endif
fprintf(stdmsg, "\n");
fflush(stdmsg);
if (global.errors >= 20) // moderate blizzard of cascading messages
fatal();
fprintf(stdmsg, "\n");
fflush(stdmsg);
}

// header is "Error: " by default (see mars.h)
void verror(Loc loc, const char *format, va_list ap,
const char *p1, const char *p2, const char *header)
{
if (!global.gag)
{
verrorPrint(loc, header, format, ap, p1, p2);
if (global.errors >= 20) // moderate blizzard of cascading messages
fatal();
//halt();
}
else
Expand All @@ -232,48 +250,27 @@ void verror(Loc loc, const char *format, va_list ap, const char *p1, const char
void verrorSupplemental(Loc loc, const char *format, va_list ap)
{
if (!global.gag)
{
fprintf(stdmsg, "%s: ", loc.toChars());
#if _MSC_VER
// MS doesn't recognize %zu format
OutBuffer tmp;
tmp.vprintf(format, ap);
fprintf(stdmsg, "%s", tmp.toChars());
#else
vfprintf(stdmsg, format, ap);
#endif
fprintf(stdmsg, "\n");
fflush(stdmsg);
}
verrorPrint(loc, " ", format, ap);
}

void vwarning(Loc loc, const char *format, va_list ap)
{
if (global.params.warnings && !global.gag)
{
char *p = loc.toChars();

if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);

fprintf(stdmsg, "Warning: ");
#if _MSC_VER
// MS doesn't recognize %zu format
OutBuffer tmp;
tmp.vprintf(format, ap);
fprintf(stdmsg, "%s", tmp.toChars());
#else
vfprintf(stdmsg, format, ap);
#endif
fprintf(stdmsg, "\n");
fflush(stdmsg);
verrorPrint(loc, "Warning: ", format, ap);
//halt();
if (global.params.warnings == 1)
global.warnings++; // warnings don't count if gagged
}
}

void vdeprecation(Loc loc, const char *format, va_list ap,
const char *p1, const char *p2)
{
if (!global.params.useDeprecated)
verror(loc, format, ap, p1, p2, "Deprecation: ");
}

/***************************************
* Call this after printing out fatal error messages to clean up and exit
* the compiler.
Expand Down

0 comments on commit d1f5765

Please sign in to comment.