[llvm] r292975 - Demangle: use named values for CV qualifiers

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 12:04:57 PST 2017


Author: compnerd
Date: Tue Jan 24 14:04:56 2017
New Revision: 292975

URL: http://llvm.org/viewvc/llvm-project?rev=292975&view=rev
Log:
Demangle: use named values for CV qualifiers

Rather than hard-coding magic values of 1, 2, 4 (bit-field), use an enum
to name the values.  NFC.

Modified:
    llvm/trunk/lib/Demangle/ItaniumDemangle.cpp

Modified: llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Demangle/ItaniumDemangle.cpp?rev=292975&r1=292974&r2=292975&view=diff
==============================================================================
--- llvm/trunk/lib/Demangle/ItaniumDemangle.cpp (original)
+++ llvm/trunk/lib/Demangle/ItaniumDemangle.cpp Tue Jan 24 14:04:56 2017
@@ -36,6 +36,12 @@ enum {
   success
 };
 
+enum {
+  CV_const = (1 << 0),
+  CV_volatile = (1 << 1),
+  CV_restrict = (1 << 2),
+};
+
 template <class C>
 static const char *parse_type(const char *first, const char *last, C &db);
 template <class C>
@@ -436,15 +442,15 @@ static const char *parse_cv_qualifiers(c
   cv = 0;
   if (first != last) {
     if (*first == 'r') {
-      cv |= 4;
+      cv |= CV_restrict;
       ++first;
     }
     if (*first == 'V') {
-      cv |= 2;
+      cv |= CV_volatile;
       ++first;
     }
     if (*first == 'K') {
-      cv |= 1;
+      cv |= CV_const;
       ++first;
     }
   }
@@ -1668,22 +1674,22 @@ static const char *parse_type(const char
                 p -= 2;
               else if (db.names[k].second.back() == '&')
                 p -= 1;
-              if (cv & 1) {
+              if (cv & CV_const) {
                 db.names[k].second.insert(p, " const");
                 p += 6;
               }
-              if (cv & 2) {
+              if (cv & CV_volatile) {
                 db.names[k].second.insert(p, " volatile");
                 p += 9;
               }
-              if (cv & 4)
+              if (cv & CV_restrict)
                 db.names[k].second.insert(p, " restrict");
             } else {
-              if (cv & 1)
+              if (cv & CV_const)
                 db.names[k].first.append(" const");
-              if (cv & 2)
+              if (cv & CV_volatile)
                 db.names[k].first.append(" volatile");
-              if (cv & 4)
+              if (cv & CV_restrict)
                 db.names[k].first.append(" restrict");
             }
             db.subs.back().push_back(db.names[k]);
@@ -4074,11 +4080,11 @@ static const char *parse_encoding(const
           if (db.names.empty())
             return first;
           db.names.back().first += ')';
-          if (cv & 1)
+          if (cv & CV_const)
             db.names.back().first.append(" const");
-          if (cv & 2)
+          if (cv & CV_volatile)
             db.names.back().first.append(" volatile");
-          if (cv & 4)
+          if (cv & CV_restrict)
             db.names.back().first.append(" restrict");
           if (ref == 1)
             db.names.back().first.append(" &");




More information about the llvm-commits mailing list