Class: AutoC::Module::Source

Inherits:
File
  • Object
show all
Defined in:
lib/autoc/code.rb

Instance Attribute Summary (collapse)

Attributes inherited from File

#entities

Instance Method Summary (collapse)

Methods inherited from File

#<<, #generate

Constructor Details

- (Source) initialize(m, i)

Returns a new instance of Source



193
194
195
196
197
# File 'lib/autoc/code.rb', line 193

def initialize(m, i)
  super(m)
  @index = i
  @file_name = @module.source_count > 1 ? "#{@module.name.downcase}_auto#{index}.c" : "#{@module.name.downcase}_auto.c"
end

Instance Attribute Details

- (Object) file_name (readonly)

Returns the value of attribute file_name



191
192
193
# File 'lib/autoc/code.rb', line 191

def file_name
  @file_name
end

- (Object) index (readonly)

Returns the value of attribute index



191
192
193
# File 'lib/autoc/code.rb', line 191

def index
  @index
end

Instance Method Details

- (Boolean) main?

Returns:

  • (Boolean)


199
200
201
# File 'lib/autoc/code.rb', line 199

def main?
  equal?(@module.main_source)
end

- (Object) new_stream



213
214
215
# File 'lib/autoc/code.rb', line 213

def new_stream
  ::File.new(@file_name, "w")
end

- (Object) size



207
208
209
210
211
# File 'lib/autoc/code.rb', line 207

def size
  size = 0
  @entities.each {|e| size += e.source_size}
  size
end

- (Boolean) smallest?

Returns:

  • (Boolean)


203
204
205
# File 'lib/autoc/code.rb', line 203

def smallest?
  equal?(@module.smallest_source)
end

- (Object) write(stream)



217
218
219
220
221
222
223
224
225
# File 'lib/autoc/code.rb', line 217

def write(stream)
  stream << %$
    /* AUTOMATICALLY GENERATED SOURCE FILE. DO NOT MODIFY. */
    #include "#{@module.header.file_name}"
  $
  sorted = AutoC.priority_sort(entities)
  sorted.each {|e| e.write_decls(stream)}
  sorted.each {|e| e.write_defs(stream)}
end