Class: HDLRuby::Low::StringE
- Inherits:
-
Expression
- Object
- Base::Expression
- Expression
- HDLRuby::Low::StringE
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_bool2select.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb
Overview
Extends the StringE class with functionality for extracting expressions from cast.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Attributes inherited from Expression
Attributes included from Hparent
Instance Method Summary collapse
-
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
-
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
-
#clone ⇒ Object
Clones the string.
-
#each_arg(&ruby_block) ⇒ Object
Iterates over each argument.
-
#each_block(&ruby_block) ⇒ Object
Iterates over the sub blocks.
-
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks contained in the current block.
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#each_node(&ruby_block) ⇒ Object
Iterates over the expression children if any.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the statements contained in the current block.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the concat where +type+ is the expected type of the condition if any.
-
#hash ⇒ Object
Hash function.
-
#immutable? ⇒ Boolean
Tells if the expression is immutable (cannot be written.).
-
#initialize(content, *args) ⇒ StringE
constructor
Creates a new string whose content is +str+ and is modified using the objects of +args+.
-
#map_args!(&ruby_block) ⇒ Object
Maps on the arguments.
-
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children.
-
#to_high ⇒ Object
Creates a new high string expression.
-
#to_verilog(spc = 3) ⇒ Object
Converts the system to Verilog code.
-
#to_vhdl(level = 0, std_logic = false) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods inherited from Expression
#boolean?, #break_types!, #each_ref_deep, #extract_selects_to!, #leftvalue?, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #statement, #to_c, #to_hdr, #use_name?
Methods included from Low2Symbol
Methods included from Hparent
Constructor Details
#initialize(content, *args) ⇒ StringE
Creates a new string whose content is +str+ and is modified using the objects of +args+.
5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 |
# File 'lib/HDLRuby/hruby_low.rb', line 5729 def initialize(content,*args) super(StringT) # Checks and set the content. @content = content.to_s # Process the arguments. @args = args.map do |arg| arg.parent = self arg end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5725 5726 5727 |
# File 'lib/HDLRuby/hruby_low.rb', line 5725 def content @content end |
Instance Method Details
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
339 340 341 342 343 344 345 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 339 def boolean_in_assign2select # Apply on the content. # Apply on the arguments. return StringE.new(self.content.clone,*self.each_arg.map do |arg| arg.boolean_in_assign2select end) end |
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
369 370 371 372 373 374 |
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 369 def casts_without_expression! # return StringE.new(self.content, # *self.each_arg.map(&:casts_without_expression)) self.map_args! {|arg| arg.casts_without_expression! } return self end |
#clone ⇒ Object
Clones the string.
5784 5785 5786 |
# File 'lib/HDLRuby/hruby_low.rb', line 5784 def clone return StringE.new(@content.clone,*@args.map {|arg| arg.clone}) end |
#each_arg(&ruby_block) ⇒ Object
Iterates over each argument.
Returns an enumerator if no ruby block is given.
5759 5760 5761 5762 5763 5764 |
# File 'lib/HDLRuby/hruby_low.rb', line 5759 def each_arg(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_arg) unless ruby_block # A ruby block? First apply it to each argument. @args.each(&ruby_block) end |
#each_block(&ruby_block) ⇒ Object
Iterates over the sub blocks.
5808 5809 5810 5811 5812 5813 5814 5815 5816 |
# File 'lib/HDLRuby/hruby_low.rb', line 5808 def each_block(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_block) unless ruby_block # A ruby block? # Recurse on each argument. @args.each do |arg| arg.each_block(&ruby_block) if arg.respond_to?(:each_block) end end |
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks contained in the current block.
5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 |
# File 'lib/HDLRuby/hruby_low.rb', line 5819 def each_block_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_block_deep) unless ruby_block # A ruby block? # Recurse on each argument. @args.each do |arg| if arg.respond_to?(:each_block_deep) then arg.each_block_deep(&ruby_block) end end end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
5769 5770 5771 5772 5773 5774 5775 5776 |
# File 'lib/HDLRuby/hruby_low.rb', line 5769 def each_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # Then apply on the arguments. self.each_arg(&ruby_block) end |
#each_node(&ruby_block) ⇒ Object
Iterates over the expression children if any.
5789 5790 5791 5792 5793 5794 5795 |
# File 'lib/HDLRuby/hruby_low.rb', line 5789 def each_node(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node) unless ruby_block # A ruby block? # Apply it on each argument. @args.each(&ruby_block) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
5798 5799 5800 5801 5802 5803 5804 5805 |
# File 'lib/HDLRuby/hruby_low.rb', line 5798 def each_node_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # And apply it on each argument. @args.each(&ruby_block) end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the statements contained in the current block.
5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 |
# File 'lib/HDLRuby/hruby_low.rb', line 5832 def each_statement_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_statement_deep) unless ruby_block # A ruby block? # Apply it on self. ruby_block.call(self) # Recurse on each argument. @args.each do |arg| if arg.respond_to?(:each_statement_deep) then arg.each_statement_deep(&ruby_block) end end end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
5747 5748 5749 5750 5751 5752 5753 5754 |
# File 'lib/HDLRuby/hruby_low.rb', line 5747 def eql?(obj) return false unless obj.is_a?(StringE) return false unless @content.eql?(obj.content) return false if @args.each.zip(obj.each_arg).any? do |a0,a1| !a0.eql?(a1) end return true end |
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the concat where +type+ is the expected type of the condition if any.
459 460 461 462 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 459 def explicit_types(type = nil) return StringE.new(self.content, *self.each_arg.map(&:explicit_types)) end |
#hash ⇒ Object
Hash function.
5779 5780 5781 |
# File 'lib/HDLRuby/hruby_low.rb', line 5779 def hash return @args.hash end |
#immutable? ⇒ Boolean
Tells if the expression is immutable (cannot be written.)
5741 5742 5743 5744 |
# File 'lib/HDLRuby/hruby_low.rb', line 5741 def immutable? # String objects are always immutable. true end |
#map_args!(&ruby_block) ⇒ Object
Maps on the arguments.
1982 1983 1984 1985 1986 1987 1988 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1982 def map_args!(&ruby_block) @args.map! do |arg| arg = ruby_block.call(arg) arg.parent = self unless arg.parent arg end end |
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children.
1991 1992 1993 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1991 def map_nodes!(&ruby_block) self.map_args!(&ruby_block) end |
#to_high ⇒ Object
Creates a new high string expression.
515 516 517 518 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 515 def to_high return HDLRuby::High::StringE.new(self.content, *self.each_arg.map {|arg| arg.to_high }) end |
#to_verilog(spc = 3) ⇒ Object
Converts the system to Verilog code.
2171 2172 2173 2174 2175 2176 2177 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 2171 def to_verilog(spc = 3) code = "\"#{Low.v_string(self.content)}" + "#{self.each_arg.map do |arg| to.to_verilog end.join(",")}\"" return code end |
#to_vhdl(level = 0, std_logic = false) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
1520 1521 1522 1523 1524 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1520 def to_vhdl(level = 0, std_logic = false) # Generate a report statement. return "\"#{Low2VHDL.vhdl_string(self.content)}\"" + self.each_arg.map { |arg| arg.to_vhdl }.join(" & ") end |