Permalink
Browse files

DRY on protection to string

  • Loading branch information...
1 parent 638594e commit 2cb747d29a029faf02999e356fc7aabc747ea2ab @adamdruppe committed Oct 14, 2012
Showing with 11 additions and 31 deletions.
  1. +4 −11 src/attrib.c
  2. +1 −8 src/doc.c
  3. +3 −0 src/dsymbol.h
  4. +0 −1 src/json.c
  5. +3 −11 src/traits.c
View
@@ -683,17 +683,10 @@ void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection)
{
const char *p;
- switch (protection)
- {
- case PROTprivate: p = "private"; break;
- case PROTpackage: p = "package"; break;
- case PROTprotected: p = "protected"; break;
- case PROTpublic: p = "public"; break;
- case PROTexport: p = "export"; break;
- default:
- assert(0);
- break;
- }
+ p = Pprotectionnames[protection];
+
+ assert(p);
+
buf->writestring(p);
buf->writeByte(' ');
}
View
@@ -553,15 +553,8 @@ void ScopeDsymbol::emitMemberComments(Scope *sc)
void emitProtection(OutBuffer *buf, PROT prot)
{
- const char *p;
+ const char *p = Pprotectionnames[prot];
- switch (prot)
- {
- case PROTpackage: p = "package"; break;
- case PROTprotected: p = "protected"; break;
- case PROTexport: p = "export"; break;
- default: p = NULL; break;
- }
if (p)
buf->printf("%s ", p);
}
View
@@ -96,6 +96,9 @@ enum PROT
PROTexport,
};
+// this is used for printing the protection in json, traits, docs, etc.
+static const char* Pprotectionnames[] = {NULL, "none", "private", "package", "protected", "public", "export"};
+
/* State of symbol in winding its way through the passes of the compiler
*/
enum PASS
View
@@ -44,7 +44,6 @@ const char Ptype[] = "type";
const char Pcomment[] = "comment";
const char Pmembers[] = "members";
const char Pprotection[] = "protection";
-const char* Pprotectionnames[] = {NULL, "none", "private", "package", "protected", "public", "export"};
void JsonRemoveComma(OutBuffer *buf);
View
@@ -245,17 +245,9 @@ Expression *TraitsExp::semantic(Scope *sc)
PROT protection = s->prot();
- const char *protName =
- protection == PROTundefined ? ""
- : protection == PROTnone ? "none"
- : protection == PROTprivate ? "private"
- : protection == PROTpackage ? "package"
- : protection == PROTprotected ? "protected"
- : protection == PROTpublic ? "public"
- : protection == PROTexport ? "export"
- : (assert(0), ""); // unknown
-
- StringExp *se = new StringExp(loc, (char*) protName);
+ const char *protName = Pprotectionnames[protection];
+
+ StringExp *se = new StringExp(loc, (char *) protName);
return se->semantic(sc);
}

0 comments on commit 2cb747d

Please sign in to comment.