Print this page
Rich's feedback

@@ -8,23 +8,24 @@
  * Source Licenses. See LICENSE.TXT for details.
  *
  */
 
 /*
- * Copyright 2017 Jason King.
+ * Copyright 2018 Jason King.
  */
 #include <ctype.h>
 #include <errno.h>
 #include <locale.h>
+#include <note.h>
 #include <string.h>
 #include <setjmp.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/isa_defs.h>
 #include <sys/debug.h>
-#include "sysdemangle.h"
-#include "sysdemangle_int.h"
+#include "demangle-sys.h"
+#include "demangle_int.h"
 #include "cxx.h"
 
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
 #endif

@@ -49,12 +50,14 @@
         locale_t        cpp_loc;
 } cpp_db_t;
 
 #define CK(x)                                           \
         do {                                            \
-                if (!(x))                               \
+                if (!(x)) {                             \
                         longjmp(db->cpp_jmp, 1);        \
+                }                                       \
+        NOTE(CONSTCOND)                                 \
         } while (0)
 
 #define TOP_L(db) (&(name_top(&(db)->cpp_name)->strp_l))
 #define RLEN(f, l) ((size_t)((l) - (f)))
 #define NAMT(db, n) (nlen(db) - n)

@@ -213,11 +216,11 @@
 
                 (void) memcpy(result, s->str_s, s->str_len);
         }
 
 done:
-        if (getenv("DEMANGLE_DEBUG") != NULL)
+        if (demangle_debug)
                 dump(&db, stdout);
 
         db_fini(&db);
         return (result);
 }

@@ -287,11 +290,11 @@
         return (last);
 }
 
 /*
  * _block_invoke
- * _block_invoke<digit>+        XXX: should it be <digit>* ?
+ * _block_invoke<digit>*
  * _block_invoke_<digit>+
  */
 static const char *
 parse_block_invoke(const char *first, const char *last, cpp_db_t *db)
 {

@@ -376,11 +379,11 @@
                         goto fail;
 
                 str_pair_t *sp = name_top(&db->cpp_name);
 
                 if (str_length(&sp->strp_r) == 0)
-                        str_append(&sp->strp_l, " ", 1);
+                        (void) str_append(&sp->strp_l, " ", 1);
 
                 nfmt(db, "{0:L}{1:L}", "{1:R}{0:R}");
                 t = t2;
         }
 

@@ -390,13 +393,11 @@
         size_t n = nlen(db);
 
         if (t[0] == 'v') {
                 t++;
         } else {
-
-                /*CONSTCOND*/
-                while (1) {
+                for (;;) {
                         t2 = parse_type(t, last, db);
                         if (t2 == t || t == last)
                                 break;
 
                         t = t2;

@@ -1539,15 +1540,15 @@
         str_t *l = &sp->strp_l;
         str_t *r = &sp->strp_r;
 
         if (str_length(r) > 1 &&
             r->str_s[0] == ' ' && r->str_s[1] == '[') {
-                str_append(l, " (", 2);
-                str_insert(r, 0, ")", 1);
+                (void) str_append(l, " (", 2);
+                (void) str_insert(r, 0, ")", 1);
         } else if (str_length(r) > 0 && r->str_s[0] == '(') {
-                str_append(l, "(", 1);
-                str_insert(r, 0, ")", 1);
+                (void) str_append(l, "(", 1);
+                (void) str_insert(r, 0, ")", 1);
         }
 }
 
 /* BEGIN CSTYLED */
 /*

@@ -1611,11 +1612,11 @@
         case 'C':
                 t = parse_type(first + 1, last, db);
                 if (t == first + 1 || NAMT(db, n) == 0)
                         return (first);
 
-                str_append(TOP_L(db), " complex", 8);
+                (void) str_append(TOP_L(db), " complex", 8);
                 save_top(db, 1);
                 return (t);
 
         case 'F':
                 t = parse_function_type(first, last, db);

@@ -1627,11 +1628,11 @@
         case 'G':
                 t = parse_type(first + 1, last, db);
                 if (t == first + 1 || NAMT(db, n) == 0)
                         return (first);
 
-                str_append(TOP_L(db), " imaginary", 10);
+                (void) str_append(TOP_L(db), " imaginary", 10);
                 save_top(db, 1);
                 return (t);
 
         case 'M':
                 t = parse_pointer_to_member_type(first, last, db);

@@ -1648,11 +1649,11 @@
 
                 sp = name_at(&db->cpp_name, amt - 1);
                 for (size_t i = 0; i < amt; i++, sp++) {
                         paren(sp);
                         if (str_pair_len(sp) > 0)
-                                str_append(&sp->strp_l, "&&", 2);
+                                (void) str_append(&sp->strp_l, "&&", 2);
                 }
 
                 save_top(db, amt);
                 return (t);
 

@@ -1670,14 +1671,14 @@
                                 continue;
 
                         paren(sp);
                         if (first[1] != 'U' ||
                             strncmp(l->str_s, "objc_object<", 12) != 0) {
-                                str_append(l, "*", 1);
+                                (void) str_append(l, "*", 1);
                         } else {
-                                str_erase(l, 0, 11);
-                                str_insert(l, 0, "id", 2);
+                                (void) str_erase(l, 0, 11);
+                                (void) str_insert(l, 0, "id", 2);
                         }
                 }
                 save_top(db, amt);
                 return (t);
 

@@ -1692,11 +1693,11 @@
                         if (str_length(&sp->strp_l) == 0 &&
                             str_length(&sp->strp_r) == 0)
                                 continue;
 
                         paren(sp);
-                        str_append(&sp->strp_l, "&", 1);
+                        (void) str_append(&sp->strp_l, "&", 1);
                 }
 
                 save_top(db, amt);
                 return (t);
 

@@ -1874,15 +1875,15 @@
 
                         if (str_length(s) == 0)
                                 continue;
 
                         if (cv & 1)
-                                str_append(s, " const", 6);
+                                (void) str_append(s, " const", 6);
                         if (cv & 2)
-                                str_append(s, " volatile", 9);
+                                (void) str_append(s, " volatile", 9);
                         if (cv & 4)
-                                str_append(s, " restrict", 9);
+                                (void) str_append(s, " restrict", 9);
 
                         continue;
                 }
 
                 s = &sp->strp_r;

@@ -1893,19 +1894,19 @@
                         if (s->str_s[pos - 1] == '&')
                                 pos--;
                 }
 
                 if (cv & 1) {
-                        str_insert(s, pos, " const", 6);
+                        (void) str_insert(s, pos, " const", 6);
                         pos += 6;
                 }
                 if (cv & 2) {
-                        str_insert(s, pos, " volatile", 9);
+                        (void) str_insert(s, pos, " volatile", 9);
                         pos += 9;
                 }
                 if (cv & 4) {
-                        str_insert(s, pos, " restrict", 9);
+                        (void) str_insert(s, pos, " restrict", 9);
                 }
         }
 
         save_top(db, amt);
         return (t1);

@@ -2630,11 +2631,11 @@
                 case '0':
                 case '1':
                 case '2':
                 case '5':
                         basename(db);
-                        str_insert(TOP_L(db), 0, "~", 1);
+                        (void) str_insert(TOP_L(db), 0, "~", 1);
                         break;
                 default:
                         return (first);
                 }
                 break;

@@ -2787,11 +2788,11 @@
                 str_fini(&num);
                 return (first);
         }
 
         num.str_len = n;
-        name_add_str(&db->cpp_name, &num, NULL);
+        (void) name_add_str(&db->cpp_name, &num, NULL);
 
         return (t + 1);
 }
 
 /*

@@ -3401,11 +3402,11 @@
          * if we have  " [xxx]" already, want new result to be
          * " [yyy][xxx]"
          */
         str_t *r = &name_top(&db->cpp_name)->strp_r;
         if (r->str_len > 1 && r->str_s[0] == ' ' && r->str_s[1] == '[')
-                str_erase(r, 0, 1);
+                (void) str_erase(r, 0, 1);
 
         nfmt(db, "{0:L}", " [{1}]{0:R}");
         return (t1);
 }
 

@@ -3483,11 +3484,11 @@
         if (t != t2) {
                 if (global) {
                         if (nempty(db))
                                 return (first);
 
-                        str_insert(TOP_L(db), 0, "::", 2);
+                        (void) str_insert(TOP_L(db), 0, "::", 2);
                 }
                 return (t2);
         }
 
         if (t[0] != 's' || t[1] != 'r' || last - t < 2)