class AutoC::Module::EntityContainer::AutoC::Module::EntityContainer::Module::State::AutoC::Module::EntityContainer::AutoC::Module::EntityContainer::Module::State::Module::StreamFile::AutoC::Module::EntityContainer::AutoC::Module::EntityContainer::Module::State::AutoC::Module::EntityContainer::AutoC::Module::EntityContainer::Module::State::Module::StreamFile::Module::Header

Attributes

module[R]

Public Class Methods

new(m) click to toggle source
# File lib/autoc/module.rb, line 219
  def initialize(m) = @module = m

private

  def render_contents(stream)
    render_prologue(stream)
    entities.to_a.sort.each { |e| e.interface.each { |x| stream << x } }
    render_epilogue(stream)
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #ifndef #{tag}
      #define #{tag}
    }
  end

  def render_epilogue(stream)
    stream << %{
      #endif
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Header


class Module::Source

  include Module::EntityContainer

  include Module::SmartRenderer

  attr_reader :module

  attr_reader :complexity

  attr_reader :index

  def file_name = self.module.source_count < 2 ? "#{self.module.name}_auto.c" : "#{self.module.name}_auto#{index}.c"

  def initialize(m, index)
    @module = m
    @complexity = 0
    @index = index
  end

  def <<(entity)
    @complexity += entity.complexity unless entities.include?(entity)
    super
  end

private

  def render_contents(stream)
    render_prologue(stream)
    total_entities = ::Set.new
    entities.each { |e| total_entities.merge(e.total_references) }
    total_entities.to_a.sort.each { |e| e.forward_declarations.each { |x| stream << x } }
    entities.to_a.sort.each { |e| e.implementation.each { |x| stream << x } }
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #include "#{self.module.header.file_name}"
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Source


module Entity

  include ::Comparable

  # A set of the entity's immediate references which, unlike dependencies, do not enforce the entities relative ordering
  def references = @references ||= ReferenceSet.new

  # Return the entire entity's reference set staring with self
  def total_references = @total_references ||= collect_references(::Set.new)

  # A set of the entity's immediate dependencies which enforce the entities relative ordering
  def dependencies = @dependencies ||= DependencySet.new(self)

  # Return the entire entity's dependency set staring with self
  def total_dependencies = @total_dependencies ||= collect_dependencies(::Set.new)

  protected def collect_references(set)
    unless set.include?(self)
      set << self
      references.each { |x| x.collect_references(set) }
    end
    set
  end

  protected def collect_dependencies(set)
    unless set.include?(self)
      set << self
      dependencies.each { |x| x.collect_dependencies(set) }
    end
    set
  end

  def <=>(other) = position <=> other.position

  # Compute the entity's relative position with respect to its dependencies
  def position = @position ||= begin
    p = 0
    # This code goes into infinite recursion on circular dependency
    # which must be resolved manually with Entity#references
    total_dependencies.each do |d|
      unless equal?(d)
        dp = d.position
        p = dp if p < dp # p <- max(p, dp)
      end
    end
    p + 1 # Arrange entity to follow all its dependencies
  end

  def complexity = forward_declarations.complexity + implementation.complexity # Interface part is not considered as it is shared across the sources

  def interface
    @interface ||= begin
      render_interface(stream = Module::Builder.new)
      stream
    end
  end

  def forward_declarations
    @forward_declarations ||= begin
      render_forward_declarations(stream = Module::Builder.new)
      stream
    end
  end

  def implementation
    @implementation ||= begin
      render_implementation(stream = Module::Builder.new)
      stream
    end
  end

private

  ### Overridable rendering methods

  def render_interface(stream) = nil

  def render_forward_declarations(stream) = nil

  def render_implementation(stream) = nil

end # Entity


Entity::ReferenceSet = ::Set


# @private
class Entity::DependencySet < ::Set

  def initialize(entity)
    super()
    @entity = entity
  end

  def <<(x)
    @entity.references << x # Each dependency is also registered as a reference
    super
  end

end # DependencySet


# Helper class to represent plain C side code block
class Code

  include Entity

  def initialize(interface: nil, implementation: nil, definitions: nil)
    @interface_ = interface
    @definitions_ = definitions
    @implementation_ = implementation
  end

  def inspect = "... <#{self.class}>"

private

  def render_interface(stream)
    stream << @interface_ unless @interface_.nil?
  end

  def render_implementation(stream)
    stream << @implementation_ unless @implementation_.nil?
  end

  def render_forward_declarations(stream)
    stream << @definitions_ unless @definitions_.nil?
  end

end # Code


# Helper class to inject a system-wide header into the C side interface part of the module
class SystemHeader < AutoC::Code
  

Public Instance Methods

file_name(= @file_name ||= " click to toggle source
# File lib/autoc/module.rb, line 215
  def file_name = @file_name ||= "#{self.module.name}_auto.h"

  def tag = "#{self.module.name}_auto_h".upcase

  def initialize(m) = @module = m

private

  def render_contents(stream)
    render_prologue(stream)
    entities.to_a.sort.each { |e| e.interface.each { |x| stream << x } }
    render_epilogue(stream)
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #ifndef #{tag}
      #define #{tag}
    }
  end

  def render_epilogue(stream)
    stream << %{
      #endif
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Header


class Module::Source

  include Module::EntityContainer

  include Module::SmartRenderer

  attr_reader :module

  attr_reader :complexity

  attr_reader :index

  def file_name = self.module.source_count < 2 ? "#{self.module.name}_auto.c" : "#{self.module.name}_auto#{index}.c"

  def initialize(m, index)
    @module = m
    @complexity = 0
    @index = index
  end

  def <<(entity)
    @complexity += entity.complexity unless entities.include?(entity)
    super
  end

private

  def render_contents(stream)
    render_prologue(stream)
    total_entities = ::Set.new
    entities.each { |e| total_entities.merge(e.total_references) }
    total_entities.to_a.sort.each { |e| e.forward_declarations.each { |x| stream << x } }
    entities.to_a.sort.each { |e| e.implementation.each { |x| stream << x } }
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #include "#{self.module.header.file_name}"
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Source


module Entity

  include ::Comparable

  # A set of the entity's immediate references which, unlike dependencies, do not enforce the entities relative ordering
  def references = @references ||= ReferenceSet.new

  # Return the entire entity's reference set staring with self
  def total_references = @total_references ||= collect_references(::Set.new)

  # A set of the entity's immediate dependencies which enforce the entities relative ordering
  def dependencies = @dependencies ||= DependencySet.new(self)

  # Return the entire entity's dependency set staring with self
  def total_dependencies = @total_dependencies ||= collect_dependencies(::Set.new)

  protected def collect_references(set)
    unless set.include?(self)
      set << self
      references.each { |x| x.collect_references(set) }
    end
    set
  end

  protected def collect_dependencies(set)
    unless set.include?(self)
      set << self
      dependencies.each { |x| x.collect_dependencies(set) }
    end
    set
  end

  def <=>(other) = position <=> other.position

  # Compute the entity's relative position with respect to its dependencies
  def position = @position ||= begin
    p = 0
    # This code goes into infinite recursion on circular dependency
    # which must be resolved manually with Entity#references
    total_dependencies.each do |d|
      unless equal?(d)
        dp = d.position
        p = dp if p < dp # p <- max(p, dp)
      end
    end
    p + 1 # Arrange entity to follow all its dependencies
  end

  def complexity = forward_declarations.complexity + implementation.complexity # Interface part is not considered as it is shared across the sources

  def interface
    @interface ||= begin
      render_interface(stream = Module::Builder.new)
      stream
    end
  end

  def forward_declarations
    @forward_declarations ||= begin
      render_forward_declarations(stream = Module::Builder.new)
      stream
    end
  end

  def implementation
    @implementation ||= begin
      render_implementation(stream = Module::Builder.new)
      stream
    end
  end

private

  ### Overridable rendering methods

  def render_interface(stream) = nil

  def render_forward_declarations(stream) = nil

  def render_implementation(stream) = nil

end # Entity


Entity::ReferenceSet = ::Set


# @private
class Entity::DependencySet < ::Set

  def initialize(entity)
    super()
    @entity = entity
  end

  def <<(x)
    @entity.references << x # Each dependency is also registered as a reference
    super
  end

end # DependencySet


# Helper class to represent plain C side code block
class Code

  include Entity

  def initialize(interface: nil, implementation: nil, definitions: nil)
    @interface_ = interface
    @definitions_ = definitions
    @implementation_ = implementation
  end

  def inspect = "... <#{self.class}>"

private

  def render_interface(stream)
    stream << @interface_ unless @interface_.nil?
  end

  def render_implementation(stream)
    stream << @implementation_ unless @implementation_.nil?
  end

  def render_forward_declarations(stream)
    stream << @definitions_ unless @definitions_.nil?
  end

end # Code


# Helper class to inject a system-wide header into the C side interface part of the module
class SystemHeader < AutoC
render_contents(stream) click to toggle source
# File lib/autoc/module.rb, line 223
def render_contents(stream)
  render_prologue(stream)
  entities.to_a.sort.each { |e| e.interface.each { |x| stream << x } }
  render_epilogue(stream)
end
render_epilogue(stream) click to toggle source
# File lib/autoc/module.rb, line 237
def render_epilogue(stream)
  stream << %{
    #endif
  }
end
render_prologue(stream) click to toggle source
# File lib/autoc/module.rb, line 229
def render_prologue(stream)
  stream << %{
    #{Module::CAP}
    #ifndef #{tag}
    #define #{tag}
  }
end
stream(= @stream ||= Module::StreamFile.new(file_name+'~', 'wt')) click to toggle source
# File lib/autoc/module.rb, line 243
  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end
tag(= " click to toggle source
# File lib/autoc/module.rb, line 217
  def tag = "#{self.module.name}_auto_h".upcase

  def initialize(m) = @module = m

private

  def render_contents(stream)
    render_prologue(stream)
    entities.to_a.sort.each { |e| e.interface.each { |x| stream << x } }
    render_epilogue(stream)
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #ifndef #{tag}
      #define #{tag}
    }
  end

  def render_epilogue(stream)
    stream << %{
      #endif
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Header


class Module::Source

  include Module::EntityContainer

  include Module::SmartRenderer

  attr_reader :module

  attr_reader :complexity

  attr_reader :index

  def file_name = self.module.source_count < 2 ? "#{self.module.name}_auto.c" : "#{self.module.name}_auto#{index}.c"

  def initialize(m, index)
    @module = m
    @complexity = 0
    @index = index
  end

  def <<(entity)
    @complexity += entity.complexity unless entities.include?(entity)
    super
  end

private

  def render_contents(stream)
    render_prologue(stream)
    total_entities = ::Set.new
    entities.each { |e| total_entities.merge(e.total_references) }
    total_entities.to_a.sort.each { |e| e.forward_declarations.each { |x| stream << x } }
    entities.to_a.sort.each { |e| e.implementation.each { |x| stream << x } }
  end

  def render_prologue(stream)
    stream << %{
      #{Module::CAP}
      #include "#{self.module.header.file_name}"
    }
  end

  def stream = @stream ||= Module::StreamFile.new(file_name+'~', 'wt')

end # Source


module Entity

  include ::Comparable

  # A set of the entity's immediate references which, unlike dependencies, do not enforce the entities relative ordering
  def references = @references ||= ReferenceSet.new

  # Return the entire entity's reference set staring with self
  def total_references = @total_references ||= collect_references(::Set.new)

  # A set of the entity's immediate dependencies which enforce the entities relative ordering
  def dependencies = @dependencies ||= DependencySet.new(self)

  # Return the entire entity's dependency set staring with self
  def total_dependencies = @total_dependencies ||= collect_dependencies(::Set.new)

  protected def collect_references(set)
    unless set.include?(self)
      set << self
      references.each { |x| x.collect_references(set) }
    end
    set
  end

  protected def collect_dependencies(set)
    unless set.include?(self)
      set << self
      dependencies.each { |x| x.collect_dependencies(set) }
    end
    set
  end

  def <=>(other) = position <=> other.position

  # Compute the entity's relative position with respect to its dependencies
  def position = @position ||= begin
    p = 0
    # This code goes into infinite recursion on circular dependency
    # which must be resolved manually with Entity#references
    total_dependencies.each do |d|
      unless equal?(d)
        dp = d.position
        p = dp if p < dp # p <- max(p, dp)
      end
    end
    p + 1 # Arrange entity to follow all its dependencies
  end

  def complexity = forward_declarations.complexity + implementation.complexity # Interface part is not considered as it is shared across the sources

  def interface
    @interface ||= begin
      render_interface(stream = Module::Builder.new)
      stream
    end
  end

  def forward_declarations
    @forward_declarations ||= begin
      render_forward_declarations(stream = Module::Builder.new)
      stream
    end
  end

  def implementation
    @implementation ||= begin
      render_implementation(stream = Module::Builder.new)
      stream
    end
  end

private

  ### Overridable rendering methods

  def render_interface(stream) = nil

  def render_forward_declarations(stream) = nil

  def render_implementation(stream) = nil

end # Entity


Entity::ReferenceSet = ::Set


# @private
class Entity::DependencySet < ::Set

  def initialize(entity)
    super()
    @entity = entity
  end

  def <<(x)
    @entity.references << x # Each dependency is also registered as a reference
    super
  end

end # DependencySet


# Helper class to represent plain C side code block
class Code

  include Entity

  def initialize(interface: nil, implementation: nil, definitions: nil)
    @interface_ = interface
    @definitions_ = definitions
    @implementation_ = implementation
  end

  def inspect = "... <#{self.class}>"

private

  def render_interface(stream)
    stream << @interface_ unless @interface_.nil?
  end

  def render_implementation(stream)
    stream << @implementation_ unless @implementation_.nil?
  end

  def render_forward_declarations(stream)
    stream << @definitions_ unless @definitions_.nil?
  end

end # Code


# Helper class to inject a system-wide header into the C side interface part of the module
class SystemHeader < AutoC::Code