Make large enum constants unsigned, revisited

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Make large enum constants unsigned, revisited

Alan Modra-3
The patch at https://sourceware.org/ml/cgen/2014-q2/msg00008.html was
never committed, presumably because the submitter gave up trying.  I
thought the patch was good, but have rewritten it to instead output
hex numbers rather than appending "u", an idiom used elsewhere in
cgen.  Search for "that's not k&r".

I've also fixed the upcase to apply just to identifiers, so cgen emits
0x80000000 rather than 0X80000000, and tidied the sanitize code a
little.  The tidy doesn't change emitted code.

OK to commit?

        * enum.scm (gen-enum-decl): Emit large numbers as hex.  Tidy
        start-sanitize.  Upcase just the identifiers.

Index: enum.scm
===================================================================
RCS file: /cvs/src/src/cgen/enum.scm,v
retrieving revision 1.13
diff -u -p -r1.13 enum.scm
--- enum.scm 13 Feb 2010 03:39:15 -0000 1.13
+++ enum.scm 2 Mar 2016 04:19:20 -0000
@@ -272,35 +272,31 @@
      (append!
       result
       (string-list
-       (if san?
-   (string-append "\n"
-  (if include-sanitize-marker?
-      ; split string to avoid removal
-      (string-append "/* start-"
-     "sanitize-"
-     san-code " */\n")
-      "")
-  " ")
+       (if (and san? include-sanitize-marker?)
+   ; split string to avoid removal
+   (string-append "\n/* start-"
+  "sanitize-"
+  san-code " */")
+   "")
+       (if (or san? (=? (remainder n 4) 0))
+   "\n "
    "")
-       (string-upcase
- (string-append
- (if (and (not san?) (=? (remainder n 4) 0))
-     "\n "
-     "")
- (if (= n 0)
-     " "
-     ", ")
- (gen-c-symbol prefix)
- (gen-c-symbol (car e))
- (if (or sequential?
- (null? (cdr e))
- (eq? '- (cadr e)))
-     ""
-     (string-append " = "
-    (if (number? (cadr e))
- (number->string (cadr e))
- (cadr e))))
- ))
+       (if (= n 0)
+   " "
+   ", ")
+       (string-upcase (gen-c-symbol prefix))
+       (string-upcase (gen-c-symbol (car e)))
+       (if (or sequential?
+       (null? (cdr e))
+       (eq? '- (cadr e)))
+   ""
+   (string-append " = "
+  (if (number? (cadr e))
+      (if (>= (cadr e) #x80000000)
+  (string-append "0x"
+ (number->string (cadr e) 16))
+  (number->string (cadr e)))
+      (string-upcase (cadr e)))))
        (if (and san? include-sanitize-marker?)
    ; split string to avoid removal
    (string-append "\n/* end-"

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: Make large enum constants unsigned, revisited

Frank Ch. Eigler
Hi, Alan -

On Wed, Mar 02, 2016 at 03:16:01PM +1030, Alan Modra wrote:
> The patch at https://sourceware.org/ml/cgen/2014-q2/msg00008.html was
> never committed, presumably because the submitter gave up trying.  [...]

Yikes.  Anyway lgtm, go for it.

- FChE