Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 5481 - Support deprecated("message") #463

Merged
merged 1 commit into from over 1 year ago

8 participants

Daniel Murphy Andrei Alexandrescu Andrej Mitrovic Damian Ziemba David Nadlinger Walter Bright Brad Roberts Hara Kenji
Daniel Murphy
Collaborator

Add an optional message to deprecated.

Andrei Alexandrescu
Owner

This is a highly useful feature. I think we should merge it in and document it properly.

Andrej Mitrovic
Collaborator

If the code to handle @disable is similar to @deprecated we could consider implementing messages for the former too in another pull request. http://d.puremagic.com/issues/show_bug.cgi?id=8728

Damian Ziemba

LGTM :+1:
Indeed it is very useful.

@yebblies what do you think about adding unittest for failure (without -d) and asserting about correct deprecated message being displayed?

@9rnsr @dawgfoto what you think?

Daniel Murphy
Collaborator

@nazriel Does the autotester support that? I don't remember any other tests that check the output from dmd.

David Nadlinger
Collaborator

@yebblies: Kenji recently added support for that, see e.g. 21f32ed.

Damian Ziemba

@yebblies won't https://github.com/D-Programming-Language/dmd/blob/master/test/d_do_test.d#L178 work?
I think I saw it somewhere in action for Error message enhancement PR

Edit: Ups, @klickverbot was faster. And yea, that's exactly the PR I was looking for.

Daniel Murphy
Collaborator

Awesome, done. The duplicated error messages are caused by a different bug.

Damian Ziemba

Umm, auto tester bug or I am blind? Because I see no difference between expected and actual output (for example here http://d.puremagic.com/test-results/pull.ghtml?runid=316239)

DOWN: so the latter. NOT good *grins

Daniel Murphy
Collaborator

Path separators

Walter Bright
Owner

LGTM

Brad Roberts
Owner

This pull needs a quick rebase due to a conflict introduced by pulling in the other deprecation refactoring pull.

Daniel Murphy Fix Issue 5481 - Support deprecated("message")
Add an optional message to deprecated.
1e2f85e
Daniel Murphy
Collaborator

Done.

Damian Ziemba

@9rnsr @dawgfoto any final words? Can we merge it please?

Hara Kenji 9rnsr merged commit 2c4f26e into from October 07, 2012
Hara Kenji 9rnsr closed this October 07, 2012
Hara Kenji
Collaborator

Merged!

Daniel Murphy
Collaborator

Thanks all!

Andrei Alexandrescu
Owner

Great work everyone. This solves a known, long-standing issue to which we had no good solution. A solution has been proposed, implemented, and reviewed by the community and got approved by the BDFL. Congratulations to all involved!

Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Daniel Murphy yebblies deleted the branch November 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 07, 2012
Daniel Murphy Fix Issue 5481 - Support deprecated("message")
Add an optional message to deprecated.
1e2f85e
This page is out of date. Refresh to see the latest.
38  src/attrib.c
@@ -542,6 +542,44 @@ void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
542 542
     AttribDeclaration::toCBuffer(buf, hgs);
543 543
 }
544 544
 
  545
+/********************************* DeprecatedDeclaration ****************************/
  546
+
  547
+DeprecatedDeclaration::DeprecatedDeclaration(Expression *msg, Dsymbols *decl)
  548
+        : StorageClassDeclaration(STCdeprecated, decl)
  549
+{
  550
+    this->msg = msg;
  551
+}
  552
+
  553
+Dsymbol *DeprecatedDeclaration::syntaxCopy(Dsymbol *s)
  554
+{
  555
+    assert(!s);
  556
+    return new DeprecatedDeclaration(msg->syntaxCopy(), Dsymbol::arraySyntaxCopy(decl));
  557
+}
  558
+
  559
+void DeprecatedDeclaration::setScope(Scope *sc)
  560
+{
  561
+    assert(msg);
  562
+    char *depmsg = NULL;
  563
+    StringExp *se = msg->toString();
  564
+    if (se)
  565
+        depmsg = (char *)se->string;
  566
+    else
  567
+        msg->error("string expected, not '%s'", msg->toChars());
  568
+
  569
+    Scope *scx = sc->push();
  570
+    scx->depmsg = depmsg;
  571
+    StorageClassDeclaration::setScope(scx);
  572
+    scx->pop();
  573
+}
  574
+
  575
+void DeprecatedDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
  576
+{
  577
+    buf->writestring("deprecated(");
  578
+    msg->toCBuffer(buf, hgs);
  579
+    buf->writestring(") ");
  580
+    AttribDeclaration::toCBuffer(buf, hgs);
  581
+}
  582
+
545 583
 /********************************* LinkDeclaration ****************************/
546 584
 
547 585
 LinkDeclaration::LinkDeclaration(enum LINK p, Dsymbols *decl)
12  src/attrib.h
@@ -61,7 +61,7 @@ struct AttribDeclaration : Dsymbol
61 61
     void toObjFile(int multiobj);                       // compile to .obj file
62 62
 };
63 63
 
64  
-struct StorageClassDeclaration: AttribDeclaration
  64
+struct StorageClassDeclaration : AttribDeclaration
65 65
 {
66 66
     StorageClass stc;
67 67
 
@@ -75,6 +75,16 @@ struct StorageClassDeclaration: AttribDeclaration
75 75
     static void stcToCBuffer(OutBuffer *buf, StorageClass stc);
76 76
 };
77 77
 
  78
+struct DeprecatedDeclaration : StorageClassDeclaration
  79
+{
  80
+    Expression *msg;
  81
+
  82
+    DeprecatedDeclaration(Expression *msg, Dsymbols *decl);
  83
+    Dsymbol *syntaxCopy(Dsymbol *s);
  84
+    void setScope(Scope *sc);
  85
+    void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
  86
+};
  87
+
78 88
 struct LinkDeclaration : AttribDeclaration
79 89
 {
80 90
     enum LINK linkage;
16  src/dsymbol.c
@@ -61,6 +61,7 @@ Dsymbol::Dsymbol(Identifier *ident)
61 61
     this->comment = NULL;
62 62
     this->scope = NULL;
63 63
     this->errors = false;
  64
+    this->depmsg = NULL;
64 65
 }
65 66
 
66 67
 int Dsymbol::equals(Object *o)
@@ -320,6 +321,8 @@ void Dsymbol::setScope(Scope *sc)
320 321
     if (!sc->nofree)
321 322
         sc->setNoFree();                // may need it even after semantic() finishes
322 323
     scope = sc;
  324
+    if (sc->depmsg)
  325
+        depmsg = sc->depmsg;
323 326
 }
324 327
 
325 328
 void Dsymbol::importAll(Scope *sc)
@@ -651,7 +654,18 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
651 654
                 goto L1;
652 655
         }
653 656
 
654  
-        deprecation(loc, "is deprecated");
  657
+        char *message = NULL;
  658
+        for (Dsymbol *p = this; p; p = p->parent)
  659
+        {
  660
+            message = p->depmsg;
  661
+            if (message)
  662
+                break;
  663
+        }
  664
+
  665
+        if (message)
  666
+            deprecation(loc, "is deprecated - %s", message);
  667
+        else
  668
+            deprecation(loc, "is deprecated");
655 669
     }
656 670
 
657 671
   L1:
1  src/dsymbol.h
@@ -122,6 +122,7 @@ struct Dsymbol : Object
122 122
     Loc loc;                    // where defined
123 123
     Scope *scope;               // !=NULL means context to use for semantic()
124 124
     bool errors;                // this symbol failed to pass semantic()
  125
+    char *depmsg;               // customized deprecation message
125 126
 
126 127
     Dsymbol();
127 128
     Dsymbol(Identifier *);
23  src/parse.c
@@ -364,7 +364,6 @@ Dsymbols *Parser::parseDeclDefs(int once)
364 364
             case TOKoverride:     stc = STCoverride;     goto Lstc;
365 365
             case TOKabstract:     stc = STCabstract;     goto Lstc;
366 366
             case TOKsynchronized: stc = STCsynchronized; goto Lstc;
367  
-            case TOKdeprecated:   stc = STCdeprecated;   goto Lstc;
368 367
 #if DMDV2
369 368
             case TOKnothrow:      stc = STCnothrow;      goto Lstc;
370 369
             case TOKpure:         stc = STCpure;         goto Lstc;
@@ -411,13 +410,17 @@ Dsymbols *Parser::parseDeclDefs(int once)
411 410
                             stc = STCimmutable;
412 411
                         }
413 412
                         goto Lstc;
  413
+                    case TOKdeprecated:
  414
+                        if (peek(&token)->value == TOKlparen)
  415
+                            break;
  416
+                        stc = STCdeprecated;
  417
+                        goto Lstc;
414 418
                     case TOKfinal:        stc = STCfinal;        goto Lstc;
415 419
                     case TOKauto:         stc = STCauto;         goto Lstc;
416 420
                     case TOKscope:        stc = STCscope;        goto Lstc;
417 421
                     case TOKoverride:     stc = STCoverride;     goto Lstc;
418 422
                     case TOKabstract:     stc = STCabstract;     goto Lstc;
419 423
                     case TOKsynchronized: stc = STCsynchronized; goto Lstc;
420  
-                    case TOKdeprecated:   stc = STCdeprecated;   goto Lstc;
421 424
                     case TOKnothrow:      stc = STCnothrow;      goto Lstc;
422 425
                     case TOKpure:         stc = STCpure;         goto Lstc;
423 426
                     case TOKref:          stc = STCref;          goto Lstc;
@@ -463,6 +466,22 @@ Dsymbols *Parser::parseDeclDefs(int once)
463 466
                 s = new StorageClassDeclaration(storageClass, a);
464 467
                 break;
465 468
 
  469
+            case TOKdeprecated:
  470
+                if (peek(&token)->value != TOKlparen)
  471
+                {
  472
+                    stc = STCdeprecated;
  473
+                    goto Lstc;
  474
+                }
  475
+            {
  476
+                nextToken();
  477
+                check(TOKlparen);
  478
+                Expression *e = parseAssignExp();
  479
+                check(TOKrparen);
  480
+                a = parseBlock();
  481
+                s = new DeprecatedDeclaration(e, a);
  482
+                break;
  483
+            }
  484
+
466 485
             case TOKextern:
467 486
                 if (peek(&token)->value != TOKlparen)
468 487
                 {   stc = STCextern;
2  src/scope.c
@@ -67,6 +67,7 @@ Scope::Scope()
67 67
     this->protection = PROTpublic;
68 68
     this->explicitProtection = 0;
69 69
     this->stc = 0;
  70
+    this->depmsg = NULL;
70 71
     this->offset = 0;
71 72
     this->inunion = 0;
72 73
     this->incontract = 0;
@@ -114,6 +115,7 @@ Scope::Scope(Scope *enclosing)
114 115
     this->linkage = enclosing->linkage;
115 116
     this->protection = enclosing->protection;
116 117
     this->explicitProtection = enclosing->explicitProtection;
  118
+    this->depmsg = enclosing->depmsg;
117 119
     this->stc = enclosing->stc;
118 120
     this->offset = 0;
119 121
     this->inunion = enclosing->inunion;
1  src/scope.h
@@ -87,6 +87,7 @@ struct Scope
87 87
     int explicitProtection;     // set if in an explicit protection attribute
88 88
 
89 89
     StorageClass stc;           // storage class
  90
+    char *depmsg;               // customized deprecation message
90 91
 
91 92
     unsigned flags;
92 93
 #define SCOPEctor       1       // constructor type
32  test/compilable/depmsg.d
... ...
@@ -0,0 +1,32 @@
  1
+// REQUIRED_ARGS: -d
  2
+
  3
+void main()
  4
+{
  5
+    class Inner
  6
+    {
  7
+        deprecated("With message!")
  8
+        {
  9
+            struct A { }
  10
+            class B { }
  11
+            interface C { }
  12
+            union D { }
  13
+            enum E { e };
  14
+            //typedef int F;
  15
+            alias int G;
  16
+            static int H;
  17
+            template I() { class I {} }
  18
+        }
  19
+    }
  20
+    with(Inner)
  21
+    {
  22
+        A a;
  23
+        B b;
  24
+        C c;
  25
+        D d;
  26
+        E e;
  27
+        //F f;
  28
+        G g;
  29
+        auto h = H;
  30
+        I!() i;
  31
+    }
  32
+}
50  test/fail_compilation/depmsg.d
... ...
@@ -0,0 +1,50 @@
  1
+/*
  2
+TEST_OUTPUT:
  3
+---
  4
+fail_compilation/depmsg.d(20): Deprecation: struct depmsg.main.Inner.A is deprecated - With message!
  5
+fail_compilation/depmsg.d(20): Deprecation: struct depmsg.main.Inner.A is deprecated - With message!
  6
+fail_compilation/depmsg.d(21): Deprecation: class depmsg.main.Inner.B is deprecated - With message!
  7
+fail_compilation/depmsg.d(21): Deprecation: class depmsg.main.Inner.B is deprecated - With message!
  8
+fail_compilation/depmsg.d(22): Deprecation: interface depmsg.main.Inner.C is deprecated - With message!
  9
+fail_compilation/depmsg.d(22): Deprecation: interface depmsg.main.Inner.C is deprecated - With message!
  10
+fail_compilation/depmsg.d(23): Deprecation: union depmsg.main.Inner.D is deprecated - With message!
  11
+fail_compilation/depmsg.d(23): Deprecation: union depmsg.main.Inner.D is deprecated - With message!
  12
+fail_compilation/depmsg.d(24): Deprecation: enum depmsg.main.Inner.E is deprecated - With message!
  13
+fail_compilation/depmsg.d(24): Deprecation: enum depmsg.main.Inner.E is deprecated - With message!
  14
+fail_compilation/depmsg.d(26): Deprecation: alias depmsg.main.Inner.G is deprecated - With message!
  15
+fail_compilation/depmsg.d(27): Deprecation: variable depmsg.main.Inner.H is deprecated - With message!
  16
+fail_compilation/depmsg.d(28): Deprecation: class depmsg.main.Inner.I!().I is deprecated - With message!
  17
+---
  18
+*/
  19
+
  20
+#line 1
  21
+void main()
  22
+{
  23
+    class Inner
  24
+    {
  25
+        deprecated("With message!")
  26
+        {
  27
+            struct A { }
  28
+            class B { }
  29
+            interface C { }
  30
+            union D { }
  31
+            enum E { e };
  32
+            //typedef int F;
  33
+            alias int G;
  34
+            static int H;
  35
+            template I() { class I {} }
  36
+        }
  37
+    }
  38
+    with(Inner)
  39
+    {
  40
+        A a;
  41
+        B b;
  42
+        C c;
  43
+        D d;
  44
+        E e;
  45
+        //F f;
  46
+        G g;
  47
+        auto h = H;
  48
+        I!() i;
  49
+    }
  50
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.