Module: CSquare::Indexable::InstanceMethods
- Defined in:
- lib/csquare.rb
Instance Method Summary collapse
- #declare_inline_source(enumeree) ⇒ Object
-
#decorated_call(name, type_symbol) ⇒ Object
Given some function call, see if it needs to be decorated.
- #expand_options(options) ⇒ Object
- #force_decorated_call(name, type_symbol) ⇒ Object
- #get_binding ⇒ Object
- #index(basename, options_and_mappings = {}) ⇒ Object
-
#inline_op_function_name(op) ⇒ Object
TODO: Change the 2 to be the number of arguments it takes or something more indicative.
- #preprocess_source(file) ⇒ Object
-
#read_and_parse_source(source) ⇒ Object
TODO: Unify caches between Generator and Blueprint.
- #template_keys(source) ⇒ Object
Instance Method Details
#declare_inline_source(enumeree) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/csquare.rb', line 107 def declare_inline_source enumeree @inline_sources[enumeree] = begin if self.respond_to?(:parsed_inline_op_function) parsed_inline_op_function(enumeree) else blueprint_for(enumeree).parsed_inline_op_function(enumeree) end end end |
#decorated_call(name, type_symbol) ⇒ Object
Given some function call, see if it needs to be decorated. If so, return the decorated version; if not, return the original.
You should make sure your function is listed in sources if calls to it aren’t being decorated when it should be.
Returns a String.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/csquare.rb', line 74 def decorated_call name, type_symbol if @externs.has_key?(name) return_typename = @externs[name] return force_decorated_call(name, type_symbol) if return_typename == C::CustomType.new(@key) end # If all else fails, return as-is name end |
#expand_options(options) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/csquare.rb', line 92 def = {} .each_pair do |opt, val| if opt.is_a?(Array) opt.each do |o| [o] = val end else [opt] = val end end end |
#force_decorated_call(name, type_symbol) ⇒ Object
87 88 89 |
# File 'lib/csquare.rb', line 87 def force_decorated_call name, type_symbol [name.to_s, type_symbol.to_s].compact.join('_') end |
#get_binding ⇒ Object
49 50 51 |
# File 'lib/csquare.rb', line 49 def get_binding binding end |
#index(basename, options_and_mappings = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/csquare.rb', line 118 def index basename, = {} @indices ||= Hash.new { |h,k| h[k] = [] } on = [:on] new_index = CSquare::Generator::Index.new(self, basename, ()) @externs[basename] = new_index.return_typename # Save the index by its enumerator id @indices[on || basename] << new_index end |
#inline_op_function_name(op) ⇒ Object
TODO: Change the 2 to be the number of arguments it takes or something more indicative
55 56 57 |
# File 'lib/csquare.rb', line 55 def inline_op_function_name op "#{CSquare::Generator::OP_FUNCTION_NAMES[op]}2" end |
#preprocess_source(file) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/csquare.rb', line 31 def preprocess_source file r, w = IO.pipe source = nil pid = fork do $stdout.reopen(w) r.close cerb = CERB.new(file, self) w.close end w.close source = r.read Process.wait2(pid) source end |
#read_and_parse_source(source) ⇒ Object
TODO: Unify caches between Generator and Blueprint
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/csquare.rb', line 15 def read_and_parse_source source code = read_source "#{source}.c" begin CSquare::Function.new(code, self.template_keys(source) + keys_for(source)) rescue C::ParseError => e STDERR.puts "Error parsing source #{source.inspect}." STDERR.puts "custom type names were #{self.template_keys(source).inspect}" STDERR.puts e.inspect STDERR.puts code.size raise e end end |
#template_keys(source) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/csquare.rb', line 60 def template_keys(source) k = self.keys k = k.concat(extra_keys(source)) if respond_to?(:extra_keys) k = k.concat(extra_template_keys_for(source)) if respond_to?(:extra_template_keys_for) k end |