Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Deprecation (dmd-1.x) #909

Merged
merged 1 commit into from

6 participants

@llucax

The deprecation() function works similar to the error() or warning()
functions but only prints messages if global.params.useDeprecated is
false. If it is, it uses the error() function to actually print the
messages and halt the program.

This patch also tries to make the messages consistent with the
behaviour. Some messages said that some feature was deprecated when it
has been completely removed in reality and should be plain errors.

@leandro-lucarella-sociomantic leandro-lucarella-sociomantic Add deprecation() to print deprecation messages
The deprecation() function works similar to the error() or warning()
functions but only prints messages if global.params.useDeprecated is
false. If it is, it uses the error() function to actually print the
messages and halt the program.

This patch also tries to make the messages consistent with the
behaviour. Some messages said that some feature was deprecated when it
has been completely removed in reality and should be plain errors or
vice versa.

Finally, deprecations are reported with Deprecation instead of Error
(and all the error messages are normalized and produced by a single
function).
2343302
@WalterBright WalterBright was assigned
@andralex
Owner

This is tied to #908. dmd developers, please merge or reject in lockstep.

@yebblies
Collaborator

The corresponding D2 pull request has been merged.

@llucax

I can update this pull request too if needed, just let me know (since Walter tend to do all D1 merging himself I'm not sure it makes any sense to do so).

@braddr
Owner

@WalterBright Which is easier for d2 -> d1 syncing? You end to be the one that does them all.

@WalterBright WalterBright referenced this pull request from a commit
@WalterBright WalterBright merge D1 pull #909 c2422b9
@WalterBright WalterBright merged commit 2343302 into D-Programming-Language:dmd-1.x

1 check failed

Details default Fail: 9
@WalterBright

Sigh, it doesn't compile:

dmc -c -I..\root;\dm\include -o -cpp -DDM_TARGET_CPU_X86=1 dsymbol
{
^
dsymbol.c(210) : Error: 'getLoc' is not a member of 'Dsymbol'
if (!loc.filename) // avoid bug 5861.
^
dsymbol.c(211) : Error: undefined identifier 'loc', did you mean 'Loc'?
Module *m = getModule();
^
dsymbol.c(213) : Error: undefined identifier 'getModule'
loc.filename = m->srcfile->toChars();
^
dsymbol.c(216) : Error: invalid simple type name destructor
return loc;
^
dsymbol.c(218) : Error: reference must refer to same type or be const
Fatal error: too many errors
--- errorlevel 1

@WalterBright

Ignore that, my fault.

@llucax

@WalterBright That patch was outdated though, I wouldn't be surprised if it didn't compile (o at least merge), I was waiting for feedback. I'll take a look at the D1 code, update any missing bits and do a new pull request.

@llucax

OK, it wasn't as outdated as I thought, here are a couple of very minor fixes and cleanups: #1206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 19, 2012
  1. @leandro-lucarella-sociomantic

    Add deprecation() to print deprecation messages

    leandro-lucarella-sociomantic authored
    The deprecation() function works similar to the error() or warning()
    functions but only prints messages if global.params.useDeprecated is
    false. If it is, it uses the error() function to actually print the
    messages and halt the program.
    
    This patch also tries to make the messages consistent with the
    behaviour. Some messages said that some feature was deprecated when it
    has been completely removed in reality and should be plain errors or
    vice versa.
    
    Finally, deprecations are reported with Deprecation instead of Error
    (and all the error messages are normalized and produced by a single
    function).
This page is out of date. Refresh to see the latest.
View
33 src/dsymbol.c
@@ -206,10 +206,8 @@ const char *Dsymbol::toPrettyChars()
return s;
}
-char *Dsymbol::locToChars()
+Loc& Dsymbol::getLoc()
{
- OutBuffer buf;
-
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();
@@ -217,7 +215,12 @@ char *Dsymbol::locToChars()
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
- return loc.toChars();
+ return loc;
+}
+
+char *Dsymbol::locToChars()
+{
+ return getLoc().toChars();
}
const char *Dsymbol::kind()
@@ -582,17 +585,9 @@ 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);
}
@@ -600,7 +595,15 @@ 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);
}
@@ -624,7 +627,7 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
goto L1;
}
- error(loc, "is deprecated");
+ deprecation(loc, "is deprecated");
}
L1:
View
2  src/dsymbol.h
@@ -124,11 +124,13 @@ 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 checkDeprecated(Loc loc, Scope *sc);
Module *getModule();
Dsymbol *pastMixin();
View
22 src/expression.c
@@ -1002,6 +1002,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)
@@ -4711,7 +4722,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
(s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
s != s2)
{
- error("shadowing declaration %s is deprecated", s->toPrettyChars());
+ deprecation("shadowing declaration %s is deprecated", s->toPrettyChars());
}
}
}
@@ -7434,8 +7445,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;
@@ -7691,9 +7701,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;
@@ -8629,7 +8637,7 @@ Expression *AssignExp::semantic(Scope *sc)
{ Expression *e = new DotIdExp(loc, ae->e1, id);
if (1 || !global.params.useDeprecated)
- { error("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
+ { deprecation("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
return new ErrorExp();
}
View
1  src/expression.h
@@ -111,6 +111,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);
View
3  src/iasm.c
@@ -4238,8 +4238,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)
View
25 src/lexer.c
@@ -314,6 +314,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;
@@ -594,8 +602,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;
}
@@ -2254,8 +2261,7 @@ TOK Lexer::number(Token *t)
goto L1;
case 'l':
- if (1 || !global.params.useDeprecated)
- error("'l' suffix is deprecated, use 'L' instead");
+ deprecation("'l' suffix is deprecated, use 'L' instead");
case 'L':
f = FLAGS_long;
L1:
@@ -2271,8 +2277,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
@@ -2504,8 +2510,7 @@ __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++;
@@ -2513,8 +2518,8 @@ __body
}
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)
{
View
1  src/lexer.h
@@ -305,6 +305,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 pragma();
unsigned decodeUTF();
void getDocComment(Token *t, unsigned lineComment);
View
69 src/mars.c
@@ -192,17 +192,26 @@ 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, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ vdeprecation(loc, format, ap);
+
+ va_end( ap );
+}
+
+// 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)
{
- if (!global.gag)
- {
char *p = loc.toChars();
if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
- fprintf(stdmsg, "Error: ");
+ fputs(header, stdmsg);
if (p1)
fprintf(stdmsg, "%s ", p1);
if (p2)
@@ -217,8 +226,17 @@ void verror(Loc loc, const char *format, va_list ap, const char *p1, const char
#endif
fprintf(stdmsg, "\n");
fflush(stdmsg);
- if (global.errors >= 20) // moderate blizzard of cascading messages
- fatal();
+}
+
+// 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
@@ -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.
View
5 src/mars.h
@@ -416,11 +416,14 @@ typedef uint64_t StorageClass;
void warning(Loc loc, const char *format, ...);
+void deprecation(Loc loc, const char *format, ...);
void error(Loc loc, const char *format, ...);
void errorSupplemental(Loc loc, const char *format, ...);
-void verror(Loc loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
+void verror(Loc loc, const char *format, va_list, const char *p1 = NULL, const char *p2 = NULL, const char *header = "Error: ");
void vwarning(Loc loc, const char *format, va_list);
void verrorSupplemental(Loc loc, const char *format, va_list);
+void verrorPrint(Loc loc, const char *header, const char *format, va_list, const char *p1 = NULL, const char *p2 = NULL);
+void vdeprecation(Loc loc, const char *format, va_list, const char *p1 = NULL, const char *p2 = NULL);
void fatal();
void err_nomem();
int runLINK();
View
12 src/mtype.c
@@ -626,8 +626,7 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
}
else if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(NULL);
}
else if (ident == Id::init)
@@ -695,8 +694,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
if (ident == Id::offset)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".offset deprecated, use .offsetof");
+ deprecation(e->loc, ".offset deprecated, use .offsetof");
goto Loffset;
}
else if (ident == Id::offsetof)
@@ -745,8 +743,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
}
if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(sc);
return e;
}
@@ -5049,8 +5046,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
return getTypeInfo(sc);
}
if (ident == Id::outer && sym->vthis)
View
10 src/parse.c
@@ -1326,8 +1326,8 @@ BaseClasses *Parser::parseBaseClasses()
nextToken();
break;
}
- //if (prot && !global.params.useDeprecated)
- //error("use of base class protection is deprecated");
+ //if (prot)
+ //deprecation("use of base class protection is deprecated");
if (token.value == TOKidentifier)
{
BaseClass *b = new BaseClass(parseBasicType(), protection);
@@ -3221,8 +3221,7 @@ Statement *Parser::parseStatement(int flags)
arg = new Parameter(STCin, NULL, token.ident, NULL);
nextToken();
nextToken();
- if (1 || !global.params.useDeprecated)
- error("if (v; e) is deprecated, use if (auto v = e)");
+ deprecation("if (v; e) is deprecated, use if (auto v = e)");
}
}
@@ -3575,8 +3574,7 @@ Statement *Parser::parseStatement(int flags)
nextToken();
s = parseStatement(PSsemi | PScurlyscope);
#if DMDV2
- if (!global.params.useDeprecated)
- error("volatile statements deprecated; used synchronized statements instead");
+ deprecation("volatile statements deprecated; used synchronized statements instead");
#endif
s = new VolatileStatement(loc, s);
break;
View
8 src/statement.c
@@ -116,6 +116,14 @@ void Statement::warning(const char *format, ...)
va_end( ap );
}
+void Statement::deprecation(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(loc, format, ap);
+ va_end( ap );
+}
+
int Statement::hasBreak()
{
//printf("Statement::hasBreak()\n");
View
1  src/statement.h
@@ -92,6 +92,7 @@ struct Statement : Object
void error(const char *format, ...);
void warning(const char *format, ...);
+ void deprecation(const char *format, ...);
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual TryCatchStatement *isTryCatchStatement() { return NULL; }
virtual GotoStatement *isGotoStatement() { return NULL; }
Something went wrong with that request. Please try again.