class HDLRuby::Low::Expression
Describes an expression.
NOTE: this is an abstract class which is not to be used directly.
Describes an expression.
NOTE: this is an abstract class which is not to be used directly.
Extends the Expression
class with generation of C text.
Extends the Expression
class with generation of hdr text.
Add the conversion to high.
Extends the Expression
class with conversion to symbol.
Extends the Expression
class with generation of HDLRuby::High
text.
Extends the Expression
class with fixing of types and constants.
Describes an expression.
NOTE: this is an abstract class which is not to be used directly.
Extends the Expression
class for checking if it a boolean expression or not.
Extends the Expression
class with functionality for moving the declarations to the upper namespace.
Extends the Expression
class with functionality for converting select expressions to ase statements.
Attributes
# Gets the type of the expression. def type
# By default: the void type. return Void
end
Public Class Methods
Creates a new Expression
with type
# File lib/HDLRuby/hruby_low.rb, line 4327 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
Public Instance Methods
Tells if the expression is boolean.
# File lib/HDLRuby/hruby_low_with_bool.rb, line 98 def boolean? return false end
Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. types
include the resulting types.
# 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
Clones the expression (deeply)
# File lib/HDLRuby/hruby_low.rb, line 4423 def clone raise AnyError, "Internal error: clone not defined for class: #{self.class}" end
Iterates over the expression children if any.
# File lib/HDLRuby/hruby_low.rb, line 4380 def each_node(&ruby_block) # By default: no child. end
Iterates over the nodes deeply if any.
# File lib/HDLRuby/hruby_low.rb, line 4387 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
Iterates over all the references encountered in the expression.
NOTE: do not iterate inside the references.
# File lib/HDLRuby/hruby_low.rb, line 4398 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
Comparison for hash: structural comparison.
# File lib/HDLRuby/hruby_low.rb, line 4340 def eql?(obj) return false unless obj.is_a?(Expression) return false unless @type.eql?(obj.type) return true end
Explicit the types conversions in the expression where type
is the expected type of the condition if any.
# File lib/HDLRuby/hruby_low_fix_types.rb, line 195 def explicit_types(type = nil) raise "Should implement explicit_types for class #{self.class}." end
Extract the Select
expressions and put them into selects
# File lib/HDLRuby/hruby_low_without_select.rb, line 229 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
function.
# File lib/HDLRuby/hruby_low.rb, line 4347 def hash return [@type].hash end
Tells if the expression is immutable (cannot be written.)
# File lib/HDLRuby/hruby_low.rb, line 4375 def immutable? false end
Tells if the expression is a left value of an assignment.
# File lib/HDLRuby/hruby_low.rb, line 4352 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
Maps on the children.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1343 def map_nodes!(&ruby_block) # By default, nothing to do. end
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.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1355 def replace_expressions!(node2rep) # By default, nothing to do. return {} end
Replaces recursively former
name by nname
until it is redeclared.
# 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
Tells if the expression is a right value.
# File lib/HDLRuby/hruby_low.rb, line 4370 def rightvalue? return !self.leftvalue? end
Sets the type.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1333 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
Get the statement of the expression.
# File lib/HDLRuby/hruby_low.rb, line 4408 def statement if self.parent.is_a?(Statement) return self.parent else return self.parent.statement end end
Generates the C text of the equivalent HDLRuby
code. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2c.rb, line 1519 def to_c(level = 0) # Should never be here. raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}" end
Generates the text of the equivalent hdr text. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2hdr.rb, line 542 def to_hdr(level = 0) # Should never be here. raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}" end
Creates a new high expression.
# File lib/HDLRuby/hruby_low2high.rb, line 374 def to_high raise AnyError, "Internal error: to_high is not defined for class: #{self.class}" end
Generates the text of the equivalent HDLRuby::High
code. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2vhd.rb, line 1132 def to_vhdl(level = 0) # Should never be here. raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}" end
Tell if the expression includes a signal whose name is one of names
.
# File lib/HDLRuby/hruby_low.rb, line 4417 def use_name?(*names) # By default nothing. return false end