Class: Rubinius::ToolSet.current::TS::Melbourne

Inherits:
Object
  • Object
show all
Defined in:
lib/rubinius/processor/processor.rb

Overview

TODO: This will change to: class Processor

Direct Known Subclasses

Melbourne19

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

TODO: remove when all processors are defined



22
23
24
# File 'lib/rubinius/processor/processor.rb', line 22

def method_missing(sym, *args)
  puts " *** missing #{sym} #{args.map { |x| x.inspect}.join(", ")}"
end

Instance Method Details

#process_alias(line, to, from) ⇒ Object

Processing methods



29
30
31
# File 'lib/rubinius/processor/processor.rb', line 29

def process_alias(line, to, from)
  AST::Alias.new line, to, from
end

#process_and(line, left, right) ⇒ Object



33
34
35
# File 'lib/rubinius/processor/processor.rb', line 33

def process_and(line, left, right)
  AST::And.new line, left, right
end

#process_args(line, args, defaults, splat) ⇒ Object



37
38
39
# File 'lib/rubinius/processor/processor.rb', line 37

def process_args(line, args, defaults, splat)
  AST::FormalArguments.new line, args, defaults, splat
end

#process_argscat(line, array, rest) ⇒ Object



41
42
43
# File 'lib/rubinius/processor/processor.rb', line 41

def process_argscat(line, array, rest)
  AST::ConcatArgs.new line, array, rest
end

#process_argspush(line, arguments, value) ⇒ Object



45
46
47
# File 'lib/rubinius/processor/processor.rb', line 45

def process_argspush(line, arguments, value)
  AST::PushArgs.new line, arguments, value
end

#process_array(line, array) ⇒ Object



49
50
51
# File 'lib/rubinius/processor/processor.rb', line 49

def process_array(line, array)
  AST::ArrayLiteral.new line, array
end

#process_attrasgn(line, receiver, name, arguments) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/rubinius/processor/processor.rb', line 53

def process_attrasgn(line, receiver, name, arguments)
  if name == :[]=
    AST::ElementAssignment.new line, receiver, arguments
  else
    AST::AttributeAssignment.new line, receiver, name, arguments
  end
end

#process_back_ref(line, ref) ⇒ Object



61
62
63
# File 'lib/rubinius/processor/processor.rb', line 61

def process_back_ref(line, ref)
  AST::BackRef.new line, ref
end

#process_begin(line, body) ⇒ Object



65
66
67
# File 'lib/rubinius/processor/processor.rb', line 65

def process_begin(line, body)
  AST::Begin.new line, body
end

#process_block(line, array) ⇒ Object



69
70
71
# File 'lib/rubinius/processor/processor.rb', line 69

def process_block(line, array)
  AST::Block.new line, array
end

#process_block_arg(line, name) ⇒ Object



73
74
75
# File 'lib/rubinius/processor/processor.rb', line 73

def process_block_arg(line, name)
  AST::BlockArgument.new line, name
end

#process_block_pass(line, method_send, body) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/rubinius/processor/processor.rb', line 77

def process_block_pass(line, method_send, body)
  node = AST::BlockPass.new line, body
  if method_send
    method_send.block = node
    method_send
  else
    node
  end
end

#process_break(line, value) ⇒ Object



87
88
89
# File 'lib/rubinius/processor/processor.rb', line 87

def process_break(line, value)
  AST::Break.new line, value
end

#process_call(line, receiver, name, arguments) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rubinius/processor/processor.rb', line 91

def process_call(line, receiver, name, arguments)
  if arguments.kind_of? AST::BlockPass
    block = arguments
    arguments = block.arguments
    block.arguments = nil
  else
    block = nil
  end

  if node = process_transforms(line, receiver, name, arguments)
    node.block = block if block
    return node
  end

  if arguments
    node = AST::SendWithArguments.new line, receiver, name, arguments
  else
    node = AST::Send.new line, receiver, name
  end

  node.block = block
  node
end

#process_case(line, receiver, whens, else_body) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/rubinius/processor/processor.rb', line 115

def process_case(line, receiver, whens, else_body)
  if receiver
    AST::ReceiverCase.new line, receiver, whens, else_body
  else
    AST::Case.new line, whens, else_body
  end
end

#process_cdecl(line, expr, value) ⇒ Object



123
124
125
# File 'lib/rubinius/processor/processor.rb', line 123

def process_cdecl(line, expr, value)
  AST::ConstantAssignment.new line, expr, value
end

#process_class(line, name, superclass, body) ⇒ Object



127
128
129
# File 'lib/rubinius/processor/processor.rb', line 127

def process_class(line, name, superclass, body)
  AST::Class.new line, name, superclass, body
end

#process_colon2(line, outer, name) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rubinius/processor/processor.rb', line 131

def process_colon2(line, outer, name)
  if outer
    if outer.kind_of? AST::ConstantAccess and
       outer.name == :Rubinius
      case name
      when :Type
        AST::TypeConstant.new line
      when :Mirror
        AST::MirrorConstant.new line
      else
        AST::ScopedConstant.new line, outer, name
      end
    else
      AST::ScopedConstant.new line, outer, name
    end
  else
    AST::ConstantAccess.new line, name
  end
end

#process_colon3(line, name) ⇒ Object



151
152
153
# File 'lib/rubinius/processor/processor.rb', line 151

def process_colon3(line, name)
  AST::ToplevelConstant.new line, name
end

#process_const(line, name) ⇒ Object



155
156
157
# File 'lib/rubinius/processor/processor.rb', line 155

def process_const(line, name)
  AST::ConstantAccess.new line, name
end

#process_cvar(line, name) ⇒ Object



159
160
161
# File 'lib/rubinius/processor/processor.rb', line 159

def process_cvar(line, name)
  AST::ClassVariableAccess.new line, name
end

#process_cvasgn(line, name, value) ⇒ Object



163
164
165
# File 'lib/rubinius/processor/processor.rb', line 163

def process_cvasgn(line, name, value)
  AST::ClassVariableAssignment.new line, name, value
end

#process_cvdecl(line, name, value) ⇒ Object



167
168
169
# File 'lib/rubinius/processor/processor.rb', line 167

def process_cvdecl(line, name, value)
  AST::ClassVariableDeclaration.new line, name, value
end

#process_dangling_nodeObject



10
11
12
13
# File 'lib/rubinius/processor/processor.rb', line 10

def process_dangling_node
  puts "Processing called but node was NULL"
  # TODO: output info about the current AST node
end

#process_defined(line, expr) ⇒ Object



171
172
173
# File 'lib/rubinius/processor/processor.rb', line 171

def process_defined(line, expr)
  AST::Defined.new line, expr
end

#process_defn(line, name, body) ⇒ Object



175
176
177
# File 'lib/rubinius/processor/processor.rb', line 175

def process_defn(line, name, body)
  AST::Define.new line, name, body
end

#process_defs(line, receiver, name, body) ⇒ Object



179
180
181
# File 'lib/rubinius/processor/processor.rb', line 179

def process_defs(line, receiver, name, body)
  AST::DefineSingleton.new line, receiver, name, body
end

#process_dot2(line, start, finish) ⇒ Object



183
184
185
# File 'lib/rubinius/processor/processor.rb', line 183

def process_dot2(line, start, finish)
  AST::Range.new line, start, finish
end

#process_dot3(line, start, finish) ⇒ Object



187
188
189
# File 'lib/rubinius/processor/processor.rb', line 187

def process_dot3(line, start, finish)
  AST::RangeExclude.new line, start, finish
end

#process_dregx(line, str, array, flags) ⇒ Object



191
192
193
# File 'lib/rubinius/processor/processor.rb', line 191

def process_dregx(line, str, array, flags)
  AST::DynamicRegex.new line, str, array, flags
end

#process_dregx_once(line, str, array, flags) ⇒ Object



195
196
197
# File 'lib/rubinius/processor/processor.rb', line 195

def process_dregx_once(line, str, array, flags)
  AST::DynamicOnceRegex.new line, str, array, flags
end

#process_dstr(line, str, array) ⇒ Object



199
200
201
# File 'lib/rubinius/processor/processor.rb', line 199

def process_dstr(line, str, array)
  AST::DynamicString.new line, str, array
end

#process_dsym(line, str, array) ⇒ Object



203
204
205
# File 'lib/rubinius/processor/processor.rb', line 203

def process_dsym(line, str, array)
  AST::DynamicSymbol.new line, str, array
end

#process_dxstr(line, str, array) ⇒ Object



207
208
209
# File 'lib/rubinius/processor/processor.rb', line 207

def process_dxstr(line, str, array)
  AST::DynamicExecuteString.new line, str, array
end

#process_ensure(line, body, ensr) ⇒ Object



211
212
213
# File 'lib/rubinius/processor/processor.rb', line 211

def process_ensure(line, body, ensr)
  AST::Ensure.new line, body, ensr
end

#process_evstr(line, value) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/rubinius/processor/processor.rb', line 215

def process_evstr(line, value)
  if value
    AST::ToString.new line, value
  else
    AST::StringLiteral.new line, ""
  end
end

#process_false(line) ⇒ Object



223
224
225
# File 'lib/rubinius/processor/processor.rb', line 223

def process_false(line)
  AST::FalseLiteral.new line
end

#process_fcall(line, name, arguments) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rubinius/processor/processor.rb', line 227

def process_fcall(line, name, arguments)
  receiver = AST::Self.new line

  if arguments.kind_of? AST::BlockPass
    block = arguments
    arguments = block.arguments
    block.arguments = nil
  else
    block = nil
  end

  if node = process_transforms(line, receiver, name, arguments, true)
    node.block = block if block
    return node
  end

  if arguments
    node = AST::SendWithArguments.new line, receiver, name, arguments, true
  else
    node = AST::Send.new line, receiver, name, true
  end

  node.block = block
  node
end

#process_file(line) ⇒ Object



253
254
255
# File 'lib/rubinius/processor/processor.rb', line 253

def process_file(line)
  AST::File.new line
end

#process_fixnum(line, value) ⇒ Object



257
258
259
# File 'lib/rubinius/processor/processor.rb', line 257

def process_fixnum(line, value)
  AST::FixnumLiteral.new line, value
end

#process_flip2(line, start, finish) ⇒ Object



261
262
263
# File 'lib/rubinius/processor/processor.rb', line 261

def process_flip2(line, start, finish)
  AST::Flip2.new line, start, finish
end

#process_flip3(line, start, finish) ⇒ Object



265
266
267
# File 'lib/rubinius/processor/processor.rb', line 265

def process_flip3(line, start, finish)
  AST::Flip3.new line, start, finish
end

#process_float(line, str) ⇒ Object



269
270
271
# File 'lib/rubinius/processor/processor.rb', line 269

def process_float(line, str)
  AST::FloatLiteral.new line, str
end

#process_for(line, iter, arguments, body) ⇒ Object



273
274
275
276
277
# File 'lib/rubinius/processor/processor.rb', line 273

def process_for(line, iter, arguments, body)
  method_send = AST::Send.new line, iter, :each
  method_send.block = AST::For.new line, arguments, body
  method_send
end

#process_gasgn(line, name, expr) ⇒ Object



279
280
281
# File 'lib/rubinius/processor/processor.rb', line 279

def process_gasgn(line, name, expr)
  AST::GlobalVariableAssignment.new line, name, expr
end

#process_gvar(line, name) ⇒ Object



283
284
285
# File 'lib/rubinius/processor/processor.rb', line 283

def process_gvar(line, name)
  AST::GlobalVariableAccess.for_name line, name
end

#process_hash(line, array) ⇒ Object



287
288
289
# File 'lib/rubinius/processor/processor.rb', line 287

def process_hash(line, array)
  AST::HashLiteral.new line, array
end

#process_iasgn(line, name, value) ⇒ Object



291
292
293
# File 'lib/rubinius/processor/processor.rb', line 291

def process_iasgn(line, name, value)
  AST::InstanceVariableAssignment.new line, name, value
end

#process_if(line, cond, body, else_body) ⇒ Object



295
296
297
# File 'lib/rubinius/processor/processor.rb', line 295

def process_if(line, cond, body, else_body)
  AST::If.new line, cond, body, else_body
end

#process_iter(line, method_send, arguments, body) ⇒ Object



299
300
301
302
# File 'lib/rubinius/processor/processor.rb', line 299

def process_iter(line, method_send, arguments, body)
  method_send.block = AST::Iter.new line, arguments, body
  method_send
end

#process_ivar(line, name) ⇒ Object



304
305
306
# File 'lib/rubinius/processor/processor.rb', line 304

def process_ivar(line, name)
  AST::InstanceVariableAccess.new line, name
end

#process_lasgn(line, name, value) ⇒ Object



308
309
310
# File 'lib/rubinius/processor/processor.rb', line 308

def process_lasgn(line, name, value)
  AST::LocalVariableAssignment.new line, name, value
end

#process_lit(line, sym) ⇒ Object



312
313
314
# File 'lib/rubinius/processor/processor.rb', line 312

def process_lit(line, sym)
  AST::SymbolLiteral.new line, sym
end

#process_lvar(line, name) ⇒ Object



316
317
318
# File 'lib/rubinius/processor/processor.rb', line 316

def process_lvar(line, name)
  AST::LocalVariableAccess.new line, name
end

#process_masgn(line, left, right, splat) ⇒ Object



320
321
322
# File 'lib/rubinius/processor/processor.rb', line 320

def process_masgn(line, left, right, splat)
  AST::MultipleAssignment.new line, left, right, splat
end

#process_match(line, pattern, flags) ⇒ Object



324
325
326
# File 'lib/rubinius/processor/processor.rb', line 324

def process_match(line, pattern, flags)
  AST::Match.new line, pattern, flags
end

#process_match2(line, pattern, value) ⇒ Object



328
329
330
# File 'lib/rubinius/processor/processor.rb', line 328

def process_match2(line, pattern, value)
  AST::Match2.new line, pattern, value
end

#process_match3(line, pattern, value) ⇒ Object



332
333
334
# File 'lib/rubinius/processor/processor.rb', line 332

def process_match3(line, pattern, value)
  AST::Match3.new line, pattern, value
end

#process_missing_node(line, node_name, node_type) ⇒ Object

This method is analogous to #method_missing. It is called if there is no processing method defined for a node.



17
18
19
# File 'lib/rubinius/processor/processor.rb', line 17

def process_missing_node(line, node_name, node_type)
  puts "Unhandled node #{node_name} (#{node_type})"
end

#process_module(line, name, body) ⇒ Object



336
337
338
# File 'lib/rubinius/processor/processor.rb', line 336

def process_module(line, name, body)
  AST::Module.new line, name, body
end

#process_negate(line, value) ⇒ Object



340
341
342
# File 'lib/rubinius/processor/processor.rb', line 340

def process_negate(line, value)
  AST::Negate.new line, value
end

#process_next(line, value) ⇒ Object



344
345
346
# File 'lib/rubinius/processor/processor.rb', line 344

def process_next(line, value)
  AST::Next.new line, value
end

#process_nil(line) ⇒ Object



348
349
350
# File 'lib/rubinius/processor/processor.rb', line 348

def process_nil(line)
  AST::NilLiteral.new line
end

#process_not(line, value) ⇒ Object



352
353
354
# File 'lib/rubinius/processor/processor.rb', line 352

def process_not(line, value)
  AST::Not.new line, value
end

#process_nth_ref(line, ref) ⇒ Object



356
357
358
# File 'lib/rubinius/processor/processor.rb', line 356

def process_nth_ref(line, ref)
  AST::NthRef.new line, ref
end

#process_number(line, base, str) ⇒ Object

TODO: Fix the way 1.8 parser handles this



361
362
363
364
365
366
367
368
369
# File 'lib/rubinius/processor/processor.rb', line 361

def process_number(line, base, str)
  value = str.to_i base
  case value
  when Fixnum
    AST::FixnumLiteral.new line, value
  when Bignum
    AST::NumberLiteral.new line, value
  end
end

#process_op_asgn1(line, receiver, index, op, value) ⇒ Object



371
372
373
# File 'lib/rubinius/processor/processor.rb', line 371

def process_op_asgn1(line, receiver, index, op, value)
  AST::OpAssign1.new line, receiver, index, op, value
end

#process_op_asgn2(line, receiver, name, op, value) ⇒ Object



375
376
377
# File 'lib/rubinius/processor/processor.rb', line 375

def process_op_asgn2(line, receiver, name, op, value)
  AST::OpAssign2.new line, receiver, name, op, value
end

#process_op_asgn_and(line, var, value) ⇒ Object



379
380
381
# File 'lib/rubinius/processor/processor.rb', line 379

def process_op_asgn_and(line, var, value)
  AST::OpAssignAnd.new line, var, value
end

#process_op_asgn_or(line, var, value) ⇒ Object



383
384
385
# File 'lib/rubinius/processor/processor.rb', line 383

def process_op_asgn_or(line, var, value)
  AST::OpAssignOr.new line, var, value
end

#process_or(line, left, right) ⇒ Object



387
388
389
# File 'lib/rubinius/processor/processor.rb', line 387

def process_or(line, left, right)
  AST::Or.new line, left, right
end

#process_parse_error(message, column, line, source) ⇒ Object



5
6
7
8
# File 'lib/rubinius/processor/processor.rb', line 5

def process_parse_error(message, column, line, source)
  msg = "#{message}: #{@name}:#{line}:#{column}"
  @syntax_errors << SyntaxError.from(msg, column, line, source, @name)
end

#process_postexe(line) ⇒ Object



391
392
393
# File 'lib/rubinius/processor/processor.rb', line 391

def process_postexe(line)
  AST::Send.new line, AST::Self.new(line), :at_exit, true
end

#process_preexe(line) ⇒ Object



395
396
397
398
399
# File 'lib/rubinius/processor/processor.rb', line 395

def process_preexe(line)
  node = AST::PreExe.new line
  add_pre_exe node
  node
end

#process_redo(line) ⇒ Object



401
402
403
# File 'lib/rubinius/processor/processor.rb', line 401

def process_redo(line)
  AST::Redo.new line
end

#process_regex(line, str, flags) ⇒ Object



405
406
407
# File 'lib/rubinius/processor/processor.rb', line 405

def process_regex(line, str, flags)
  AST::RegexLiteral.new line, str, flags
end

#process_resbody(line, conditions, body, nxt) ⇒ Object



409
410
411
# File 'lib/rubinius/processor/processor.rb', line 409

def process_resbody(line, conditions, body, nxt)
  AST::RescueCondition.new line, conditions, body, nxt
end

#process_rescue(line, body, rescue_body, else_body) ⇒ Object



413
414
415
# File 'lib/rubinius/processor/processor.rb', line 413

def process_rescue(line, body, rescue_body, else_body)
  AST::Rescue.new line, body, rescue_body, else_body
end

#process_retry(line) ⇒ Object



417
418
419
# File 'lib/rubinius/processor/processor.rb', line 417

def process_retry(line)
  AST::Retry.new line
end

#process_return(line, value) ⇒ Object



421
422
423
# File 'lib/rubinius/processor/processor.rb', line 421

def process_return(line, value)
  AST::Return.new line, value
end

#process_sclass(line, receiver, body) ⇒ Object



425
426
427
# File 'lib/rubinius/processor/processor.rb', line 425

def process_sclass(line, receiver, body)
  AST::SClass.new line, receiver, body
end

#process_scope(line, body) ⇒ Object



429
430
431
432
433
434
435
# File 'lib/rubinius/processor/processor.rb', line 429

def process_scope(line, body)
  if body.kind_of? AST::Block
    body
  elsif body
    AST::Block.new line, [body]
  end
end

#process_self(line) ⇒ Object



437
438
439
# File 'lib/rubinius/processor/processor.rb', line 437

def process_self(line)
  AST::Self.new line
end

#process_splat(line, expr) ⇒ Object



441
442
443
# File 'lib/rubinius/processor/processor.rb', line 441

def process_splat(line, expr)
  AST::SplatValue.new line, expr
end

#process_str(line, str) ⇒ Object



445
446
447
# File 'lib/rubinius/processor/processor.rb', line 445

def process_str(line, str)
  AST::StringLiteral.new line, str
end

#process_super(line, arguments) ⇒ Object



449
450
451
# File 'lib/rubinius/processor/processor.rb', line 449

def process_super(line, arguments)
  AST::Super.new line, arguments
end

#process_svalue(line, expr) ⇒ Object



453
454
455
# File 'lib/rubinius/processor/processor.rb', line 453

def process_svalue(line, expr)
  AST::SValue.new line, expr
end

#process_to_ary(line, expr) ⇒ Object



457
458
459
# File 'lib/rubinius/processor/processor.rb', line 457

def process_to_ary(line, expr)
  AST::ToArray.new line, expr
end

#process_true(line) ⇒ Object



461
462
463
# File 'lib/rubinius/processor/processor.rb', line 461

def process_true(line)
  AST::TrueLiteral.new line
end

#process_undef(line, sym) ⇒ Object



465
466
467
# File 'lib/rubinius/processor/processor.rb', line 465

def process_undef(line, sym)
  AST::Undef.new line, sym
end

#process_until(line, cond, body, check_first) ⇒ Object



469
470
471
# File 'lib/rubinius/processor/processor.rb', line 469

def process_until(line, cond, body, check_first)
  AST::Until.new line, cond, body, check_first
end

#process_valias(line, to, from) ⇒ Object



483
484
485
# File 'lib/rubinius/processor/processor.rb', line 483

def process_valias(line, to, from)
  AST::VAlias.new line, to, from
end

#process_values(line, first, rest) ⇒ Object



487
488
489
490
# File 'lib/rubinius/processor/processor.rb', line 487

def process_values(line, first, rest)
  rest.body.unshift first
  rest
end

#process_vcall(line, name) ⇒ Object



473
474
475
476
477
478
479
480
481
# File 'lib/rubinius/processor/processor.rb', line 473

def process_vcall(line, name)
  receiver = AST::Self.new line

  if node = process_transforms(line, receiver, name, nil, true)
    return node
  end

  AST::Send.new line, receiver, name, true, true
end

#process_when(line, conditions, body) ⇒ Object



492
493
494
# File 'lib/rubinius/processor/processor.rb', line 492

def process_when(line, conditions, body)
  AST::When.new line, conditions, body
end

#process_while(line, cond, body, check_first) ⇒ Object



496
497
498
# File 'lib/rubinius/processor/processor.rb', line 496

def process_while(line, cond, body, check_first)
  AST::While.new line, cond, body, check_first
end

#process_xstr(line, str) ⇒ Object



500
501
502
# File 'lib/rubinius/processor/processor.rb', line 500

def process_xstr(line, str)
  AST::ExecuteString.new line, str
end

#process_yield(line, arguments, unwrap) ⇒ Object



504
505
506
# File 'lib/rubinius/processor/processor.rb', line 504

def process_yield(line, arguments, unwrap)
  AST::Yield.new line, arguments, unwrap
end

#process_zarray(line) ⇒ Object



508
509
510
# File 'lib/rubinius/processor/processor.rb', line 508

def process_zarray(line)
  AST::EmptyArray.new line
end

#process_zsuper(line) ⇒ Object



512
513
514
# File 'lib/rubinius/processor/processor.rb', line 512

def process_zsuper(line)
  AST::ZSuper.new line
end