Class: HDLRuby::Low::Expression
- Inherits:
-
Base::Expression
- Object
- Base::Expression
- HDLRuby::Low::Expression
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2sym.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_with_bool.rb,
lib/HDLRuby/hruby_low_without_select.rb,
lib/HDLRuby/hruby_low_without_namespace.rb
Overview
Extends the Expression class with functionality for moving the declarations to the upper namespace.
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Gets the type of the expression.
Attributes included from Hparent
Instance Method Summary collapse
-
#boolean? ⇒ Boolean
Tells if the expression is boolean.
-
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions.
-
#clone ⇒ Object
Clones the expression (deeply).
-
#each_node(&ruby_block) ⇒ Object
(also: #each_expression)
Iterates over the expression children if any.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#each_ref_deep(&ruby_block) ⇒ Object
Iterates over all the references encountered in the expression.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the expression where +type+ is the expected type of the condition if any.
-
#extract_selects_to!(selects) ⇒ Object
Extract the Select expressions and put them into +selects+.
-
#hash ⇒ Object
Hash function.
-
#initialize(type = Void) ⇒ Expression
constructor
Creates a new Expression with +type+.
-
#leftvalue? ⇒ Boolean
Tells if the expression is a left value of an assignment.
-
#map_nodes!(&ruby_block) ⇒ Object
(also: #map_expressions!)
Maps on the children.
-
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement.
-
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
-
#rightvalue? ⇒ Boolean
Tells if the expression is a right value.
-
#set_type!(type) ⇒ Object
Sets the type.
-
#statement ⇒ Object
Get the statement of the expression.
-
#to_c(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code.
-
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods included from Low2Symbol
Methods included from Hparent
Constructor Details
#initialize(type = Void) ⇒ Expression
Creates a new Expression with +type+
3741 3742 3743 3744 3745 3746 3747 3748 |
# File 'lib/HDLRuby/hruby_low.rb', line 3741 def initialize(type = Void) # Check and set the type. if type.is_a?(Type) then @type = type else raise AnyError, "Invalid class for a type: #{type.class}." end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Gets the type of the expression.
def type # By default: the void type. return Void end
3738 3739 3740 |
# File 'lib/HDLRuby/hruby_low.rb', line 3738 def type @type end |
Instance Method Details
#boolean? ⇒ Boolean
Tells if the expression is boolean.
98 99 100 |
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 98 def boolean? return false end |
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. +types+ include the resulting types.
504 505 506 507 508 509 510 511 512 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 504 def break_types!(types) self.each_node do |node| # Need to break only in the case of a cast. if node.is_a?(Cast) then # node.type.break_types!(types) node.set_type!(node.type.break_types!(types)) end end end |
#clone ⇒ Object
Clones the expression (deeply)
3823 3824 3825 3826 |
# File 'lib/HDLRuby/hruby_low.rb', line 3823 def clone raise AnyError, "Internal error: clone not defined for class: #{self.class}" end |
#each_node(&ruby_block) ⇒ Object Also known as: each_expression
Iterates over the expression children if any.
3786 3787 3788 |
# File 'lib/HDLRuby/hruby_low.rb', line 3786 def each_node(&ruby_block) # By default: no child. end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
3793 3794 3795 3796 3797 3798 3799 |
# File 'lib/HDLRuby/hruby_low.rb', line 3793 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 that's all. end |
#each_ref_deep(&ruby_block) ⇒ Object
Iterates over all the references encountered in the expression.
NOTE: do not iterate inside the references.
3804 3805 3806 3807 3808 3809 3810 3811 |
# File 'lib/HDLRuby/hruby_low.rb', line 3804 def each_ref_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_ref_deep) unless ruby_block # puts "each_ref_deep for Expression which is:#{self}" # A ruby block? # If the expression is a reference, applies ruby_block on it. ruby_block.call(self) if self.is_a?(Ref) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3751 3752 3753 3754 3755 |
# File 'lib/HDLRuby/hruby_low.rb', line 3751 def eql?(obj) return false unless obj.is_a?(Expression) return false unless @type.eql?(obj.type) return true end |
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the expression where +type+ is the expected type of the condition if any.
181 182 183 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 181 def explicit_types(type = nil) raise "Should implement explicit_types for class #{self.class}." end |
#extract_selects_to!(selects) ⇒ Object
Extract the Select expressions and put them into +selects+
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 216 def extract_selects_to!(selects) # Recurse on the sub expressions. self.map_expressions! {|expr| expr.extract_selects_to!(selects) } # Treat case of select. if self.is_a?(Select) then # Create the signal replacing self. sig = SignalI.new(HDLRuby.uniq_name,self.type) # Add the self with replacing sig to the extracted selects selects << [self,sig] # Create the signal replacing self. blk = self.statement.block if blk then # Add the signal in the block. blk.add_inner(sig) else # No block, this is a connection, add the signal in the # socpe self.statement.scope.add_inner(sig) end # And return a reference to it. return RefName.new(sig.type,RefThis.new,sig.name) end return self end |
#hash ⇒ Object
Hash function.
3758 3759 3760 |
# File 'lib/HDLRuby/hruby_low.rb', line 3758 def hash return [@type].hash end |
#leftvalue? ⇒ Boolean
Tells if the expression is a left value of an assignment.
3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 |
# File 'lib/HDLRuby/hruby_low.rb', line 3763 def leftvalue? # Maybe its the left of a left value. if parent.respond_to?(:leftvalue?) && parent.leftvalue? then # Yes so it is also a left value if it is a sub ref. if parent.respond_to?(:ref) then # It might nor be a sub ref. return parent.ref == self else # It is necessarily a sub ref (case of RefConcat for now). return true end end # No, therefore maybe it is directly a left value. return (parent.is_a?(Transmit) || parent.is_a?(Connection)) && parent.left == self end |
#map_nodes!(&ruby_block) ⇒ Object Also known as: map_expressions!
Maps on the children.
1185 1186 1187 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1185 def map_nodes!(&ruby_block) # By default, nothing to do. end |
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.
NOTE: the replacement is duplicated.
1197 1198 1199 1200 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1197 def replace_expressions!(node2rep) # By default, nothing to do. return {} end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
492 493 494 495 496 497 498 499 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 492 def replace_names!(former,nname) # By default: try to replace the name recursively. self.each_node_deep do |node| if node.respond_to?(:name) && node.name == former then node.set_name!(nname) end end end |
#rightvalue? ⇒ Boolean
Tells if the expression is a right value.
3781 3782 3783 |
# File 'lib/HDLRuby/hruby_low.rb', line 3781 def rightvalue? return !self.leftvalue? end |
#set_type!(type) ⇒ Object
Sets the type.
1175 1176 1177 1178 1179 1180 1181 1182 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1175 def set_type!(type) # Check and set the type. if type.is_a?(Type) then @type = type else raise AnyError, "Invalid class for a type: #{type.class}." end end |
#statement ⇒ Object
Get the statement of the expression.
3814 3815 3816 3817 3818 3819 3820 |
# File 'lib/HDLRuby/hruby_low.rb', line 3814 def statement if self.parent.is_a?(Statement) return self.parent else return self.parent.statement end end |
#to_c(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
1402 1403 1404 1405 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1402 def to_c(level = 0) # Should never be here. raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}" end |
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
542 543 544 545 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 542 def to_high(level = 0) # Should never be here. raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}" end |
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
1108 1109 1110 1111 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1108 def to_vhdl(level = 0) # Should never be here. raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}" end |