Sha256: 7b9a354915ed4901d1bc0d03a55f30e0557d79524a4737d18e45e2e49c7ecfa1

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

require 'sfrp/flat/elements'
require 'sfrp/flat/exception'
require 'sfrp/flat/expression'
require 'sfrp/flat/dsl'

module SFRP
  module Flat
    class Set
      def initialize(&block)
        @funcs = []
        @tconsts = []
        @vconsts = []
        @nodes = []
        @output_node_strs = []
        @init_func_strs = []
        block.call(self) if block
      end

      def to_poly
        Poly::Set.new do |dest_set|
          (@funcs + @tconsts + @vconsts + @nodes).each do |element|
            element.to_poly(self, dest_set)
          end
          @output_node_strs.each { |s| dest_set.append_output_node_str(s) }
          @init_func_strs.each { |s| dest_set.append_init_func_str(s) }
        end
      end

      def append_output_node_str(node_str)
        @output_node_strs << node_str
      end

      def append_init_func_str(init_func_str)
        @init_func_strs << init_func_str
      end

      def <<(element)
        case element
        when Function
          @funcs << element
        when TConst
          @tconsts << element
        when VConst
          @vconsts << element
        when Node
          @nodes << element
        else
          raise
        end
      end

      def tconst(str)
        @tconsts.find { |tconst| tconst.str == str }
      end

      def node(str)
        @nodes.find { |node| node.str == str }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sfrp-1.5.2 lib/sfrp/flat/set.rb
sfrp-1.5.1 lib/sfrp/flat/set.rb
sfrp-1.5.0 lib/sfrp/flat/set.rb
sfrp-1.4.0 lib/sfrp/flat/set.rb
sfrp-1.2.1 lib/sfrp/flat/set.rb
sfrp-1.2.0 lib/sfrp/flat/set.rb
sfrp-1.1.0 lib/sfrp/flat/set.rb