* Make large enum constants unsigned, revisited
@ 2016-03-02 4:46 Alan Modra
2016-03-02 11:41 ` Frank Ch. Eigler
0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2016-03-02 4:46 UTC (permalink / raw)
To: cgen
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Make large enum constants unsigned, revisited
2016-03-02 4:46 Make large enum constants unsigned, revisited Alan Modra
@ 2016-03-02 11:41 ` Frank Ch. Eigler
0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2016-03-02 11:41 UTC (permalink / raw)
To: Alan Modra; +Cc: cgen
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-02 11:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-02 4:46 Make large enum constants unsigned, revisited Alan Modra
2016-03-02 11:41 ` Frank Ch. Eigler
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).