Class: C::Variable
- Inherits:
-
Object
- Object
- C::Variable
- Defined in:
- lib/csquare.rb
Instance Method Summary collapse
- #depth ⇒ Object
- #involves?(literal_or_variables) ⇒ Boolean
-
#recombine!(function, blueprint, type_symbol, return_type = nil) ⇒ Object
Replace some expression with the pattern from Blueprint.
- #return_typename(function, blueprint = nil) ⇒ Object
- #underlying_value ⇒ Object
Instance Method Details
#depth ⇒ Object
664 665 666 |
# File 'lib/csquare.rb', line 664 def depth 0 end |
#involves?(literal_or_variables) ⇒ Boolean
632 633 634 |
# File 'lib/csquare.rb', line 632 def involves? literal_or_variables literal_or_variables.is_a?(Array) ? literal_or_variables.include?(self.name) : literal_or_variables == self.name end |
#recombine!(function, blueprint, type_symbol, return_type = nil) ⇒ Object
Replace some expression with the pattern from Blueprint.
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/csquare.rb', line 669 def recombine! function, blueprint, type_symbol, return_type=nil args_types = {} replace_vars = blueprint.vars(type_symbol) return_node = if replace_vars.has_key?(self.name) n = self.clone n.name = replace_vars[self.name] n else self end [return_node, self.return_typename(function, blueprint)] end |
#return_typename(function, blueprint = nil) ⇒ Object
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'lib/csquare.rb', line 640 def return_typename function, blueprint=nil return :boolean if %w{true false}.include?(self.name) if parent_block.has_local?(self.name, blueprint) t = function.type_of(self.name, blueprint) return t.to_s if t.is_a?(C::PrimitiveType) # int, float, double, etc return t.is_a?(C::DirectType) ? t.name : t end # This is kind of a hack. To do it the real way, we really need to know the type symbol if self.name =~ /_(MIN|MAX)$/ return blueprint.externs[self.name] if blueprint.externs.has_key?(self.name) name_without_minmax = self.name[0...-4] if blueprint.extra_templates_by_source.has_key?(function.name) && blueprint.extra_templates_by_source[function.name].has_key?(name_without_minmax) return blueprint.extra_templates_by_source[function.name][name_without_minmax] end end require 'pry' binding.pry raise(NotImplementedError, "undeclared variable #{self.name.inspect}") end |
#underlying_value ⇒ Object
636 637 638 |
# File 'lib/csquare.rb', line 636 def self.name end |