Class: CExtractor

Inherits:
Object show all
Includes:
CExtractorConstants, CExtractorTypes
Defined in:
lib/ceedling/c_extractor/c_extractor.rb

Constant Summary

Constants included from CExtractorConstants

CExtractorConstants::C11_SPECIFIER_KEYWORDS, CExtractorConstants::DECORATOR_KEYWORDS, CExtractorConstants::DEFAULT_CHUNK_SIZE, CExtractorConstants::DEFAULT_MAX_FUNCTION_LENGTH, CExtractorConstants::DEFAULT_MAX_LINE_LENGTH, CExtractorConstants::MODIFIER_KEYWORDS, CExtractorConstants::MSVC_CALLING_CONVENTIONS, CExtractorConstants::PRIVATE_KEYWORDS, CExtractorConstants::TYPE_KEYWORDS, CExtractorConstants::TYPE_QUALIFIER_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chunk_size=(value) ⇒ Object (writeonly)

Sets the attribute chunk_size

Parameters:

  • value

    the value to set the attribute chunk_size to.



23
24
25
# File 'lib/ceedling/c_extractor/c_extractor.rb', line 23

def chunk_size=(value)
  @chunk_size = value
end

#max_buffer_length=(value) ⇒ Object (writeonly)

Sets the attribute max_buffer_length

Parameters:

  • value

    the value to set the attribute max_buffer_length to.



23
24
25
# File 'lib/ceedling/c_extractor/c_extractor.rb', line 23

def max_buffer_length=(value)
  @max_buffer_length = value
end

Instance Method Details

#from_file(filepath) ⇒ Object

Extract C module contents from a source file on disk.

Parameters:

filepath: String path to the C source file to extract from

Returns: CModule struct containing all features extracted.

Raises:

CeedlingException: If file cannot be opened (permissions, doesn't exist, etc.)


46
47
48
49
50
51
52
53
54
# File 'lib/ceedling/c_extractor/c_extractor.rb', line 46

def from_file(filepath)
  begin
    File.open(filepath, 'r') do |file|
      return extract_contents( file, filepath )
    end
  rescue => ex
    raise CeedlingException.new("Error opening file for C contents extraction `#{filepath}` ⏩️ #{ex.message}")
  end
end

#from_string(content:, chunk_size: DEFAULT_CHUNK_SIZE, max_buffer_length: DEFAULT_MAX_FUNCTION_LENGTH, max_line_length: DEFAULT_MAX_LINE_LENGTH) ⇒ Object

Extract C module contents from an in-memory string.

Parameters:

content:           String containing C source code to extract from
chunk_size:        (Optional) Size of chunks to read at a time (default: 16 KB)
max_buffer_length: (Optional) Maximum allowed function size (default: 5 MB)
max_line_length:   (Optional) Maximum allowed line length (default: 1000 chars)

Returns: CModule struct containing all features extracted.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ceedling/c_extractor/c_extractor.rb', line 65

def from_string(
  content:,
  chunk_size:        DEFAULT_CHUNK_SIZE,
  max_buffer_length: DEFAULT_MAX_FUNCTION_LENGTH,
  max_line_length:   DEFAULT_MAX_LINE_LENGTH
)
  @chunk_size        = chunk_size
  @max_buffer_length = max_buffer_length
  @functions.max_line_length    = max_line_length
  @declarations.max_line_length = max_line_length

  return extract_contents( StringIO.new( content ), nil )
end

#setupObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ceedling/c_extractor/c_extractor.rb', line 25

def setup()
  # Aliases
  @code_text     = @c_extractor_code_text
  @functions     = @c_extractor_functions
  @declarations  = @c_extractor_declarations
  @preprocessing = @c_extractor_preprocessing
  @definitions   = @c_extractor_definitions

  @chunk_size        = DEFAULT_CHUNK_SIZE
  @max_buffer_length = DEFAULT_MAX_FUNCTION_LENGTH
end