public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: cgen@sourceware.org
Subject: Make large enum constants unsigned, revisited
Date: Wed, 02 Mar 2016 04:46:00 -0000	[thread overview]
Message-ID: <20160302044600.GW10657@bubble.grove.modra.org> (raw)

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	other threads:[~2016-03-02  4:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02  4:46 Alan Modra [this message]
2016-03-02 11:41 ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160302044600.GW10657@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=cgen@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).