Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix issue 4813 trait for getting at access modifiers #952

Closed
wants to merge 1 commit into from

6 participants

jmaschme Robert Clipsham Alex Rønne Petersen Andrei Alexandrescu Adam D. Ruppe Walter Bright
jmaschme

Added isPublic, isPrivate, isProtected, isPackage, and isExport traits

jmaschme Fix issue 4813
Added isPublic, isPrivate, isProtected, isPackage, and isExport traits
31416a5
Robert Clipsham

Would a getProtection trait not be more useful/flexible? Otherwise we'll end up with lots of wrappers for it unless they're added to phobos.

jmaschme

I think that would probably be best left for Phobos. There is no built-in representation for a protection type, so what would a getProtection trait return.

Also this approach is fairly consistent with the existing traits (isStaticFunction, isFinalFunction, isVirtualFunction, etc).

Robert Clipsham

I was thinking a string. It's fine either way I guess as long as the inverse is in phobos (with the current pull I'd expect a getProtection template in phobos which returns a string with the protection type).

Alex Rønne Petersen
alexrp commented July 05, 2012

Given that we have isVirtualFunction, isFinalFunction, and so on, I'd go for consistency and do it like this pull request does. It would have been better to have traits that returned strings for these things, but now we're stuck with the other approach, so let's be consistent.

Andrei Alexandrescu
Owner

I just reviewed a pull request that added protection level detection to __traits: #856. How do these two compare?

Adam D. Ruppe

I just tried using this DSYMBOL macro on my code, and it didn't pass an important test to me: it didn't give the protection on members returned from traits(getMember).

Adam D. Ruppe

I pushed an update to mine that passes the tests I need - in addition to the macro, gotta check for various dot expressions. Take a look at the pull request Andrei linked to.

Other than that, the difference is I return a string instead of doing is... meh either way works for me, the string just seemed simpler.

Hara Kenji 9rnsr referenced this pull request September 29, 2012
Merged

Protection trait #856

Walter Bright

Closed as it is redundant with #856.

Walter Bright WalterBright closed this November 10, 2012
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.

May 14, 2012
jmaschme Fix issue 4813
Added isPublic, isPrivate, isProtected, isPackage, and isExport traits
31416a5
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 25 additions and 0 deletions. Show diff stats Hide diff stats

  1. 5  src/idgen.c
  2. 20  src/traits.c
5  src/idgen.c
@@ -321,6 +321,11 @@ Msgtable msgtable[] =
321 321
     { "isRef" },
322 322
     { "isOut" },
323 323
     { "isLazy" },
  324
+    { "isPublic" },
  325
+    { "isPrivate" },
  326
+    { "isProtected" },
  327
+    { "isPackage" },
  328
+    { "isExport" },
324 329
     { "hasMember" },
325 330
     { "identifier" },
326 331
     { "parent" },
20  src/traits.c
@@ -187,6 +187,26 @@ Expression *TraitsExp::semantic(Scope *sc)
187 187
     {
188 188
         ISDSYMBOL((d = s->isDeclaration()) != NULL && d->storage_class & STClazy)
189 189
     }
  190
+    else if (ident == Id::isPublic)
  191
+    {
  192
+        ISDSYMBOL((s->prot() == PROTpublic));
  193
+    }
  194
+    else if (ident == Id::isPrivate)
  195
+    {
  196
+        ISDSYMBOL((s->prot() == PROTprivate));
  197
+    }
  198
+    else if (ident == Id::isProtected)
  199
+    {
  200
+        ISDSYMBOL((s->prot() == PROTprotected));
  201
+    }
  202
+    else if (ident == Id::isPackage)
  203
+    {
  204
+        ISDSYMBOL((s->prot() == PROTpackage));
  205
+    }
  206
+    else if (ident == Id::isExport)
  207
+    {
  208
+        ISDSYMBOL((s->prot() == PROTexport));
  209
+    }
190 210
     else if (ident == Id::identifier)
191 211
     {   // Get identifier for symbol as a string literal
192 212
 
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.