Skip to content

Commit 3ae4449

Browse files
author
aamine
committed
* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.
* ext/racc/cparse/cparse.c: should mark CparseParams objects. * lib/racc/parser.rb: sync with original code, rev 1.8. * lib/racc/parser.rb: update coding style. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 3ae5361 commit 3ae4449

File tree

3 files changed

+98
-56
lines changed

3 files changed

+98
-56
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Thu Jul 6 22:17:21 2006 Minero Aoki <aamine@loveruby.net>
2+
3+
* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.
4+
5+
* ext/racc/cparse/cparse.c: should mark CparseParams objects.
6+
7+
* lib/racc/parser.rb: sync with original code, rev 1.8.
8+
9+
* lib/racc/parser.rb: update coding style.
10+
111
Mon Jul 3 19:04:38 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
212

313
* ext/tk/tcltklib.c (ip_make_menu_embeddable): help to make a menu

ext/racc/cparse/cparse.c

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This library is free software.
88
You can distribute/modify this program under the same terms of ruby.
99
10-
$originalId: cparse.c,v 1.7 2006/07/02 10:02:02 aamine Exp $
10+
$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $
1111
1212
*/
1313

@@ -194,9 +194,9 @@ static VALUE lexer_i _((VALUE block_args, VALUE data, VALUE self));
194194
static VALUE assert_array _((VALUE a));
195195
static long assert_integer _((VALUE n));
196196
static VALUE assert_hash _((VALUE h));
197-
static void initialize_params _((struct cparse_params *v,
198-
VALUE parser, VALUE arg,
197+
static VALUE initialize_params _((VALUE vparams, VALUE parser, VALUE arg,
199198
VALUE lexer, VALUE lexmid));
199+
static void cparse_params_mark _((void *ptr));
200200

201201
static void parse_main _((struct cparse_params *v,
202202
VALUE tok, VALUE val, int resume));
@@ -217,12 +217,14 @@ static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
217217
static VALUE
218218
racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
219219
{
220-
struct cparse_params params;
221-
struct cparse_params *v = &params;
220+
volatile VALUE vparams;
221+
struct cparse_params *v;
222222

223+
vparams = Data_Make_Struct(CparseParams, struct cparse_params,
224+
cparse_params_mark, -1, v);
223225
D_puts("starting cparse");
224226
v->sys_debug = RTEST(sysdebug);
225-
initialize_params(v, parser, arg, Qnil, Qnil);
227+
vparams = initialize_params(vparams, parser, arg, Qnil, Qnil);
226228
v->lex_is_iterator = Qfalse;
227229
parse_main(v, Qnil, Qnil, 0);
228230

@@ -232,12 +234,14 @@ racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
232234
static VALUE
233235
racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
234236
{
235-
struct cparse_params params;
236-
struct cparse_params *v = &params;
237+
volatile VALUE vparams;
238+
struct cparse_params *v;
237239

240+
vparams = Data_Make_Struct(CparseParams, struct cparse_params,
241+
cparse_params_mark, -1, v);
238242
v->sys_debug = RTEST(sysdebug);
239243
D_puts("start C yyparse");
240-
initialize_params(v, parser, arg, lexer, lexmid);
244+
vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
241245
v->lex_is_iterator = Qtrue;
242246
D_puts("params initialized");
243247
parse_main(v, Qnil, Qnil, 0);
@@ -310,12 +314,13 @@ assert_integer(VALUE n)
310314
return NUM2LONG(n);
311315
}
312316

313-
static void
314-
initialize_params(struct cparse_params *v,
315-
VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
317+
static VALUE
318+
initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
316319
{
317-
v->value_v = Data_Wrap_Struct(CparseParams, 0, 0, v);
320+
struct cparse_params *v;
318321

322+
Data_Get_Struct(vparams, struct cparse_params, v);
323+
v->value_v = vparams;
319324
v->parser = parser;
320325
v->lexer = lexer;
321326
if (! NIL_P(lexmid))
@@ -360,6 +365,45 @@ initialize_params(struct cparse_params *v,
360365
v->fin = 0;
361366

362367
v->lex_is_iterator = Qfalse;
368+
369+
rb_iv_set(parser, "@vstack", v->vstack);
370+
if (v->debug) {
371+
rb_iv_set(parser, "@tstack", v->tstack);
372+
}
373+
else {
374+
rb_iv_set(parser, "@tstack", Qnil);
375+
}
376+
377+
return vparams;
378+
}
379+
380+
static void
381+
cparse_params_mark(void *ptr)
382+
{
383+
struct cparse_params *v = (struct cparse_params*)ptr;
384+
385+
rb_gc_mark(v->value_v);
386+
rb_gc_mark(v->parser);
387+
rb_gc_mark(v->lexer);
388+
rb_gc_mark(v->action_table);
389+
rb_gc_mark(v->action_check);
390+
rb_gc_mark(v->action_default);
391+
rb_gc_mark(v->action_pointer);
392+
rb_gc_mark(v->goto_table);
393+
rb_gc_mark(v->goto_check);
394+
rb_gc_mark(v->goto_default);
395+
rb_gc_mark(v->goto_pointer);
396+
rb_gc_mark(v->goto_pointer);
397+
rb_gc_mark(v->goto_pointer);
398+
rb_gc_mark(v->goto_pointer);
399+
rb_gc_mark(v->goto_pointer);
400+
rb_gc_mark(v->reduce_table);
401+
rb_gc_mark(v->token_table);
402+
rb_gc_mark(v->state);
403+
rb_gc_mark(v->vstack);
404+
rb_gc_mark(v->tstack);
405+
rb_gc_mark(v->t);
406+
rb_gc_mark(v->retval);
363407
}
364408

365409
static void
@@ -446,8 +490,10 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
446490
extract_user_token(v, tmp, &tok, &val);
447491
}
448492
/* convert token */
449-
tmp = rb_hash_aref(v->token_table, tok);
450-
v->t = NIL_P(tmp) ? vERROR_TOKEN : tmp;
493+
v->t = rb_hash_aref(v->token_table, tok);
494+
if (NIL_P(v->t)) {
495+
v->t = vERROR_TOKEN;
496+
}
451497
D_printf("(act) t(k2)=%ld\n", NUM2LONG(v->t));
452498
if (v->debug) {
453499
rb_funcall(v->parser, id_d_read_token,
@@ -765,7 +811,7 @@ Init_cparse(void)
765811
rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
766812
rb_str_new2(RACC_VERSION));
767813
rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
768-
rb_str_new2("$originalId: cparse.c,v 1.7 2006/07/02 10:02:02 aamine Exp $"));
814+
rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
769815

770816
CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);
771817

lib/racc/parser.rb

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
2-
# parser.rb
2+
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
33
#
4-
# Copyright (c) 1999-2003 Minero Aoki <aamine@loveruby.net>
4+
# Copyright (c) 1999-2006 Minero Aoki
55
#
66
# This program is free software.
77
# You can distribute/modify this program under the same terms of ruby.
@@ -10,8 +10,6 @@
1010
# into a Racc output file, you may use that output file
1111
# without restriction.
1212
#
13-
# $raccId: parser.rb,v 1.4 2003/11/03 13:41:47 aamine Exp $
14-
#
1513

1614
unless defined?(NotImplementedError)
1715
NotImplementedError = NotImplementError
@@ -24,7 +22,6 @@ class ParseError < StandardError; end
2422
ParseError = Racc::ParseError
2523
end
2624

27-
2825
module Racc
2926

3027
unless defined?(Racc_No_Extentions)
@@ -33,14 +30,14 @@ module Racc
3330

3431
class Parser
3532

36-
Racc_Runtime_Version = '1.4.4'
37-
Racc_Runtime_Revision = '$raccRevision: 1.4 $'.split[1]
33+
Racc_Runtime_Version = '1.4.5'
34+
Racc_Runtime_Revision = '$originalRevision: 1.8 $'.split[1]
3835

39-
Racc_Runtime_Core_Version_R = '1.4.4'
40-
Racc_Runtime_Core_Revision_R = '$raccRevision: 1.4 $'.split[1]
36+
Racc_Runtime_Core_Version_R = '1.4.5'
37+
Racc_Runtime_Core_Revision_R = '$originalRevision: 1.8 $'.split[1]
4138
begin
4239
require 'racc/cparse'
43-
# Racc_Runtime_Core_Version_C = (defined in extension)
40+
# Racc_Runtime_Core_Version_C = (defined in extention)
4441
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
4542
unless new.respond_to?(:_racc_do_parse_c, true)
4643
raise LoadError, 'old cparse.so'
@@ -106,7 +103,7 @@ def next_token
106103
raise NotImplementedError, "#{self.class}\#next_token is not defined"
107104
end
108105

109-
def _racc_do_parse_rb( arg, in_debug )
106+
def _racc_do_parse_rb(arg, in_debug)
110107
action_table, action_check, action_default, action_pointer,
111108
goto_table, goto_check, goto_default, goto_pointer,
112109
nt_base, reduce_table, token_table, shift_n,
@@ -151,11 +148,11 @@ def _racc_do_parse_rb( arg, in_debug )
151148
### yyparse
152149
###
153150

154-
def yyparse( recv, mid )
151+
def yyparse(recv, mid)
155152
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
156153
end
157154

158-
def _racc_yyparse_rb( recv, mid, arg, c_debug )
155+
def _racc_yyparse_rb(recv, mid, arg, c_debug)
159156
action_table, action_check, action_default, action_pointer,
160157
goto_table, goto_check, goto_default, goto_pointer,
161158
nt_base, reduce_table, token_table, shift_n,
@@ -174,7 +171,6 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
174171
end
175172
end
176173
recv.__send__(mid) do |tok, val|
177-
# $stderr.puts "rd: tok=#{tok}, val=#{val}"
178174
unless tok
179175
@racc_t = 0
180176
else
@@ -188,12 +184,7 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
188184
act = action_table[i] and
189185
action_check[i] == @racc_state[-1]
190186
act = action_default[@racc_state[-1]]
191-
# $stderr.puts "02: act=#{act}"
192-
# $stderr.puts "curstate=#{@racc_state[-1]}"
193-
else
194-
# $stderr.puts "01: act=#{act}"
195187
end
196-
197188
while act = _racc_evalact(act, arg)
198189
;
199190
end
@@ -206,9 +197,6 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
206197
act = action_table[i] and
207198
action_check[i] == @racc_state[-1]
208199
act = action_default[@racc_state[-1]]
209-
# $stderr.puts "04: act=#{act}"
210-
else
211-
# $stderr.puts "03: act=#{act}"
212200
end
213201
while act = _racc_evalact(act, arg)
214202
;
@@ -222,13 +210,12 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
222210
### common
223211
###
224212

225-
def _racc_evalact( act, arg )
226-
# $stderr.puts "ea: act=#{act}"
213+
def _racc_evalact(act, arg)
227214
action_table, action_check, action_default, action_pointer,
228215
goto_table, goto_check, goto_default, goto_pointer,
229216
nt_base, reduce_table, token_table, shift_n,
230217
reduce_n, use_result, * = arg
231-
nerr = 0 # tmp
218+
nerr = 0 # tmp
232219

233220
if act > 0 and act < shift_n
234221
#
@@ -261,7 +248,7 @@ def _racc_evalact( act, arg )
261248
when 2 # yyaccept
262249
return shift_n
263250
else
264-
raise RuntimeError, '[Racc Bug] unknown jump code'
251+
raise '[Racc Bug] unknown jump code'
265252
end
266253
end
267254

@@ -299,7 +286,6 @@ def _racc_evalact( act, arg )
299286
break
300287
end
301288
end
302-
303289
throw :racc_end_parse, nil if @racc_state.size <= 1
304290
@racc_state.pop
305291
@racc_vstack.pop
@@ -311,15 +297,15 @@ def _racc_evalact( act, arg )
311297
return act
312298

313299
else
314-
raise RuntimeError, "[Racc Bug] unknown action #{act.inspect}"
300+
raise "[Racc Bug] unknown action #{act.inspect}"
315301
end
316302

317303
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
318304

319305
nil
320306
end
321307

322-
def _racc_do_reduce( arg, act )
308+
def _racc_do_reduce(arg, act)
323309
action_table, action_check, action_default, action_pointer,
324310
goto_table, goto_check, goto_default, goto_pointer,
325311
nt_base, reduce_table, token_table, shift_n,
@@ -360,7 +346,7 @@ def _racc_do_reduce( arg, act )
360346
goto_default[k1]
361347
end
362348

363-
def on_error( t, val, vstack )
349+
def on_error(t, val, vstack)
364350
raise ParseError, sprintf("\nparse error on value %s (%s)",
365351
val.inspect, token_to_str(t) || '?')
366352
end
@@ -381,20 +367,20 @@ def yyerrok
381367
# for debugging output
382368
#
383369

384-
def racc_read_token( t, tok, val )
370+
def racc_read_token(t, tok, val)
385371
@racc_debug_out.print 'read '
386372
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
387373
@racc_debug_out.puts val.inspect
388374
@racc_debug_out.puts
389375
end
390376

391-
def racc_shift( tok, tstack, vstack )
377+
def racc_shift(tok, tstack, vstack)
392378
@racc_debug_out.puts "shift #{racc_token2str tok}"
393379
racc_print_stacks tstack, vstack
394380
@racc_debug_out.puts
395381
end
396382

397-
def racc_reduce( toks, sim, tstack, vstack )
383+
def racc_reduce(toks, sim, tstack, vstack)
398384
out = @racc_debug_out
399385
out.print 'reduce '
400386
if toks.empty?
@@ -413,20 +399,20 @@ def racc_accept
413399
@racc_debug_out.puts
414400
end
415401

416-
def racc_e_pop( state, tstack, vstack )
402+
def racc_e_pop(state, tstack, vstack)
417403
@racc_debug_out.puts 'error recovering mode: pop token'
418404
racc_print_states state
419405
racc_print_stacks tstack, vstack
420406
@racc_debug_out.puts
421407
end
422408

423-
def racc_next_state( curstate, state )
409+
def racc_next_state(curstate, state)
424410
@racc_debug_out.puts "goto #{curstate}"
425411
racc_print_states state
426412
@racc_debug_out.puts
427413
end
428414

429-
def racc_print_stacks( t, v )
415+
def racc_print_stacks(t, v)
430416
out = @racc_debug_out
431417
out.print ' ['
432418
t.each_index do |i|
@@ -435,19 +421,19 @@ def racc_print_stacks( t, v )
435421
out.puts ' ]'
436422
end
437423

438-
def racc_print_states( s )
424+
def racc_print_states(s)
439425
out = @racc_debug_out
440426
out.print ' ['
441427
s.each {|st| out.print ' ', st }
442428
out.puts ' ]'
443429
end
444430

445-
def racc_token2str( tok )
431+
def racc_token2str(tok)
446432
self.class::Racc_token_to_s_table[tok] or
447-
raise RuntimeError, "[Racc Bug] can't convert token #{tok} to string"
433+
raise "[Racc Bug] can't convert token #{tok} to string"
448434
end
449435

450-
def token_to_str( t )
436+
def token_to_str(t)
451437
self.class::Racc_token_to_s_table[t]
452438
end
453439

0 commit comments

Comments
 (0)