Method: Emfrp::TypeDef#marker_gen

Defined in:
lib/emfrp/compile/c/syntax_codegen.rb

#marker_gen(ct) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 159

def marker_gen(ct)
  return if enum?(ct)
  params = [[ref_name(ct), "x"], ["int", "mark"]]
  ct.define_func("void", marker_func_name(ct), params) do |x|
    x << "if (mark > x->mark) { x->mark = mark; }" unless self[:static]
    accessor = self[:static] ? "." : "->"
    cases = []
    self[:tvalues].each_with_index do |tvalue, i|
      calls = []
      tvalue[:params].each_with_index do |param, i|
        if ct.tdef(param).is_a?(TypeDef) && !ct.tdef(param).enum?(ct)
          fn = ct.tdef(param).marker_func_name(ct)
          calls << "#{fn}(x#{accessor}value.#{tvalue.struct_name(ct)}.member#{i}, mark);"
        end
      end
      cases << "case #{i}: #{calls.join(" ")} break;" if calls.size > 0
    end
    if cases.size > 0
      switch_exp = self[:tvalues].size == 1 ? "0" : "x#{accessor}tvalue_id"
      x << ct.make_block("switch (#{switch_exp}) {", cases, "}")
    end
  end
end