Class: Metal::Generator::OrSet

Inherits:
Object
  • Object
show all
Defined in:
lib/metal/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(and_sets) ⇒ OrSet

Returns a new instance of OrSet.



214
215
216
# File 'lib/metal/generator.rb', line 214

def initialize(and_sets)
  @and_sets = and_sets
end

Instance Method Details

#generate(ctx, source) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/metal/generator.rb', line 220

def generate(ctx, source)
  if @and_sets.length <= 1
    # optimize
    @and_sets.each {|and_set|
      and_set.generate(ctx, source)
    }
  else
    objs = []
    @and_sets.each {|and_set|
      obj = ctx.rule.with_lambda(source) {
        and_set.generate(ctx, source)
      }
      objs.push obj
    }
    set_name = "#{objs.first}_or"
    source << "Lambda* #{set_name}[] = {\n"
      objs.each {|obj|
        source << "&#{obj},\n"
      }
      source << "NULL\n"
    source << "};\n"
    source << "ctx->act_or(#{set_name});\n"
  end
end

#preprocess(ctx) ⇒ Object



217
218
219
# File 'lib/metal/generator.rb', line 217

def preprocess(ctx)
  @and_sets.each {|and_set| and_set.preprocess(ctx) }
end