Class: UnsafeFuncRewriter
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- UnsafeFuncRewriter
- Defined in:
- lib/bud/rewrite.rb
Overview
Check for whether the rule invokes any “unsafe” functions (functions that might return a different value every time they are called, e.g., budtime). The test for “unsafe” functions is pretty naive: any function call with a nil receiver is treated as unsafe unless it is belongs to a list of “safe” functions (below) or it denotes a lattice identifier. In the latter case, the rule is akin to an implicit join with the lattice, so we only rescan it on deltas to the lattice (see “rescan_on_merge” in LatticeWrapper).
Although this is called a rewriter, it doesn't modify the input AST.
Constant Summary
- SAFE_FUNC_LIST =
[:int_ip_port, :ip_port, :ip, :port].to_set
Instance Attribute Summary (collapse)
-
- (Object) unsafe_func_called
readonly
Returns the value of attribute unsafe_func_called.
Instance Method Summary (collapse)
-
- (UnsafeFuncRewriter) initialize(bud_instance)
constructor
A new instance of UnsafeFuncRewriter.
- - (Boolean) is_collection_name?(op)
- - (Object) is_safe_func(op)
- - (Object) process_call(exp)
- - (Object) process_iter(exp)
- - (Object) push_and_process(exp)
Constructor Details
- (UnsafeFuncRewriter) initialize(bud_instance)
A new instance of UnsafeFuncRewriter
354 355 356 357 358 359 360 361 |
# File 'lib/bud/rewrite.rb', line 354 def initialize(bud_instance) super() self.require_empty = false self.expected = Sexp @bud_instance = bud_instance @unsafe_func_called = false @elem_stack = [] end |
Instance Attribute Details
- (Object) unsafe_func_called (readonly)
Returns the value of attribute unsafe_func_called
352 353 354 |
# File 'lib/bud/rewrite.rb', line 352 def unsafe_func_called @unsafe_func_called end |
Instance Method Details
- (Boolean) is_collection_name?(op)
391 392 393 |
# File 'lib/bud/rewrite.rb', line 391 def is_collection_name?(op) @bud_instance.tables.has_key?(op.to_sym) || @bud_instance.lattices.has_key?(op.to_sym) end |
- (Object) is_safe_func(op)
395 396 397 |
# File 'lib/bud/rewrite.rb', line 395 def is_safe_func(op) SAFE_FUNC_LIST.include? op end |
- (Object) process_call(exp)
363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/bud/rewrite.rb', line 363 def process_call(exp) tag, recv, op, *args = exp # We assume that unsafe funcs have a nil receiver (Bud instance is implicit # receiver). if recv.nil? and @elem_stack.size > 0 unless is_safe_func(op) || is_collection_name?(op) @unsafe_func_called = true end end return s(tag, process(recv), op, *(args.map{|a| process(a)})) end |
- (Object) process_iter(exp)
377 378 379 380 381 |
# File 'lib/bud/rewrite.rb', line 377 def process_iter(exp) tag, recv, iter_args, body = exp new_body = push_and_process(body) return s(tag, process(recv), process(iter_args), new_body) end |
- (Object) push_and_process(exp)
383 384 385 386 387 388 389 |
# File 'lib/bud/rewrite.rb', line 383 def push_and_process(exp) obj_id = exp.object_id @elem_stack.push(obj_id) rv = process(exp) raise Bud::Error unless @elem_stack.pop == obj_id return rv end |