FFI::ClangSourceFFIClangUnsavedFile

class UnsavedFile

Represents an unsaved file with in-memory contents for parsing.

Definitions

def initialize(filename, contents)

Initialize an unsaved file with filename and contents.

Signature

parameter filename String

The path to the unsaved file.

parameter contents String

The in-memory contents of the file.

Implementation

def initialize(filename, contents)
	@filename = filename
	@contents = contents
end

attr_accessor :filename

Signature

attribute String

The path to the unsaved file.

attr_accessor :contents

Signature

attribute String

The in-memory contents of the file.

def self.unsaved_pointer_from(unsaved)

Convert an array of unsaved files to a libclang pointer structure.

Signature

parameter unsaved Array(UnsavedFile)

The array of unsaved files.

returns FFI::MemoryPointer | Nil

A pointer to the unsaved file structures, or nil if empty.

Implementation

def self.unsaved_pointer_from(unsaved)
	return nil if unsaved.length == 0
	
	vec = MemoryPointer.new(Lib::CXUnsavedFile, unsaved.length)
	
	unsaved.each_with_index do |file, i|
		uf = Lib::CXUnsavedFile.new(vec + i * Lib::CXUnsavedFile.size)
		uf[:filename] = MemoryPointer.from_string(file.filename)
		uf[:contents] = MemoryPointer.from_string(file.contents)
		uf[:length] = file.contents.length
	end
	
	vec
end