From b5524d9f8a569014c7f33d0d01e1621d8d71c9de Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 28 Oct 2014 02:53:24 +0000 Subject: [PATCH] eventids2.c: reduce size * ext/ripper/eventids2.c (token_assoc): reduce size. unsigned short can hold 65535 at least. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/ripper/eventids2.c | 6 ++++-- ext/ripper/tools/generate.rb | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c index bfb4e094d0..abbe584454 100644 --- a/ext/ripper/eventids2.c +++ b/ext/ripper/eventids2.c @@ -125,11 +125,13 @@ ripper_init_eventids2(void) set_id2(CHAR); } +STATIC_ASSERT(k__END___range, k__END__ < SHRT_MAX); +STATIC_ASSERT(ripper_scanner_ids_size, sizeof(ripper_scanner_ids) < SHRT_MAX); #define O(member) (int)offsetof(ripper_scanner_ids_t, ripper_id_##member) static const struct token_assoc { - int token; - int id_offset; + unsigned short token; + unsigned short id_offset; } token_to_eventid[] = { {' ', O(words_sep)}, {'!', O(op)}, diff --git a/ext/ripper/tools/generate.rb b/ext/ripper/tools/generate.rb index fc30e775bb..06b57101d1 100755 --- a/ext/ripper/tools/generate.rb +++ b/ext/ripper/tools/generate.rb @@ -149,9 +149,13 @@ def read_ids1_with_locations(path) end def read_ids2(path) - File.open(path) {|f| - return f.read.scan(/ID\s+ripper_id_(\w+)/).flatten.uniq.sort - } + src = File.open(path) {|f| f.read} + ids2 = src.scan(/ID\s+ripper_id_(\w+)/).flatten.uniq.sort + diff = src.scan(/set_id2\((\w+)\);/).flatten - ids2 + unless diff.empty? + abort "missing scanner IDs: #{diff}" + end + return ids2 end main