BSDL Device Tree Compiler
|
Public Member Functions | |
virtual | ~input_buffer () |
input_buffer () | |
input_buffer (const char *b, size_t s) | |
input_buffer | buffer_from_offset (size_t offset, size_t s=0) |
bool | empty () |
char | operator* () |
char | operator[] (int offset) |
input_buffer & | operator++ () |
operator const char * () | |
bool | consume (char c) |
bool | consume (const char *str) |
bool | consume_integer (long long &outInt) |
template<typename T > | |
bool | consume_binary (T &out) |
bool | consume_hex_byte (uint8_t &outByte) |
input_buffer & | next_token () |
void | parse_error (const char *msg) |
void | dump () |
template<> | |
bool | consume_binary (uint8_t &out) |
Protected Attributes | |
const char * | buffer |
size_t | size |
Class encapsulating the input file. Can be used as a const char*, but has range checking. Attempting to access anything out of range will return a 0 byte. The input buffer can be cheaply copied, without copying the underlying memory, however it is the user's responsibility to ensure that such copies do not persist beyond the lifetime of the underlying memory.
This also contains methods for reporting errors and for consuming the token stream.
|
inlinevirtual |
Virtual destructor. Does nothing, but exists so that subclasses that own the memory can run cleanup code for deallocating it.
|
inline |
Constructs an empty buffer.
|
inline |
Constructs a new buffer with a specified memory region and size.
|
inline |
Returns a new input buffer referring into this input, clamped to the specified size. If the requested buffer would fall outside the range of this one, then it returns an empty buffer.
The returned buffer shares the same underlying storage as the original. This is intended to be used for splitting up the various sections of a device tree blob. Requesting a size of 0 will give a buffer that extends to the end of the available memory.
|
inline |
Consumes a character. Moves the cursor one character forward if the next character matches the argument, returning true. If the current character does not match the argument, returns false.
|
inline |
Consumes a string. If the (null-terminated) string passed as the argument appears in the input, advances the cursor to the end and returns true. Returns false if the string does not appear at the current point in the input.
|
inline |
Template function that consumes a binary value in big-endian format from the input stream. Returns true and advances the cursor if there is a value of the correct size. This function assumes that all values must be natively aligned, and so advances the cursor to the correct alignment before reading.
bool dtc::input_buffer::consume_binary | ( | uint8_t & | out | ) |
Explicit specialisation for reading a single byte.
|
inline |
Consumes two hex digits and return the resulting byte via the first argument. If the next two characters are hex digits, returns true and advances the cursor. If not, then returns false and leaves the cursor in place.
|
inline |
Reads an integer in base 8, 10, or 16. Returns true and advances the cursor to the end of the integer if the cursor points to an integer, returns false and does not move the cursor otherwise.
The parsed value is returned via the argument.
|
inline |
Dumps the current cursor value and the unconsumed values in the input buffer to the standard error. This method is intended solely for debugging.
|
inline |
Returns true if this buffer has no unconsumed space in it.
|
inline |
Advances the cursor to the start of the next token, skipping comments and whitespace. If the cursor already points to the start of a token, then this function does nothing.
|
inline |
Cast to char* operator. Returns a pointer into the buffer that can be used for constructing strings.
|
inline |
Dereferencing operator, allows the buffer to be treated as a char* and dereferenced to give a character. This returns a null byte if the cursor is out of range.
|
inline |
Increments the cursor, iterating forward in the buffer.
|
inline |
Array subscripting operator, returns a character at the specified index offset from the current cursor. The offset may be negative, to reread characters that have already been read. If the current cursor plus offset is outside of the range, this returns a nul byte.
|
inline |
Prints a message indicating the location of a parse error.
|
protected |
The buffer. This class doesn't own the buffer, but the mmap_input_buffer subclass does.
|
protected |
The size of the buffer.